diff --git a/scripts/menu-baseline-diff.sh b/scripts/menu-baseline-diff.sh
index f68aeb1..833ad2a 100755
--- a/scripts/menu-baseline-diff.sh
+++ b/scripts/menu-baseline-diff.sh
@@ -1,17 +1,20 @@
#!/bin/bash
-# v13-f2 Task 2.3 Web 菜单 0 误差验证脚本 (生成器侧 0 误差)
+# v13-f2 Task 2.3 + 2.6 菜单 0 误差验证脚本 (生成器侧 0 误差)
#
-# 校验 WebMenuBuilder 生成的 entity 跟 116 baseline Web menu 的字段集一致:
-# 1. 字段名集合一致 (key set 0 误差)
+# 校验 WebMenuBuilder + LinkMenuBuilder + ButtonMenuBuilder + NoSpaMenuBuilder + DataReportMenuBuilder
+# 生成的 entity 跟 baseline 样本的字段集一致:
+# 1. Web 字段名集合一致 (key set 0 误差, 116 baseline)
# 2. 必含关键字段都在 (fullName/enCode/parentId/category/type/propertyJson/moduleId/linkTarget)
# 3. 4 authorize 字段名匹配 (JNPF 真实字段名: isButtonAuthorize/isColumnAuthorize/isDataAuthorize/isFormAuthorize)
-# 4. propertyJson 字段名集合一致 (0 冗余: 1/2 type 2 字段, 3/9 type 4 字段)
-# 5. category = "Web"
-# 6. linkTarget = "_self"
+# 4. propertyJson 字段名集合一致 (0 冗余)
+# 5. category = "Web" (Web/NoSpa/Link/Button) / "dataReport" (DataReport)
+# 6. linkTarget 按 type 区分
+# 7. v13-f2 Task 2.6: Link 必含 http(s)://, 4 authorize=0, type=7
+# 8. v13-f2 Task 2.6: Button 无 urlAddress/pageAddress, 4 authorize=0, type=0, parentId != -1
set -e
cd /home/ubuntu/ccWorkDir/.worktrees/v13-f2-menu
-# 1. 用 WebMenuBuilder 生成 4 种典型 entity, 写到一个 jsonl
+# 1. 用 menu builder 生成多种典型 entity, 写到 target/baseline-dump/
JAR=$(ls ssw-dacli/target/ssw-dacli-*.jar | grep -v sources | head -1)
[ -z "$JAR" ] && { echo "no jar, build first"; exit 1; }
@@ -42,20 +45,66 @@ print('=== Baseline propertyJson 字段集 (按 type) ===')
for t in sorted(pj_field_sets):
print(f' type={t}: ' + str(sorted(pj_field_sets[t])))
print()
+"
-# 3. 校验 WebMenuBuilder 输出字段集
-import subprocess
-from pathlib import Path
-# 跑 WebMenuBuilderTest 拿到 dump
-# 但更简单: 直接用 jar 跑测试
-print('=== 验证 WebMenuBuilder 输出 ===')
-print('跑: java -cp $JAR org.junit...')
-" 2>&1 | head -30
-
-# 4. 直接用 mvn 跑测试, 跑成功即 0 误差
-mvn test -pl ssw-dacli -Dtest='WebMenuBuilderTest' -q 2>&1 | tail -10
+# 3. 直接用 mvn 跑测试, 跑成功即 0 误差
+mvn test -pl ssw-dacli -q 2>&1 | tail -25
+# 4. v13-f2 Task 2.6 Link/Button 专项验证 (无 DB baseline, 验证 builder 输出字段结构)
echo ""
echo "=========================================="
-echo "Web 菜单 0 误差: 4/4 @Test 通过 + baseline 116 字段集一致"
+echo "Link + Button 菜单 0 误差验证 (Task 2.6)"
echo "=========================================="
+python3 -c "
+import json
+from pathlib import Path
+
+# 验证 LinkMenuBuilder 生成的 3 个例子
+link_dump = Path('target/baseline-dump/LinkMenuBuilder.json')
+if not link_dump.exists():
+ link_dump = Path('ssw-dacli/target/baseline-dump/LinkMenuBuilder.json')
+if link_dump.exists():
+ examples = json.loads(link_dump.read_text())
+ print(f'Link examples: {len(examples)}')
+ for i, e in enumerate(examples):
+ url = e.get('urlAddress', '')
+ assert e['category'] == 'Web', f'[{i}] category 必须 Web'
+ assert e['type'] == 7, f'[{i}] type 必须 7 (int), 实际: {type(e[\"type\"]).__name__} {e[\"type\"]}'
+ assert e['linkTarget'] == '_blank', f'[{i}] linkTarget 必须 _blank'
+ assert e['isButtonAuthorize'] == 0, f'[{i}] isButtonAuthorize 必须 0'
+ assert e['isColumnAuthorize'] == 0, f'[{i}] isColumnAuthorize 必须 0'
+ assert e['isDataAuthorize'] == 0, f'[{i}] isDataAuthorize 必须 0'
+ assert e['isFormAuthorize'] == 0, f'[{i}] isFormAuthorize 必须 0'
+ assert url.startswith(('http://', 'https://')), f'[{i}] urlAddress 必须 http(s):// 开头: {url}'
+ pj = json.loads(e['propertyJson'])
+ assert pj.get('moduleId') == '', f'[{i}] pj.moduleId 必须空'
+ assert 'webType' not in pj, f'[{i}] Link 菜单 pj 不应含 webType'
+ print(f' Link 0 误差: {len(examples)}/{len(examples)} 验证通过')
+else:
+ print(' Link dump not found, run LinkMenuBuilderTest first')
+
+# 验证 ButtonMenuBuilder 生成的 4 个例子
+btn_dump = Path('target/baseline-dump/ButtonMenuBuilder.json')
+if not btn_dump.exists():
+ btn_dump = Path('ssw-dacli/target/baseline-dump/ButtonMenuBuilder.json')
+if btn_dump.exists():
+ examples = json.loads(btn_dump.read_text())
+ print(f'Button examples: {len(examples)}')
+ for i, e in enumerate(examples):
+ assert e['category'] == 'Web', f'[{i}] category 必须 Web'
+ assert e['type'] == 0, f'[{i}] type 必须 0 (int), 实际: {type(e[\"type\"]).__name__} {e[\"type\"]}'
+ assert e['linkTarget'] == '_self', f'[{i}] linkTarget 必须 _self'
+ assert e['isButtonAuthorize'] == 0, f'[{i}] isButtonAuthorize 必须 0'
+ assert e['isColumnAuthorize'] == 0, f'[{i}] isColumnAuthorize 必须 0'
+ assert e['isDataAuthorize'] == 0, f'[{i}] isDataAuthorize 必须 0'
+ assert e['isFormAuthorize'] == 0, f'[{i}] isFormAuthorize 必须 0'
+ assert 'urlAddress' not in e, f'[{i}] Button 菜单不应有 urlAddress'
+ assert 'pageAddress' not in e, f'[{i}] Button 菜单不应有 pageAddress'
+ assert e['parentId'] != '-1', f'[{i}] parentId 必须 != -1'
+ pj = json.loads(e['propertyJson'])
+ assert pj.get('moduleId') == '', f'[{i}] pj.moduleId 必须空'
+ assert 'webType' not in pj, f'[{i}] Button 菜单 pj 不应含 webType'
+ print(f' Button 0 误差: {len(examples)}/{len(examples)} 验证通过')
+else:
+ print(' Button dump not found, run ButtonMenuBuilderTest first')
+"
diff --git a/scripts/menu-baseline/developSystem-link-button.jsonl b/scripts/menu-baseline/developSystem-link-button.jsonl
new file mode 100644
index 0000000..e69de29
diff --git a/scripts/menu-baseline/link-button-decisions.md b/scripts/menu-baseline/link-button-decisions.md
new file mode 100644
index 0000000..a159571
--- /dev/null
+++ b/scripts/menu-baseline/link-button-decisions.md
@@ -0,0 +1,166 @@
+# v13-f2 Task 2.6 — Link + Button 菜单 0 误差决策
+
+> **v13-f2 Task 2.6 决策**: Link (外链) + Button 菜单 0 误差打磨
+> **2026-06-12**
+
+---
+
+## 1. 现状调研
+
+### 1.1 DB 端 0 样本
+
+| 维度 | 结果 |
+|------|------|
+| `base_module WHERE f_category IN ('Link','Button')` | **0 行** |
+| `base_module WHERE f_type = 0` | **0 行** (type=0 不存在) |
+| `base_module WHERE f_link_target = '_blank' AND f_type = 7` | 1 行 (`onlineDev.dataScreen`, no-spa `${dataV}?token=...`) |
+| `base_module WHERE f_link_target = '_blank' AND f_type = 6` | 3 行 (大屏类型) |
+
+**结论**: JNPF 平台 DB 没有 category=Link/Button 的字段,**Link/Button 是 JNPF 菜单设计器 UI 层的概念**,不是 DB 字段值。
+
+### 1.2 前端映射 (Form.vue line 75-87)
+
+```ts
+const typeData: any[] = [
+ { id: 1, fullName: '目录' },
+ { id: 11, fullName: '表单回传' },
+ { id: 2, fullName: '页面' },
+ { id: 3, fullName: '在线表单' },
+ { id: 9, fullName: '流程' },
+ { id: 4, fullName: '字典' },
+ { id: 10, fullName: '报表' },
+ { id: 5, fullName: '报表(原)' },
+ { id: 6, fullName: '大屏' },
+ { id: 8, fullName: '门户' },
+ { id: 7, fullName: '外链' }, // ← Link 在 JNPF 设计器里就是 type=7
+];
+```
+
+**没有独立的 "Button" type**。Button 概念 = 父菜单的子节点 (add/edit/delete 等权限按钮)。
+
+### 1.3 前端 authorize 规则 (Form.vue line 271-295)
+
+```ts
+function onTypeChange(val) {
+ if ([2, 3, 4, 9, 11].includes(val)) {
+ state.dataForm.isButtonAuthorize = 1;
+ state.dataForm.isColumnAuthorize = 1;
+ state.dataForm.isFormAuthorize = 1;
+ state.dataForm.isDataAuthorize = 1;
+ } else {
+ // type = 1, 5, 6, 7, 8, 10 全部走 0
+ state.dataForm.isButtonAuthorize = 0;
+ state.dataForm.isColumnAuthorize = 0;
+ state.dataForm.isFormAuthorize = 0;
+ state.dataForm.isDataAuthorize = 0;
+ }
+ state.dataForm.linkTarget = val == 6 ? '_blank' : '_self';
+}
+```
+
+**关键**:
+- type=7 (外链) → 4 authorize 全 **0** (修正原 LinkMenuBuilder 的 bug: 写 1 错了)
+- 任何 type 不在 [2,3,4,9,11] 列表 → 4 authorize 全 0
+
+### 1.4 唯一 _blank + type=7 DB 样本 (实测)
+
+| 字段 | 值 |
+|------|-----|
+| id | `643238393602125` |
+| type | 7 |
+| category | Web |
+| urlAddress | `${dataV}?token=${jnpfToken}&appCode=${jnpfAppCode}` |
+| linkTarget | `_blank` |
+| 4 authorize | **1, 1, 1, 1** ← 这是 no-spa 模式 (system 模板, 不是普通外链) |
+| propertyJson | `{"moduleId":"","iconBackgroundColor":"","isTree":0}` (3 字段) |
+
+> 注: 这是 JNPF 平台系统自带的"大屏设计"菜单 (no-spa 模式), 不是普通外链. 普通外链没有 DB 样本.
+
+---
+
+## 2. 决策 (按 JNPF Form.vue 前端规则 + DB 实测)
+
+### 2.1 LinkMenuBuilder (外链) 决策
+
+| 字段 | 值 | 依据 |
+|------|-----|------|
+| type | **7** (int) | Form.vue line 73, 86: type=7 = 外链 |
+| category | **Web** | 跟 no-spa 一致 (都是 type=7) |
+| linkTarget | **`_blank`** | 跟所有 _blank 样本一致 |
+| urlAddress | **http(s)://...** 透传 | Form.vue line 297: '地址以http://或https://为开头' |
+| pageAddress | = urlAddress | 跟 no-spa 一致 |
+| 4 authorize | **0, 0, 0, 0** | Form.vue line 281-291: type=7 不在 [2,3,4,9,11] → 全 0 |
+| moduleId | **""** | 实体字段, 跟 propertyJson.moduleId 同步 (盲点 JNPF-30) |
+| icon | `icon-ym icon-ym-link` | 默认 |
+| propertyJson | **3 字段** `{moduleId:"", iconBackgroundColor:"", isTree:0}` | 跟唯一 type=7 样本一致 (3 字段) |
+| sortCode | 0 | 默认 |
+| enabledMark | 1 | 默认 |
+| noShow | 0 | 默认 |
+| systemId | ctx.extra.systemId | 透传 |
+
+**修正原 LinkMenuBuilder 的 bug**:
+- 原 stub `entity.put("type", "7")` → 改为 `entity.put("type", 7)` (int, 盲点 JNPF-30)
+- 原 stub `entity.put("isButtonAuthorize", 1)` 等 4 个全 1 → 改为全 0 (Form.vue line 287-290)
+- 原 stub `entity.put("category", "Web")` → 保留
+- 原 stub `pj.put("webType", 7)` → 删除 (跟唯一 DB 样本 3 字段一致, 不是 no-spa 4 字段)
+
+### 2.2 ButtonMenuBuilder (按钮权限) 决策
+
+> **JNPF 设计器中 "Button" 没有独立 type**. Button 概念 = 父菜单的子节点 (add/edit/delete 等).
+> 在 DB 中通常体现为: parent 是 Web 菜单, child 是无页面 (无 urlAddress) 的子节点, type 可以是 0 (老 JNPF) 或 1 (新 JNPF).
+
+| 字段 | 值 | 依据 |
+|------|-----|------|
+| type | **0** (int) | 老 JNPF Button 概念, ButtonMenuBuilder 沿用 |
+| category | **Web** | 跟 Web 父菜单一致 (按钮是 Web 菜单的子) |
+| linkTarget | **`_self`** (默认) | 按钮不跳转 |
+| urlAddress | **null/不写** | 按钮无页面 |
+| pageAddress | **null/不写** | 按钮无页面 |
+| 4 authorize | **0, 0, 0, 0** | Form.vue line 287-290: type=0 不在 [2,3,4,9,11] → 全 0 |
+| moduleId | **""** | 按钮无关联表单 |
+| icon | 用户指定 (默认 `""`) | 按钮通常无图标 |
+| propertyJson | **3 字段** `{moduleId:"", iconBackgroundColor:"", isTree:0}` | 跟 Link 一致 |
+| sortCode | 0 | 默认 |
+| enabledMark | 1 | 默认 |
+| noShow | 0 | 默认 |
+| systemId | ctx.extra.systemId | 透传 |
+| parentId | **必填 != -1** | 按钮必须挂到父菜单下 |
+
+**修正原 ButtonMenuBuilder 的 bug**:
+- 原 stub `entity.put("type", "0")` → 改为 `entity.put("type", 0)` (int, 盲点 JNPF-30)
+- 原 stub 4 authorize = 1 (虽然没显式写但 AuthorizeFieldsBuilder 默认 1) → 改为全 0
+- 原 stub `linkTarget = "_self"` → 保留
+
+---
+
+## 3. 跟其它 builder 的关系
+
+| Builder | category() | webType | type | linkTarget | 4 authorize | urlAddress | pj |
+|---------|-----------|---------|------|------------|-------------|-----------|-----|
+| **WebMenuBuilder** | "Web" | 1-3, 9 | 1/2/3/9 | _self | 全 1 | model/... | 3-4 字段 |
+| **NoSpaMenuBuilder** | "Web" | 7 | 7 | _blank | 全 1 | /ssw/... | 4 字段含 webType=7 |
+| **DataReportMenuBuilder** | "dataReport" | 8/10 | 8/10 | _self/null | 全 0 | report/portal/... | 4 字段 webType=null |
+| **LinkMenuBuilder** ← | "Link" | 7 | 7 | _blank | **全 0** | http(s)://... | 3 字段 |
+| **ButtonMenuBuilder** ← | "Button" | 0 | 0 | _self | **全 0** | null | 3 字段 |
+
+---
+
+## 4. 0 误差验证方法
+
+**没有 DB baseline 样本** — 0 误差 = 字段结构 + 值匹配 JNPF 前端 Form.vue line 281-291 规则.
+
+```bash
+mvn test -pl ssw-dacli -Dtest='LinkMenuBuilderTest,ButtonMenuBuilderTest' -q
+# 8 个 @Test 通过
+```
+
+---
+
+## 5. 总结
+
+| 项 | Link | Button |
+|----|------|--------|
+| DB 样本 | 0 个 (无 baseline) | 0 个 (无 baseline) |
+| 决策依据 | JNPF Form.vue line 73, 86, 281-291, 297 | JNPF Form.vue line 281-291 (无独立 Button type) |
+| 0 误差保证 | 测试断言字段值匹配前端规则 | 测试断言字段值匹配前端规则 |
+| Link ↔ NoSpa 区别 | Link: http(s):// 外部, pj 3 字段, 4 auth=0 | NoSpa: /ssw/ 平台内, pj 4 字段含 webType, 4 auth=1 |
diff --git a/scripts/menu-baseline/workSystem-link-button.jsonl b/scripts/menu-baseline/workSystem-link-button.jsonl
new file mode 100644
index 0000000..e69de29
diff --git a/ssw-dacli/src/main/java/ssw/dacli/menu/builder/ButtonMenuBuilder.java b/ssw-dacli/src/main/java/ssw/dacli/menu/builder/ButtonMenuBuilder.java
index 2da52a9..8b389ad 100644
--- a/ssw-dacli/src/main/java/ssw/dacli/menu/builder/ButtonMenuBuilder.java
+++ b/ssw-dacli/src/main/java/ssw/dacli/menu/builder/ButtonMenuBuilder.java
@@ -6,16 +6,40 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
- * 按钮菜单 builder (Button)
+ * 按钮菜单 builder (Button, type=0)
*
- * 按钮菜单是菜单的子项, 用于按钮级权限控制 (添加/编辑/删除/导入/导出 等)。
+ *
JNPF 平台没有独立 "Button" type, Button 概念 = 父菜单的子节点 (add/edit/delete 等按钮权限).
+ * 老 JNPF 用 type=0 表示按钮, 本 builder 沿用此惯例用于按钮级权限控制场景.
*
- * 关键点:
- * - type=0 (按钮, 不同于 type=1 目录)
- * - parentId = 父菜单 ID (不能是 -1)
- * - 不带 urlAddress / pageAddress
- * - enCode 通常是 "add" / "edit" / "delete" / "batch" 等动词
- * - 不带 moduleId
+ *
0 误差对齐 (JNPF Form.vue line 281-291 实测, v13-f2 Task 2.6 决策):
+ *
+ * - type = 0 (int, 老 JNPF Button 概念, 盲点 JNPF-30)
+ * - category = "Web" (按钮是 Web 父菜单的子节点, 跟父菜单一致)
+ * - parentId 必填 != -1 (按钮必须挂到具体菜单下, 不能是顶级)
+ * - linkTarget = "_self" (按钮不跳转, 默认 _self)
+ * - urlAddress = null (按钮无页面, 不写字段)
+ * - pageAddress = null (按钮无页面, 不写字段)
+ * - 4 authorize 字段全 0 (Form.vue line 287-290: type=0 不在 [2,3,4,9,11] 列表 → 全 0)
+ * - moduleId = "" (按钮无关联表单, 跟 propertyJson.moduleId 同步, 盲点 JNPF-30)
+ * - propertyJson 3 字段 {moduleId:"", iconBackgroundColor:"", isTree:0} (跟 Link 一致)
+ * - icon 用户指定 (默认 "") (按钮通常无图标)
+ * - enabledMark = 1, noShow = 0, sortCode = 0 (默认)
+ * - systemId 透传 (parent menu 在子应用下)
+ *
+ *
+ * enCode 命名约定: add / edit / delete / batch / import / export / print / download / upload 等动词.
+ *
+ *
与 WebMenuBuilder 区别:
+ *
+ * - Web(type=1/2/3/9): 有 urlAddress/pageAddress/moduleId, 4 authorize=1
+ * - Button: 无 urlAddress/pageAddress, 4 authorize=0, type=0
+ *
+ *
+ * 与 LinkMenuBuilder 区别:
+ *
+ * - Link(type=7): 有 http(s):// urlAddress, linkTarget=_blank
+ * - Button: 无 urlAddress, linkTarget=_self, type=0
+ *
*
* @author v13-f2 Agent-F2
*/
@@ -31,36 +55,66 @@ public class ButtonMenuBuilder implements MenuBuilder {
@Override
public String buildMenuEntity(MenuBuildContext ctx) {
try {
- if ("-1".equals(ctx.parentId) || ctx.parentId == null) {
+ // 1. 校验 parentId 必填且 != -1 (按钮必须挂到具体菜单下)
+ if (ctx.parentId == null || "-1".equals(ctx.parentId)) {
throw new IllegalArgumentException(
- "Button 菜单必须挂到具体菜单下, parentId 不能是 -1"
+ "Button 菜单必须挂到具体菜单下, parentId 不能是 -1 或 null, 实际: " + ctx.parentId
);
}
+ // 2. type=0 (int, 盲点 JNPF-30)
+ int type = ctx.menuType != null ? Integer.parseInt(ctx.menuType) : 0;
+ if (type != 0) {
+ throw new IllegalArgumentException(
+ "Button 菜单 type 必须是 0, 实际: " + type
+ );
+ }
+
+ // 3. 构造 entity (LinkedHashMap 保 key 顺序)
Map entity = new LinkedHashMap<>();
entity.put("fullName", ctx.name);
entity.put("enCode", ctx.enCode);
entity.put("parentId", ctx.parentId);
- entity.put("type", "0"); // JNPF 按钮 type=0
- entity.put("enabledMark", 1);
- entity.put("sortCode", 0);
entity.put("category", "Web");
- entity.put("linkTarget", "_self");
+ entity.put("type", type); // int 0, 盲点 JNPF-30
+ entity.put("webType", ctx.webType == 0 ? 0 : ctx.webType); // 透传 (默认 0)
entity.put("icon", ctx.icon == null ? "" : ctx.icon);
- // 按钮: 不带 urlAddress / pageAddress / moduleId
+ entity.put("linkTarget", "_self");
+ // 按钮: 不带 urlAddress / pageAddress / moduleId (留空)
- // propertyJson: 按钮空结构
+ // 4 authorize 字段全 0 (Form.vue line 287-290: type=0 不在 [2,3,4,9,11] → 全 0)
+ entity.put("isButtonAuthorize", 0);
+ entity.put("isColumnAuthorize", 0);
+ entity.put("isDataAuthorize", 0);
+ entity.put("isFormAuthorize", 0);
+
+ // propertyJson: 3 字段 (跟 Link 一致)
Map pj = new LinkedHashMap<>();
pj.put("moduleId", "");
pj.put("iconBackgroundColor", "");
pj.put("isTree", 0);
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("noShow", 0);
+
+ // systemId 透传
+ if (ctx.extra != null && ctx.extra.get("systemId") != null) {
+ entity.put("systemId", ctx.extra.get("systemId"));
+ }
+
if (ctx.description != null) entity.put("description", ctx.description);
- AuthorizeFieldsBuilder.apply(entity, ctx);
-
return mapper.writeValueAsString(entity);
+ } catch (IllegalArgumentException e) {
+ throw e;
} catch (Exception e) {
throw new RuntimeException("ButtonMenuBuilder failed: " + e.getMessage(), e);
}
diff --git a/ssw-dacli/src/main/java/ssw/dacli/menu/builder/LinkMenuBuilder.java b/ssw-dacli/src/main/java/ssw/dacli/menu/builder/LinkMenuBuilder.java
index 2e9b508..79b52b6 100644
--- a/ssw-dacli/src/main/java/ssw/dacli/menu/builder/LinkMenuBuilder.java
+++ b/ssw-dacli/src/main/java/ssw/dacli/menu/builder/LinkMenuBuilder.java
@@ -6,18 +6,37 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
- * 外链 Link 菜单 builder (type=7 但不带 no-spa 路径)
+ * 外链 Link 菜单 builder (type=7 + linkTarget=_blank + 完整 http(s):// URL)
*
- * 用于挂外部链接 (不是 no-spa 平台内 HTML, 而是 http://... 之类)。
+ * 对应 JNPF 设计器 typeData 中 id=7 '外链' 选项 (Form.vue line 73, 86).
+ * 用于挂外部链接 (https://example.com/...), 浏览器侧点击新窗口打开.
*
- * 关键点:
- * - linkTarget = _blank (新窗口)
- * - urlAddress = 完整 http(s):// 链接
- * - 不带 moduleId
+ *
0 误差对齐 (JNPF Form.vue line 271-295 实测, v13-f2 Task 2.6 决策):
+ *
+ * - type = 7 (int, 跟 Web menu 一致, 盲点 JNPF-30)
+ * - category = "Web" (type=7 跟 no-spa 一致, 都是 Web 子类)
+ * - linkTarget = "_blank" (新窗口, Form.vue line 292: val==6 才 _blank 实际只对 type=6 生效; type=7 默认 _self, 但外链场景必改 _blank)
+ * - urlAddress = 完整 http(s):// 链接 (Form.vue line 297: '地址以http://或https://为开头')
+ * - pageAddress = urlAddress (跟 no-spa 一致)
+ * - 4 authorize 字段全 0 (Form.vue line 287-290: type=7 不在 [2,3,4,9,11] 列表 → 全 0)
+ * - moduleId = "" (实体字段跟 propertyJson.moduleId 同步, 盲点 JNPF-30)
+ * - propertyJson 3 字段 {moduleId:"", iconBackgroundColor:"", isTree:0} (跟 DB 唯一 type=7 样本一致, 不含 webType)
+ * - icon = "icon-ym icon-ym-link" (默认外链图标)
+ * - enabledMark = 1, noShow = 0, sortCode = 0 (默认)
+ * - systemId 透传 (parent menu 在子应用下)
+ *
*
- * 与 NoSpaMenuBuilder 区别:
- * - NoSpa: /ssw/{app}/... 平台内, 走 nginx 代理, 用 token 模板
- * - Link: 完整外部 URL, 不需要 token 模板
+ * 与 NoSpaMenuBuilder 区别 (type 都是 7):
+ *
+ * - NoSpa: /ssw/{app}/... 平台内静态, pj 4 字段含 webType=7, 4 authorize=1
+ * - Link: 完整 http(s):// 外部链接, pj 3 字段无 webType, 4 authorize=0
+ *
+ *
+ * 与 WebMenuBuilder 区别:
+ *
+ * - Web(type=1/2/3/9): linkTarget=_self, 4 authorize=1, 走 SPA 路由
+ * - Link: linkTarget=_blank, 4 authorize=0, 走浏览器新窗口
+ *
*
* @author v13-f2 Agent-F2
*/
@@ -33,9 +52,10 @@ public class LinkMenuBuilder implements MenuBuilder {
@Override
public String buildMenuEntity(MenuBuildContext ctx) {
try {
+ // 1. 校验 urlAddress 必填且以 http:// 或 https:// 开头 (Form.vue line 297)
if (ctx.urlAddress == null) {
throw new IllegalArgumentException(
- "Link 菜单必须提供 urlAddress (完整 http:// 链接)"
+ "Link 菜单必须提供 urlAddress (完整 http(s):// 链接)"
);
}
if (!ctx.urlAddress.startsWith("http://") && !ctx.urlAddress.startsWith("https://")) {
@@ -44,36 +64,60 @@ public class LinkMenuBuilder implements MenuBuilder {
);
}
+ // 2. type=7 (int, 盲点 JNPF-30)
+ int type = ctx.menuType != null ? Integer.parseInt(ctx.menuType) : 7;
+ if (type != 7) {
+ throw new IllegalArgumentException(
+ "Link 菜单 type 必须是 7, 实际: " + type
+ );
+ }
+
+ // 3. 构造 entity (LinkedHashMap 保 key 顺序)
Map entity = new LinkedHashMap<>();
entity.put("fullName", ctx.name);
entity.put("enCode", ctx.enCode);
entity.put("parentId", ctx.parentId);
- entity.put("type", "7");
- entity.put("enabledMark", 1);
- entity.put("sortCode", 0);
entity.put("category", "Web");
- entity.put("linkTarget", "_blank");
- entity.put("isButtonAuthorize", 1);
- entity.put("isColumnAuthorize", 1);
- entity.put("isDataAuthorize", 1);
- entity.put("isFormAuthorize", 1);
+ entity.put("type", type); // int 7, 盲点 JNPF-30
+ entity.put("webType", ctx.webType == 0 ? 7 : ctx.webType); // 透传 (默认 7)
entity.put("icon", ctx.icon == null ? "icon-ym icon-ym-link" : ctx.icon);
entity.put("urlAddress", ctx.urlAddress);
entity.put("pageAddress", ctx.urlAddress);
+ entity.put("linkTarget", "_blank");
- // propertyJson: Link 不带 moduleId
+ // 4 authorize 字段全 0 (Form.vue line 287-290: type=7 不在 [2,3,4,9,11] → 全 0)
+ entity.put("isButtonAuthorize", 0);
+ entity.put("isColumnAuthorize", 0);
+ entity.put("isDataAuthorize", 0);
+ entity.put("isFormAuthorize", 0);
+
+ // propertyJson: 3 字段 (跟 DB 唯一 type=7 样本一致, 不含 webType)
Map pj = new LinkedHashMap<>();
pj.put("moduleId", "");
- pj.put("webType", 7);
pj.put("iconBackgroundColor", "");
pj.put("isTree", 0);
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("noShow", 0);
+
+ // systemId 透传
+ if (ctx.extra != null && ctx.extra.get("systemId") != null) {
+ entity.put("systemId", ctx.extra.get("systemId"));
+ }
+
if (ctx.description != null) entity.put("description", ctx.description);
- AuthorizeFieldsBuilder.apply(entity, ctx);
-
return mapper.writeValueAsString(entity);
+ } catch (IllegalArgumentException e) {
+ throw e;
} catch (Exception e) {
throw new RuntimeException("LinkMenuBuilder failed: " + e.getMessage(), e);
}
diff --git a/ssw-dacli/src/test/java/ssw/dacli/menu/builder/ButtonMenuBuilderTest.java b/ssw-dacli/src/test/java/ssw/dacli/menu/builder/ButtonMenuBuilderTest.java
new file mode 100644
index 0000000..3715f56
--- /dev/null
+++ b/ssw-dacli/src/test/java/ssw/dacli/menu/builder/ButtonMenuBuilderTest.java
@@ -0,0 +1,218 @@
+package ssw.dacli.menu.builder;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * v13-f2 Task 2.6 — ButtonMenuBuilder 单元测试 (4 用例).
+ *
+ * Button 菜单 (type=0, 父菜单的子节点, 按钮级权限) 字段结构校验.
+ * 0 误差对齐 JNPF Form.vue line 281-291 实测规则 (无 DB baseline, 因 JNPF 平台无 type=0 的 DB 行).
+ *
+ *
关键字段 (跟前端规则 0 误差):
+ *
+ * - type = 0 (int, 老 JNPF Button 概念, 盲点 JNPF-30)
+ * - category = "Web" (按钮是 Web 父菜单的子节点)
+ * - parentId 必填 != -1 (按钮必须挂到具体菜单下)
+ * - linkTarget = "_self" (按钮不跳转)
+ * - urlAddress = null / 不存在 (按钮无页面)
+ * - pageAddress = null / 不存在 (按钮无页面)
+ * - 4 authorize 字段全 0 (type=0 不在 [2,3,4,9,11] 列表)
+ * - moduleId = "" (按钮无关联表单, 跟 pj.moduleId 同步, 盲点 JNPF-30)
+ * - propertyJson 3 字段 {moduleId, iconBackgroundColor, isTree}
+ *
+ */
+public class ButtonMenuBuilderTest {
+
+ private static final ObjectMapper M = new ObjectMapper();
+
+ /**
+ * 构造标准 Button 菜单上下文 (按钮挂在具体父菜单下)
+ */
+ private MenuBuildContext buildCtx(String name, String enCode, String parentId) {
+ Map extra = new HashMap<>();
+ extra.put("systemId", "workSystem");
+ extra.put("sortCode", 0);
+ MenuBuildContext ctx = MenuBuildContext.of(name, enCode, parentId, null, 0);
+ ctx.extra = extra;
+ return ctx;
+ }
+
+ @Test
+ public void testButton_basic() throws Exception {
+ // 标准按钮菜单 (挂在父菜单 id=parent123 下)
+ MenuBuildContext ctx = buildCtx("新增", "add", "parent123");
+ String json = new ButtonMenuBuilder().buildMenuEntity(ctx);
+ Map entity = M.readValue(json, Map.class);
+
+ // 顶层关键键 (v13-f2 Task 2.6)
+ assertEquals("新增", entity.get("fullName"));
+ assertEquals("add", entity.get("enCode"));
+ assertEquals("parent123", entity.get("parentId"));
+ assertEquals("Web", entity.get("category"));
+ assertEquals(0, entity.get("type")); // int, 盲点 JNPF-30
+ assertEquals(0, entity.get("webType"));
+ assertEquals("", entity.get("moduleId"));
+ assertEquals("_self", entity.get("linkTarget"));
+ assertEquals(1, entity.get("enabledMark"));
+ assertEquals(0, entity.get("noShow"));
+ assertEquals(0, entity.get("sortCode"));
+ assertEquals("workSystem", entity.get("systemId"));
+ assertEquals("", entity.get("icon")); // 默认空
+
+ // 4 authorize 字段全 0 (Form.vue line 287-290, type=0 不在 [2,3,4,9,11])
+ assertEquals(0, entity.get("isButtonAuthorize"));
+ assertEquals(0, entity.get("isColumnAuthorize"));
+ assertEquals(0, entity.get("isDataAuthorize"));
+ assertEquals(0, entity.get("isFormAuthorize"));
+
+ // 按钮无 urlAddress / pageAddress
+ assertFalse(entity.containsKey("urlAddress"),
+ "Button 菜单不应有 urlAddress");
+ assertFalse(entity.containsKey("pageAddress"),
+ "Button 菜单不应有 pageAddress");
+
+ // propertyJson 3 字段
+ String pjStr = (String) entity.get("propertyJson");
+ assertNotNull(pjStr);
+ Map pj = M.readValue(pjStr, Map.class);
+ assertEquals(3, pj.size(), "propertyJson 必须 3 字段 (不包含 webType)");
+ assertEquals("", pj.get("moduleId"));
+ assertEquals("", pj.get("iconBackgroundColor"));
+ assertEquals(0, pj.get("isTree"));
+ assertFalse(pj.containsKey("webType"), "Button 菜单 propertyJson 不应包含 webType");
+
+ // propertyJson.moduleId 一致性 (盲点 JNPF-30)
+ assertEquals(entity.get("moduleId"), pj.get("moduleId"));
+ }
+
+ @Test
+ public void testButton_noUrlAddress() throws Exception {
+ // 验证 urlAddress / pageAddress 不存在
+ MenuBuildContext ctx = buildCtx("编辑", "edit", "parent_abc");
+ String json = new ButtonMenuBuilder().buildMenuEntity(ctx);
+ Map entity = M.readValue(json, Map.class);
+
+ // 关键: 按钮无 urlAddress / pageAddress
+ assertFalse(entity.containsKey("urlAddress"),
+ "Button 菜单 entity 不应包含 urlAddress 字段");
+ assertFalse(entity.containsKey("pageAddress"),
+ "Button 菜单 entity 不应包含 pageAddress 字段");
+
+ // 即使外部传 urlAddress 也不写到 entity (按钮忽略)
+ MenuBuildContext ctxWithUrl = buildCtx("导入", "import", "parent_xyz");
+ ctxWithUrl.urlAddress = "https://should-be-ignored.com";
+ Map e2 = M.readValue(
+ new ButtonMenuBuilder().buildMenuEntity(ctxWithUrl), Map.class);
+ assertFalse(e2.containsKey("urlAddress"),
+ "Button 菜单应忽略 urlAddress, 不写到 entity");
+ assertFalse(e2.containsKey("pageAddress"),
+ "Button 菜单应忽略 pageAddress, 不写到 entity");
+
+ // 校验: parentId = -1 抛异常
+ MenuBuildContext badCtx = buildCtx("顶级按钮", "top_button", "-1");
+ assertThrows(IllegalArgumentException.class,
+ () -> new ButtonMenuBuilder().buildMenuEntity(badCtx));
+
+ // 校验: parentId = null 抛异常
+ MenuBuildContext badCtx2 = buildCtx("无parent", "no_parent", null);
+ assertThrows(IllegalArgumentException.class,
+ () -> new ButtonMenuBuilder().buildMenuEntity(badCtx2));
+ }
+
+ @Test
+ public void testButton_propertyJson() throws Exception {
+ // 验证 propertyJson 字段集 (3 字段, 跟 Link 一致)
+ MenuBuildContext ctx = buildCtx("删除", "delete", "parent_456");
+ String json = new ButtonMenuBuilder().buildMenuEntity(ctx);
+ Map entity = M.readValue(json, Map.class);
+ Map pj = M.readValue((String) entity.get("propertyJson"), Map.class);
+
+ // 必含 3 字段
+ assertTrue(pj.containsKey("moduleId"), "propertyJson must contain moduleId");
+ assertTrue(pj.containsKey("iconBackgroundColor"), "propertyJson must contain iconBackgroundColor");
+ assertTrue(pj.containsKey("isTree"), "propertyJson must contain isTree");
+
+ // 不应包含 webType
+ assertFalse(pj.containsKey("webType"), "Button 菜单 propertyJson 不含 webType");
+
+ // 字段值
+ assertEquals("", pj.get("moduleId"));
+ assertEquals("", pj.get("iconBackgroundColor"));
+ assertEquals(0, pj.get("isTree"));
+
+ // propertyJson.moduleId 一致性 (盲点 JNPF-30)
+ assertEquals(entity.get("moduleId"), pj.get("moduleId"));
+ }
+
+ @Test
+ public void testButton_dumpToFile() throws Exception {
+ // 4 个例子: add / edit / delete / import 常见按钮
+ ObjectMapper mapper = new ObjectMapper();
+ List