From c735f24c64822ef1368b85400beb7fbb16b077b6 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Sat, 20 Jun 2026 18:54:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=AE=BE=E8=AE=A1=E4=B8=AD=E5=BF=83):?= =?UTF-8?q?=20=E5=90=88=E5=B9=B6=E3=80=8C=E6=96=B0=E5=BB=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD/=E6=96=B0=E5=BB=BA=E4=B8=BB=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E3=80=8D=E4=B8=BA=E5=8D=95=E4=B8=80=E5=85=A5=E5=8F=A3=20+=20?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=B1=BB=E5=9E=8B=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 设计中心两个「新建」按钮(新建功能 / 新建主子表)合为一个「+ 新建功能」入口: 进去先选页面类型(维护型 CRUD / 树形 / 主子表),再走对应向导。扩展新页型只加一个 选项,不再加顶级按钮;recipe 类型从内部实现差异回归为向导内的一个选择。 - NewFeatureShell 重写:RecipeChooser 类型选择卡 → 按类型【构建时(JS)】分支向导步骤 (主子表才有「建子表」步及派生/汇总字段)。不依赖 amis 运行时 step hiddenOn—— amis Wizard.normalizeSteps 只在 props.data 变时重算,向导内选择改 store.data 不触发, 故 step 级动态跳步不可靠;类型进向导前定、构建时分支才健壮。 - 删 MasterDetailShell.tsx + /new-feature-md 路由 + 设计中心「新建主子表」按钮 → 设计中心回到「新建功能 + AI 建功能」两入口 - e2e:five-ring/master-detail 改为先点类型选择卡(dc-recipe-*)再进向导;3/3 绿,build 绿 Co-Authored-By: Claude Opus 4.8 (1M context) --- e2e/five-ring.spec.ts | 2 + e2e/master-detail.spec.ts | 94 ++++----- src/App.tsx | 4 +- src/pages/DesignCenterPage.tsx | 10 +- src/pages/MasterDetailShell.tsx | 180 ----------------- src/pages/NewFeatureShell.tsx | 347 +++++++++++++++++++++----------- 6 files changed, 276 insertions(+), 361 deletions(-) delete mode 100644 src/pages/MasterDetailShell.tsx diff --git a/e2e/five-ring.spec.ts b/e2e/five-ring.spec.ts index a4defcc..d06c022 100644 --- a/e2e/five-ring.spec.ts +++ b/e2e/five-ring.spec.ts @@ -70,6 +70,8 @@ test('人走五环 · 浏览器全程点穿(amis wizard:建实体 → 生成 await page.goto('/design-center'); await page.getByTestId('dc-new-feature').click(); await expect(page.getByTestId('new-feature-shell')).toBeVisible(); + // 先选页面类型 = 维护型 CRUD(统一入口的类型选择卡),再进向导。 + await page.getByTestId('dc-recipe-maintenance').click(); // ── 环①②·amis wizard 步1 建实体(combo minLength=1 自带一行字段)── await expect(page.getByPlaceholder('OA_DEMO')).toBeVisible({ timeout: 15_000 }); diff --git a/e2e/master-detail.spec.ts b/e2e/master-detail.spec.ts index c6f00da..ac9c987 100644 --- a/e2e/master-detail.spec.ts +++ b/e2e/master-detail.spec.ts @@ -1,18 +1,18 @@ /** - * 主子表(master-detail)· 浏览器全程点穿 e2e。 - * amis wizard 四步:①建主实体 → ②建子表(传 masterTable 后端自动加 MASTERID 外键) → ③生成主子页 - * (compile master-detail-v1,后端先 ensureLink 接线再编译) → ④发布。 + * 主子表(master-detail)· 浏览器全程点穿 e2e —— 走统一「新建功能」向导。 + * 设计中心「+ 新建功能」→ amis wizard:① 建实体(选「主子表」页面类型) → ②【主子表才出现】建子表 + * → ③ 生成主子页(compile master-detail-v1) → ④ 发布。 * 断言:发布后经 API 对主表 _ADD 提交主+子行,引擎按主 LIST 列级联落库(status 0);_LOAD 回读子行。 - * 后端走 8094(playwright.fivering.config 反代)。数据纪律:afterAll 删主/子实体;其余(RV/页/菜单/流)跑后 psql 清。 + * 后端走 8094(playwright.fivering.config 反代)。数据纪律:afterAll 删主/子实体;其余跑后 psql 清。 */ -import { expect, test } from '@playwright/test'; +import { expect, test, type Page } from '@playwright/test'; import http from 'node:http'; const BACKEND_PORT = 8094; const TS = Date.now(); const MASTER = `EIP4PT_MDW${TS}M`; const CHILD = `EIP4PT_MDW${TS}C`; -// 第二个用例(派生字段)专用表 +// 第二个用例(派生+汇总)专用表 const MASTER2 = `EIP4PT_MDD${TS}M`; const CHILD2 = `EIP4PT_MDD${TS}C`; @@ -49,6 +49,22 @@ function findInputTableColumn(node: any, colName: string): any { return null; } +// 登录 + 进统一新建功能向导 + 选「主子表」页面类型(使②建子表步出现)。 +async function openWizardAsMasterDetail(page: Page) { + await page.goto('/login'); + await page.getByRole('textbox').first().fill('admin'); + await page.locator('input[type="password"]').fill('111111'); + await page.getByRole('button', { name: '登录' }).click(); + await page.waitForURL((u) => !u.pathname.endsWith('/login'), { timeout: 15_000 }); + + await page.goto('/design-center'); + await page.getByTestId('dc-new-feature').click(); + await expect(page.getByTestId('new-feature-shell')).toBeVisible(); + // 先选页面类型 = 主子表(统一入口的类型选择卡)→ 进主子表向导(含②建子表步)。 + await page.getByTestId('dc-recipe-master-detail').click(); + await expect(page.getByPlaceholder('OA_DEMO')).toBeVisible({ timeout: 15_000 }); +} + test.afterAll(async () => { try { const tok = await adminToken(); await api('DELETE', `/api/meta/entity/${CHILD}`, tok); @@ -58,25 +74,13 @@ test.afterAll(async () => { } catch { /* best effort */ } }); -test('主子表 · 浏览器全程点穿(建主+子 → 生成主子页 → 发布 → 级联保存子行)', async ({ page }) => { +test('主子表 · 统一向导全程点穿(选主子表 → 建主+子 → 生成主子页 → 发布 → 级联保存子行)', async ({ page }) => { test.setTimeout(120_000); - - // 登录 - await page.goto('/login'); - await page.getByRole('textbox').first().fill('admin'); - await page.locator('input[type="password"]').fill('111111'); - await page.getByRole('button', { name: '登录' }).click(); - await page.waitForURL((u) => !u.pathname.endsWith('/login'), { timeout: 15_000 }); - - // 设计中心 → + 新建主子表 - await page.goto('/design-center'); - await page.getByTestId('dc-new-feature-md').click(); - await expect(page.getByTestId('master-detail-shell')).toBeVisible(); + await openWizardAsMasterDetail(page); // 步① 建主实体 - await expect(page.getByPlaceholder('OA_PURCHASE')).toBeVisible({ timeout: 15_000 }); - await page.getByPlaceholder('OA_PURCHASE').fill(MASTER); - await page.getByPlaceholder('采购申请').fill('采购申请'); + await page.getByPlaceholder('OA_DEMO').fill(MASTER); + await page.getByPlaceholder('演示(可选)').fill('采购申请'); await page.locator('.cxd-Select').first().click(); // 所属分类 await page.locator('.cxd-Select-option').first().click(); await page.getByRole('button', { name: '加字段' }).click(); @@ -85,19 +89,19 @@ test('主子表 · 浏览器全程点穿(建主+子 → 生成主子页 → await page.getByPlaceholder('标题').first().fill('标题'); await page.getByRole('button', { name: '保存并下一步' }).click(); - // 步② 建子表 + // 步② 建子表(选主子表后才出现) await expect(page.getByPlaceholder('OA_PURCHASE_ITEM')).toBeVisible({ timeout: 15_000 }); await page.getByPlaceholder('OA_PURCHASE_ITEM').fill(CHILD); await page.getByPlaceholder('采购明细').fill('采购明细'); - await page.getByRole('button', { name: '加字段' }).click(); + await page.getByRole('button', { name: '加子表字段' }).click(); await expect(page.getByPlaceholder('TITLE').first()).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('TITLE').first().fill('ITEMNAME'); await page.getByPlaceholder('标题').first().fill('物料'); await page.getByRole('button', { name: '保存并下一步' }).click(); // 步③ 生成主子页 - await expect(page.getByPlaceholder('采购申请(主子)')).toBeVisible({ timeout: 20_000 }); - await page.getByPlaceholder('采购申请(主子)').fill('采购申请主子'); + await expect(page.getByPlaceholder('如:客户等级维护')).toBeVisible({ timeout: 20_000 }); + await page.getByPlaceholder('如:客户等级维护').fill('采购申请主子'); await page.getByRole('button', { name: '保存并下一步' }).click(); // 步④ 发布 @@ -111,7 +115,6 @@ test('主子表 · 浏览器全程点穿(建主+子 → 生成主子页 → return r.json?.status; }, { timeout: 25_000, message: '发布后主表 _ADD(含 DETAILS 子行)应级联成功' }).toBe(0); - // _SEARCH 应能查到主记录(确认主表写流通) const s = await api('POST', `/api/flow/${MASTER}_SEARCH`, tok, {}); expect(s.json?.status).toBe(0); // 子行经 _LOAD 回读,实证级联真落库(_SEARCH 列表不嵌充子数组,_LOAD 才填充)。 @@ -123,31 +126,19 @@ test('主子表 · 浏览器全程点穿(建主+子 → 生成主子页 → expect(names, '子行水泥/钢筋应级联落库').toEqual(['水泥', '钢筋']); }); -test('主子表派生字段+父级汇总 · 向导加派生/汇总 → 发布页 tpl+SUM预览+__derive+__rollup → _ADD 服务端派生再聚合 AMOUNT/TOTAL', async ({ page }) => { +test('主子表派生字段+父级汇总 · 统一向导加派生/汇总 → 发布页 tpl+SUM预览+__derive+__rollup → _ADD 服务端派生再聚合', async ({ page }) => { test.setTimeout(120_000); + await openWizardAsMasterDetail(page); - // 登录 - await page.goto('/login'); - await page.getByRole('textbox').first().fill('admin'); - await page.locator('input[type="password"]').fill('111111'); - await page.getByRole('button', { name: '登录' }).click(); - await page.waitForURL((u) => !u.pathname.endsWith('/login'), { timeout: 15_000 }); - - await page.goto('/design-center'); - await page.getByTestId('dc-new-feature-md').click(); - await expect(page.getByTestId('master-detail-shell')).toBeVisible(); - - // 步① 建主实体 - await expect(page.getByPlaceholder('OA_PURCHASE')).toBeVisible({ timeout: 15_000 }); - await page.getByPlaceholder('OA_PURCHASE').fill(MASTER2); - await page.getByPlaceholder('采购申请').fill('派生采购'); + // 步① 建主实体(含 TOTAL 汇总目标列) + await page.getByPlaceholder('OA_DEMO').fill(MASTER2); + await page.getByPlaceholder('演示(可选)').fill('派生采购'); await page.locator('.cxd-Select').first().click(); await page.locator('.cxd-Select-option').first().click(); await page.getByRole('button', { name: '加字段' }).click(); await expect(page.getByPlaceholder('TITLE').first()).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('TITLE').first().fill('TITLE'); await page.getByPlaceholder('标题').first().fill('标题'); - // 主表第 2 列 TOTAL(父级汇总目标列) await page.getByRole('button', { name: '加字段' }).click(); await expect(page.getByPlaceholder('TITLE').nth(1)).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('TITLE').nth(1).fill('TOTAL'); @@ -160,20 +151,19 @@ test('主子表派生字段+父级汇总 · 向导加派生/汇总 → 发布页 await page.getByPlaceholder('采购明细').fill('派生明细'); const childCols = ['ITEMNAME', 'ITEMQTY', 'ITEMPRICE', 'AMOUNT']; for (let i = 0; i < childCols.length; i++) { - await page.getByRole('button', { name: '加字段' }).click(); + await page.getByRole('button', { name: '加子表字段' }).click(); await expect(page.getByPlaceholder('TITLE').nth(i)).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('TITLE').nth(i).fill(childCols[i]); } await page.getByRole('button', { name: '保存并下一步' }).click(); - // 步③ 生成主子页 + 派生字段 AMOUNT=ITEMQTY*ITEMPRICE - await expect(page.getByPlaceholder('采购申请(主子)')).toBeVisible({ timeout: 20_000 }); - await page.getByPlaceholder('采购申请(主子)').fill('派生采购主子'); + // 步③ 生成主子页 + 派生字段 AMOUNT=ITEMQTY*ITEMPRICE + 汇总 TOTAL=SUM(AMOUNT) + await expect(page.getByPlaceholder('如:客户等级维护')).toBeVisible({ timeout: 20_000 }); + await page.getByPlaceholder('如:客户等级维护').fill('派生采购主子'); await page.getByRole('button', { name: '加派生字段' }).click(); await expect(page.getByPlaceholder('MONEY')).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('MONEY').fill('AMOUNT'); await page.getByPlaceholder('QTY*PRICE').fill('ITEMQTY*ITEMPRICE'); - // 汇总字段 TOTAL = SUM(AMOUNT)(agg 默认 SUM) await page.getByRole('button', { name: '加汇总字段' }).click(); await expect(page.getByPlaceholder('TOTAL')).toBeVisible({ timeout: 10_000 }); await page.getByPlaceholder('TOTAL').fill('TOTAL'); @@ -191,15 +181,13 @@ test('主子表派生字段+父级汇总 · 向导加派生/汇总 → 发布页 const tok = await adminToken(); - // ★ 断言1:UI 走出的编译产物 = 子表 AMOUNT 列只读 tpl 实时预览 + 表单 api 透传 __derive + // ★ 断言1:子表 AMOUNT 列只读 tpl 实时预览 + 表单 api 透传 __derive const schema = (await api('GET', `/api/page/schema/${tid}`, tok)).json; expect(JSON.stringify(schema), '表单 api 应透传 __derive').toContain('__derive'); - // 按列查 AMOUNT(不依赖键序):应为只读 tpl 实时预览 ${ITEMQTY*ITEMPRICE},无 quickEdit。 const amountCol = findInputTableColumn(schema, 'AMOUNT'); expect(amountCol, 'AMOUNT 列应存在于 input-table').toBeTruthy(); expect(amountCol.type).toBe('tpl'); expect(amountCol.tpl).toBe('${ITEMQTY*ITEMPRICE}'); - // 必须显式 quickEdit:false——否则 amis needConfirm:false 会强注可编辑框覆盖 tpl 只读预览。 expect(amountCol.quickEdit, '派生列 quickEdit 必须显式 false 才保留只读 tpl 预览').toBe(false); // ★ 断言1b:主表 TOTAL 汇总列只读 static + SUM 实时预览 + 表单 api 透传 __rollup @@ -223,12 +211,10 @@ test('主子表派生字段+父级汇总 · 向导加派生/汇总 → 发布页 const rows: any[] = s.json?.data?.items ?? []; const rowA = rows.find((r) => r.TITLE === '派生单A'); expect(rowA, '应查到派生单A').toBeTruthy(); - // 子行经 _LOAD(单记录)回读:_SEARCH 列表不嵌充 LIST 子数组,_LOAD 才填充(与运行时编辑弹窗一致)。 const pk = `${MASTER2}_ID`; const loaded = await api('POST', `/api/flow/${MASTER2}_LOAD`, tok, { [pk]: String(rowA[pk]).trim() }); const details: any[] = loaded.json?.data?.result?.DETAILS ?? []; const amts = details.map((d) => Number(d.AMOUNT)).sort((a, b) => a - b); expect(amts, '服务端派生 AMOUNT=数量×单价(3×10=30,2×12.5=25)').toEqual([25, 30]); - // 父级汇总:主表 TOTAL = SUM(明细金额) = 55(服务端先逐行派生再聚合,主体未提交 TOTAL)。 expect(Number(loaded.json?.data?.result?.TOTAL), '服务端聚合 TOTAL=55').toBe(55); }); diff --git a/src/App.tsx b/src/App.tsx index 496e934..4c4e1dc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,6 @@ import { TodoPage } from './pages/TodoPage'; import { WorkbenchPage } from './pages/WorkbenchPage'; import { DesignCenterPage } from './pages/DesignCenterPage'; import { NewFeatureShell } from './pages/NewFeatureShell'; -import { MasterDetailShell } from './pages/MasterDetailShell'; import { AiFeatureForm } from './pages/AiFeatureForm'; import { ModelerPage } from './pages/ModelerPage'; @@ -44,9 +43,8 @@ export default function App() { } /> {/* 设计中心(管理员集中式低代码设计入口,替代每页设计按钮)*/} } /> - {/* 人走五环编排壳 + AI ①面入口(admin-gated,页内早返回守护)*/} + {/* 人走五环统一编排壳(向导内选页面类型:单表/树/主子表)+ AI ①面入口(admin-gated)*/} } /> - } /> } /> {/* 建模器(五环第①环·元数据→表,仅管理员)*/} } /> diff --git a/src/pages/DesignCenterPage.tsx b/src/pages/DesignCenterPage.tsx index b58f627..9385043 100644 --- a/src/pages/DesignCenterPage.tsx +++ b/src/pages/DesignCenterPage.tsx @@ -77,18 +77,10 @@ export function DesignCenterPage() { className="btn btn-sm" data-testid="dc-new-feature" onClick={() => navigate('/new-feature')} - title="人走五环,从零搭建一个新功能" + title="人走五环,从零搭建一个新功能(单表维护 / 树形 / 主子表,向导内选页面类型)" > + 新建功能 - -

新建主子表功能 · 主表 + 子表 EditGrid

- -
- -
- - ); -} diff --git a/src/pages/NewFeatureShell.tsx b/src/pages/NewFeatureShell.tsx index a62b54f..980d230 100644 --- a/src/pages/NewFeatureShell.tsx +++ b/src/pages/NewFeatureShell.tsx @@ -1,10 +1,11 @@ -// 人走五环 · 编排壳 —— 用 amis wizard 渲染(与全站业务页同一套 amis 渲染层,告别手搓原生表单)。 -// 三步全在 amis 内:① 建实体(post /api/meta/entity) → ② 生成页(post /api/design/recipe/compile) -// → ③ 发布(post /api/design/publish)。amis wizard 把每步 api 的响应数据并入数据域, -// 故 entityId(步①返)、templateId(步②返) 在后续步骤经 ${} 直接可用,无需 React 中转。 -// 红线:发布恒人审;standard 写入恒走后端 PageSchemaWriter(前端只调 /api/design/recipe/compile)。 -// §B.9-4:步① 的「字段」用 combo 多行,含引用列(type=引用 → 选 referenceTable,源 /api/meta/entities)。 -import { useMemo } from 'react'; +// 人走五环 · 统一「新建功能」入口。先选页面类型(维护型CRUD / 树形 / 主子表),再进对应向导。 +// 关键:页面类型在进向导前由 React 状态确定,向导步骤按类型在【构建时(JS)】分支(主子表才有「建子表」步 +// 及派生/汇总字段)——不依赖 amis 运行时 step hiddenOn(amis Wizard.normalizeSteps 只在 props.data 变时 +// 重算,向导内选择改的是 store.data 不触发重算,故 step 级动态跳步不可靠;构建时分支才健壮)。 +// 各类型向导:① 建实体(post /api/meta/entity) →【主子表】② 建子表 → ③ 生成页面(post /api/design/recipe/compile) +// → ④ 发布(post /api/design/publish)。主实体 id/表名经 responseData remap 到 masterEntityId/masterTable。 +// 红线:发布恒人审;standard 写入恒走后端 PageSchemaWriter(前端只调 /api/design/recipe/compile)。 +import { useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { getProfile } from '../auth/token'; import { AmisRenderer } from '../components/AmisRenderer'; @@ -19,123 +20,206 @@ const TYPE_OPTIONS = [ { label: '引用(外键)', value: 'reference' }, ]; -const RECIPE_OPTIONS = [ - { label: '维护型 CRUD(列表 + 增删改)', value: 'maintenance-crud-v1' }, - { label: '树形 CRUD(自引用层级)', value: 'tree-crud-v1' }, +const RECIPE_CARDS = [ + { recipe: 'maintenance-crud-v1', testid: 'dc-recipe-maintenance', title: '维护型 CRUD', + desc: '单表:列表 + 查询 + 增删改。最常见的基础数据/业务维护页。' }, + { recipe: 'tree-crud-v1', testid: 'dc-recipe-tree', title: '树形 CRUD', + desc: '自引用层级(需含 PARENTID 列)。组织/分类/菜单等树状数据。' }, + { recipe: 'master-detail-v1', testid: 'dc-recipe-master-detail', title: '主子表', + desc: '主表 + 子表 EditGrid,子行随主记录级联保存。支持派生字段(金额=数量×单价)与父级汇总(总额=之和)。' }, ]; -/** 人走五环建新功能向导 amis schema。 */ -function buildWizardSchema(): Record { +/** 字段 combo(含引用列:type=引用 → 选 referenceTable,源 /api/meta/entities)。 */ +function attrCombo(name: string, addButtonText: string): Record { + return { + type: 'combo', name, label: '字段', multiple: true, addable: true, removable: true, + addButtonText, minLength: 1, + items: [ + { + type: 'input-text', name: 'column', label: '列名', required: true, placeholder: 'TITLE', + columnClassName: 'w-sm', validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' }, + validationErrors: { matchRegexp: '大写字母开头' }, + }, + { type: 'input-text', name: 'display', label: '显示名', placeholder: '标题' }, + { type: 'select', name: 'type', label: '类型', value: 'string', options: TYPE_OPTIONS, columnClassName: 'w-xs' }, + { + type: 'select', name: 'referenceTable', label: '引用目标实体', + source: 'get:/api/meta/entities', labelField: 'tablename', valueField: 'tablename', + searchable: true, visibleOn: '${type === "reference"}', + description: '渲染时显该实体的显示列而非裸 id', + }, + { type: 'switch', name: 'mandatory', label: '必填', value: false }, + ], + }; +} + +/** 按页面类型构建向导 amis schema(类型已由 React 状态固定,步骤构建时 JS 分支)。 */ +function buildWizardSchema(recipe: string): Record { + const isMD = recipe === 'master-detail-v1'; + const isTree = recipe === 'tree-crud-v1'; + + const steps: Record[] = []; + + // ① 建实体(主子表则为主实体) + steps.push({ + title: '① 建实体', + subTitle: isMD ? '主表元数据' : '元数据 + 物理表', + hint: isTree + ? '树形请在字段里加 PARENTID 列(自引用父节点);标准列后端自动补。' + : '标准列(主键/审计/版本)后端自动补齐,无需在此添加。', + api: { method: 'post', url: '/api/meta/entity', responseData: { masterEntityId: '${entityId}', masterTable: '${tablename}' } }, + body: [ + { + type: 'input-text', name: 'tablename', label: isMD ? '主表名' : '表名', required: true, placeholder: 'OA_DEMO', + description: '大写字母开头,仅大写字母/数字/下划线,3–41 位', + validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{2,40}$/' }, + validationErrors: { matchRegexp: '表名格式不合法(大写字母开头,3–41 位)' }, + }, + { type: 'input-text', name: 'name', label: '显示名', placeholder: '演示(可选)' }, + { + type: 'select', name: 'entitytype', label: '所属分类', required: true, + source: 'get:/api/meta/entity-types', labelField: 'name', valueField: 'id', + searchable: true, clearable: true, + description: isMD ? '主表与子表共用此分类' : '实体归类(SYS_ENTITYTYPE),决定新功能挂在哪个功能域', + }, + attrCombo('attributes', '加字段'), + ], + }); + + // ② 建子表(仅主子表) + if (isMD) { + steps.push({ + title: '② 建子表', + subTitle: '明细', + hint: '子表自动加一列 MASTERID 指向主表(回链外键),无需手动添加。', + api: { + method: 'post', url: '/api/meta/entity', + data: { + tablename: '${childTablename}', name: '${childName}', entitytype: '${entitytype}', + tabletype: 1, masterTable: '${masterTable}', attributes: '${childAttributes}', + }, + }, + body: [ + { type: 'static', name: 'masterTable', label: '主表' }, + { + type: 'input-text', name: 'childTablename', label: '子表名', required: true, placeholder: 'OA_PURCHASE_ITEM', + validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{2,40}$/' }, validationErrors: { matchRegexp: '表名格式不合法' }, + }, + { type: 'input-text', name: 'childName', label: '子表显示名', placeholder: '采购明细' }, + attrCombo('childAttributes', '加子表字段'), + ], + }); + } + + // ③ 生成页面(主子表多派生/汇总字段) + const genBody: Record[] = [ + { type: 'static', name: 'masterTable', label: isMD ? '主表' : '实体表' }, + ]; + if (isMD) { + genBody.push({ type: 'static', label: '子表', tpl: '${childTablename}' }); + } + genBody.push( + { type: 'input-text', name: 'title', label: '页面标题', required: true, placeholder: '如:客户等级维护' }, + { type: 'input-text', name: 'displayField', label: '显示字段', placeholder: '可选,默认取实体显示列' }, + ); + if (!isMD) { + genBody.push({ type: 'input-number', name: 'pageSize', label: '每页条数', placeholder: '可选,默认 20', min: 1, max: 200 }); + } + if (isMD) { + genBody.push( + { + type: 'static', label: '可用子表列', tpl: '${childAttributes|pick:column|join:"、"}', + visibleOn: '${childAttributes && childAttributes.length}', + }, + { + type: 'combo', name: 'childDerived', label: '派生字段', multiple: true, + addable: true, removable: true, addButtonText: '加派生字段', minLength: 0, + description: '可选。如 金额=数量×单价:目标列填 MONEY、公式填 QTY*PRICE。' + + '公式仅用子表列名与 + - * / ( ),落库前服务端逐行权威求算,单元格实时预览。', + items: [ + { type: 'input-text', name: 'column', label: '目标列', required: true, placeholder: 'MONEY', + validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' }, + validationErrors: { matchRegexp: '须为大写字母开头的子表真实列' } }, + { type: 'input-text', name: 'formula', label: '公式', required: true, placeholder: 'QTY*PRICE' }, + ], + }, + { + type: 'combo', name: 'childRollup', label: '汇总字段', multiple: true, + addable: true, removable: true, addButtonText: '加汇总字段', minLength: 0, + description: '可选。如 申请总额=明细金额之和:主表列填 TOTAL、子表列填 AMOUNT、函数选 SUM。' + + '主表列须为主实体真实列、子表列须为子表真实列;落库前服务端权威聚合,主表单只读实时预览。', + items: [ + { type: 'input-text', name: 'masterColumn', label: '主表列', required: true, placeholder: 'TOTAL', + validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' }, + validationErrors: { matchRegexp: '须为大写字母开头的主表真实列' } }, + { type: 'input-text', name: 'childColumn', label: '子表列', required: true, placeholder: 'AMOUNT', + validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' }, + validationErrors: { matchRegexp: '须为大写字母开头的子表真实列' } }, + { type: 'select', name: 'agg', label: '函数', value: 'SUM', options: [ + { label: '求和 SUM', value: 'SUM' }, { label: '计数 COUNT', value: 'COUNT' }, + { label: '平均 AVG', value: 'AVG' }, { label: '最小 MIN', value: 'MIN' }, + { label: '最大 MAX', value: 'MAX' }] }, + ], + }, + ); + } + const compileData: Record = { + tableName: '${masterTable}', recipe, title: '${title}', displayField: '${displayField}', + }; + if (isMD) { + Object.assign(compileData, { + childTable: '${childTablename}', linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}', + childDerived: '${childDerived}', childRollup: '${childRollup}', + }); + } else { + compileData.pageSize = '${pageSize}'; + } + steps.push({ + title: isMD ? '③ 生成主子页' : '③ 生成页面', + subTitle: '编译落标准层', + api: { method: 'post', url: '/api/design/recipe/compile', data: compileData, responseData: { templateId: '${templateId}' } }, + body: genBody, + }); + + // ④ 发布 + steps.push({ + title: '④ 发布', + subTitle: '五流 + 菜单 + 部署包', + api: { + method: 'post', url: '/api/design/publish', + data: { + entityId: '${masterEntityId}', tableName: '${masterTable}', templateId: '${templateId}', + menuName: '${menuName}', generateDeploymentPackage: true, + }, + }, + body: [ + { type: 'static', name: 'templateId', label: '已生成模板' }, + { type: 'input-text', name: 'menuName', label: '菜单名', required: true, value: '${title}' }, + { + type: 'button', label: '进设计器微调', level: 'enhance', className: 'mb-2', + actionType: 'url', url: '/editor.html?templateId=${templateId}', blank: true, visibleOn: '${templateId}', + }, + { + type: 'alert', level: 'info', + body: '发布 = 写标准页 + 触发默认服务流 + 注册菜单(当前环境立即可用),并生成生产部署包供人审上线(发布恒人审)。' + + (isMD ? '主子表的子行经主表 _ADD 流随主记录级联落库。' : ''), + }, + ], + }); + return { type: 'page', className: 'h-full', + data: { childDerived: [], childRollup: [] }, body: { type: 'wizard', mode: 'horizontal', actionPrevLabel: '上一步', actionNextLabel: '下一步', actionNextSaveLabel: '保存并下一步', - actionFinishLabel: '完成', + actionFinishLabel: '完成(发布)', renderStepIndicator: true, - steps: [ - { - title: '① 建实体', - subTitle: '元数据 + 物理表', - hint: '标准列(主键/审计/版本)由后端自动补齐,无需在此添加。', - api: { method: 'post', url: '/api/meta/entity' }, - body: [ - { - type: 'input-text', - name: 'tablename', - label: '表名', - required: true, - placeholder: 'OA_DEMO', - description: '大写字母开头,仅大写字母/数字/下划线,3–41 位', - validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{2,40}$/' }, - validationErrors: { matchRegexp: '表名格式不合法(大写字母开头,3–41 位)' }, - }, - { type: 'input-text', name: 'name', label: '显示名', placeholder: '演示维护(可选)' }, - { - type: 'select', name: 'entitytype', label: '所属分类', required: true, - source: 'get:/api/meta/entity-types', labelField: 'name', valueField: 'id', - searchable: true, clearable: true, - description: '实体在系统中的归类(SYS_ENTITYTYPE),决定新功能挂在哪个功能域', - }, - { - type: 'combo', - name: 'attributes', - label: '字段', - multiple: true, - addable: true, - removable: true, - addButtonText: '加字段', - minLength: 1, - items: [ - { - type: 'input-text', name: 'column', label: '列名', required: true, - placeholder: 'TITLE', columnClassName: 'w-sm', - validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{0,40}$/' }, - validationErrors: { matchRegexp: '大写字母开头' }, - }, - { type: 'input-text', name: 'display', label: '显示名', placeholder: '标题' }, - { type: 'select', name: 'type', label: '类型', value: 'string', options: TYPE_OPTIONS, columnClassName: 'w-xs' }, - { - type: 'select', name: 'referenceTable', label: '引用目标实体', - source: 'get:/api/meta/entities', labelField: 'tablename', valueField: 'tablename', - searchable: true, visibleOn: '${type === "reference"}', - description: '渲染时显该实体的显示列而非裸 id', - }, - { type: 'switch', name: 'mandatory', label: '必填', value: false }, - ], - }, - ], - }, - { - title: '② 生成页面', - subTitle: '选 recipe → 落标准层', - api: { - method: 'post', url: '/api/design/recipe/compile', - data: { - tableName: '${tablename}', recipe: '${recipe}', title: '${title}', - displayField: '${displayField}', pageSize: '${pageSize}', - }, - }, - body: [ - { type: 'static', name: 'tablename', label: '实体表' }, - { - type: 'radios', name: 'recipe', label: '页面模板 recipe', - value: 'maintenance-crud-v1', options: RECIPE_OPTIONS, - }, - { type: 'input-text', name: 'title', label: '页面标题', required: true, placeholder: '如:客户等级维护' }, - { type: 'input-text', name: 'displayField', label: '显示字段', placeholder: '可选,默认取实体显示列' }, - { type: 'input-number', name: 'pageSize', label: '每页条数', placeholder: '可选,默认 20', min: 1, max: 200 }, - ], - }, - { - title: '③ 发布', - subTitle: '五流 + 菜单 + 部署包', - api: { - method: 'post', url: '/api/design/publish', - data: { - entityId: '${entityId}', tableName: '${tablename}', templateId: '${templateId}', - menuName: '${menuName}', generateDeploymentPackage: true, - }, - }, - body: [ - { type: 'static', name: 'templateId', label: '已生成模板' }, - { type: 'input-text', name: 'menuName', label: '菜单名', required: true, value: '${title}' }, - { - type: 'button', label: '进设计器微调', level: 'enhance', className: 'mb-2', - actionType: 'url', url: '/editor.html?templateId=${templateId}', blank: true, - visibleOn: '${templateId}', - }, - { - type: 'alert', level: 'info', - body: '发布 = 写标准页 + 触发 5 条默认服务流 + 注册菜单(当前环境立即可用),并生成生产部署包供人审上线(发布恒人审)。', - }, - ], - }, - ], + steps, onEvent: { finished: { actions: [{ actionType: 'toast', args: { msgType: 'success', msg: '已发布:菜单已注册,可在左侧菜单查看新功能。' } }], @@ -145,11 +229,35 @@ function buildWizardSchema(): Record { }; } +/** 页面类型选择卡。 */ +function RecipeChooser({ onPick }: { onPick: (recipe: string) => void }) { + return ( +
+ {RECIPE_CARDS.map((c) => ( + + ))} +
+ ); +} + export function NewFeatureShell() { const navigate = useNavigate(); const profile = getProfile(); const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN'; - const schema = useMemo(buildWizardSchema, []); + const [recipe, setRecipe] = useState(null); + const schema = useMemo(() => (recipe ? buildWizardSchema(recipe) : null), [recipe]); if (!isAdmin) { return
新建功能仅管理员可用。
; @@ -158,11 +266,20 @@ export function NewFeatureShell() { return (
- +

新建功能 · 人走五环

- + {schema ? ( + + ) : ( + <> +
先选页面类型,再走「建实体 → 生成页面 → 发布」。
+ + + )}
);