117 lines
5.7 KiB
Java
117 lines
5.7 KiB
Java
package ssw.dacli.menu.builder;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* no-spa 菜单 builder (type=7) — v13-f2 Task 2.4 打磨
|
|
*
|
|
* 用于挂 JNPF 平台之外的独立 HTML 页面 (no-spa-page 技能), 走 nginx 代理 public/ssw/。
|
|
*
|
|
* <p>实测 5 样本 baseline 0 误差对齐 (scripts/menu-baseline/workSystem-nospa.jsonl):
|
|
* <ul>
|
|
* <li>实体 21 字段: fullName/enCode/parentId/category/type/icon/urlAddress/pageAddress/
|
|
* linkTarget/propertyJson/sortCode/enabledMark/systemId/4 authorize/description/noShow</li>
|
|
* <li>type 字段是 int (7), 不是 string (跟 Web menu 1/2/3 一致, 盲点 JNPF-30)</li>
|
|
* <li>category 字段 = "Web" (no-spa 是 Web 的一种, linkTarget/_blank 区分, 跟前端 Link 组件 init() 逻辑一致)</li>
|
|
* <li>linkTarget = "_blank" (新窗口, 前端 Link 组件 init() 当 type=7 时 .replaceAll('${jnpfToken}', ...))</li>
|
|
* <li>urlAddress 模板: <code>/ssw/{systemId}/{enCode}?token=${jnpfToken}&appCode=${jnpfAppCode}</code></li>
|
|
* <li>pageAddress = urlAddress (复制一份, JNPF API 字段名兼容)</li>
|
|
* <li>propertyJson 4 字段: {moduleId:"", iconBackgroundColor:"", isTree:0, webType:7}</li>
|
|
* <li>moduleId = "" (空字符串, 跟 propertyJson.moduleId 一致, 盲点 JNPF-30)</li>
|
|
* <li>4 authorize 字段全 1 (isButtonAuthorize/isColumnAuthorize/isDataAuthorize/isFormAuthorize)</li>
|
|
* <li>systemId 透传 (parent menu 在子应用下, 跟 Web menu 一致)</li>
|
|
* </ul>
|
|
*
|
|
* <p>与 LinkMenuBuilder 区别:
|
|
* <ul>
|
|
* <li>NoSpa: /ssw/{app}/... 平台内静态, 走 nginx 代理, 用 ${jnpfToken} 模板</li>
|
|
* <li>Link: 完整 http(s):// 外部链接, 不需要 token 模板</li>
|
|
* </ul>
|
|
*
|
|
* <p>与 WebMenuBuilder 区别:
|
|
* <ul>
|
|
* <li>NoSpa: type=7, propertyJson.moduleId="", linkTarget=_blank, 走 Link 组件</li>
|
|
* <li>Web(type=1/2/3/9): propertyJson.moduleId=formId, linkTarget=_self, 走 SPA 路由</li>
|
|
* </ul>
|
|
*
|
|
* @author v13-f2 Agent-F2
|
|
*/
|
|
public class NoSpaMenuBuilder implements MenuBuilder {
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
@Override
|
|
public String category() {
|
|
return "Web"; // ← 关键: no-spa 是 Web 菜单的一种, 内部靠 type=7 区分
|
|
}
|
|
|
|
@Override
|
|
public String buildMenuEntity(MenuBuildContext ctx) {
|
|
try {
|
|
// 1. type=7 是 no-spa 的固定标识 (int, 非 string, 跟 Web menu 1/2/3 一致)
|
|
// 校验 ctx.menuType 显式声明 = "7" 才合法 (避免误用其他 type builder)
|
|
if (ctx.menuType != null && !"7".equals(ctx.menuType)) {
|
|
throw new IllegalArgumentException(
|
|
"no-spa 菜单 menuType 必须是 7, 实际: " + ctx.menuType
|
|
);
|
|
}
|
|
// no-spa 菜单的 type 字段恒为 7, 与 webType 解耦 (webType 仍透传, 跟 baseline 对齐)
|
|
|
|
// 2. 解析 systemId (no-spa 路径前缀) 与 enCode
|
|
String systemId = ctx.extra != null && ctx.extra.get("systemId") != null
|
|
? String.valueOf(ctx.extra.get("systemId")) : "developSystem";
|
|
String page = ctx.enCode;
|
|
String appCode = ctx.appCode != null ? ctx.appCode : systemId;
|
|
|
|
// 3. urlAddress 模板: /ssw/{systemId}/{enCode}?token=${jnpfToken}&appCode=${jnpfAppCode}
|
|
// 优先用 ctx.urlAddress (含 token 模板), 否则自动拼
|
|
String urlAddress = ctx.urlAddress != null ? ctx.urlAddress :
|
|
String.format("/ssw/%s/%s?token=${jnpfToken}&appCode=${jnpfAppCode}", systemId, page);
|
|
String pageAddress = ctx.pageAddress != null ? ctx.pageAddress : urlAddress;
|
|
|
|
// 4. 构造 entity (LinkedHashMap 保 key 顺序, 跟 baseline 字段序对齐)
|
|
Map<String, Object> entity = new LinkedHashMap<>();
|
|
entity.put("fullName", ctx.name);
|
|
entity.put("enCode", ctx.enCode);
|
|
entity.put("parentId", ctx.parentId);
|
|
entity.put("category", "Web");
|
|
entity.put("type", 7); // int, 盲点 JNPF-30
|
|
entity.put("webType", ctx.webType);
|
|
entity.put("icon", ctx.icon == null ? "icon-ym icon-ym-form" : ctx.icon);
|
|
entity.put("urlAddress", urlAddress);
|
|
entity.put("pageAddress", pageAddress);
|
|
entity.put("linkTarget", "_blank"); // ← 关键: 触发 Link 组件 init() 的 ${jnpfToken} 替换
|
|
|
|
// propertyJson: 4 字段 (moduleId + iconBackgroundColor + isTree + webType=7)
|
|
Map<String, Object> pj = new LinkedHashMap<>();
|
|
pj.put("moduleId", "");
|
|
pj.put("iconBackgroundColor", "");
|
|
pj.put("isTree", 0);
|
|
pj.put("webType", 7);
|
|
entity.put("propertyJson", mapper.writeValueAsString(pj));
|
|
|
|
// moduleId 实体字段 = "" (与 propertyJson.moduleId 一致, 盲点 JNPF-30)
|
|
entity.put("moduleId", "");
|
|
|
|
// sortCode: extra 优先, 默认 0
|
|
Object sortCodeObj = ctx.extra != null ? ctx.extra.get("sortCode") : null;
|
|
entity.put("sortCode", sortCodeObj != null ? sortCodeObj : 0);
|
|
|
|
entity.put("enabledMark", 1);
|
|
entity.put("systemId", systemId); // no-spa 必传 (子应用挂载)
|
|
if (ctx.description != null) entity.put("description", ctx.description);
|
|
entity.put("noShow", 0);
|
|
|
|
// 4 authorize 字段 (AuthorizeFieldsBuilder 兼容)
|
|
AuthorizeFieldsBuilder.apply(entity, ctx);
|
|
|
|
return mapper.writeValueAsString(entity);
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("NoSpaMenuBuilder failed: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
}
|