refactor(设计中心): 合并「新建功能/新建主子表」为单一入口 + 页面类型选择
设计中心两个「新建」按钮(新建功能 / 新建主子表)合为一个「+ 新建功能」入口: 进去先选页面类型(维护型 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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() {
|
||||
<Route path="/page/:templateId" element={<PageRenderPage />} />
|
||||
{/* 设计中心(管理员集中式低代码设计入口,替代每页设计按钮)*/}
|
||||
<Route path="/design-center" element={<DesignCenterPage />} />
|
||||
{/* 人走五环编排壳 + AI ①面入口(admin-gated,页内早返回守护)*/}
|
||||
{/* 人走五环统一编排壳(向导内选页面类型:单表/树/主子表)+ AI ①面入口(admin-gated)*/}
|
||||
<Route path="/new-feature" element={<NewFeatureShell />} />
|
||||
<Route path="/new-feature-md" element={<MasterDetailShell />} />
|
||||
<Route path="/ai-feature" element={<AiFeatureForm />} />
|
||||
{/* 建模器(五环第①环·元数据→表,仅管理员)*/}
|
||||
<Route path="/modeler" element={<ModelerPage />} />
|
||||
|
||||
@@ -77,18 +77,10 @@ export function DesignCenterPage() {
|
||||
className="btn btn-sm"
|
||||
data-testid="dc-new-feature"
|
||||
onClick={() => navigate('/new-feature')}
|
||||
title="人走五环,从零搭建一个新功能"
|
||||
title="人走五环,从零搭建一个新功能(单表维护 / 树形 / 主子表,向导内选页面类型)"
|
||||
>
|
||||
+ 新建功能
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
data-testid="dc-new-feature-md"
|
||||
onClick={() => navigate('/new-feature-md')}
|
||||
title="主子表:主表 + 子表 EditGrid,子行随主记录级联保存"
|
||||
>
|
||||
+ 新建主子表
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
data-testid="dc-ai-feature"
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
// 人走五环 · 主子表编排壳 —— amis wizard 渲染(master-detail-v1)。
|
||||
// 四步全在 amis 内:① 建主实体 → ② 建子表(传 masterTable,后端自动加 MASTERID 引用列回链主表)
|
||||
// → ③ 生成主子页(compile master-detail-v1,后端先 ensureLink 接线再编译,产 input-table 子表页)
|
||||
// → ④ 发布主表(五流+菜单)。子表行经主表 _ADD 流随主记录级联落库(引擎按 LIST 列自动回填外键)。
|
||||
// 关键:用 api.responseData 把主实体 id/表名 remap 到 masterEntityId/masterTable,
|
||||
// 避免被②子实体的响应(entityId/tablename)覆盖,后续 ③④ 仍能引用主表。
|
||||
import { useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getProfile } from '../auth/token';
|
||||
import { AmisRenderer } from '../components/AmisRenderer';
|
||||
|
||||
const TYPE_OPTIONS = [
|
||||
{ label: '文本', value: 'string' },
|
||||
{ label: '整数', value: 'integer' },
|
||||
{ label: '小数', value: 'number' },
|
||||
{ label: '日期', value: 'date' },
|
||||
{ label: '日期时间', value: 'datetime' },
|
||||
{ label: '布尔', value: 'boolean' },
|
||||
];
|
||||
|
||||
function attrCombo(name: string): Record<string, unknown> {
|
||||
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',
|
||||
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 },
|
||||
{ type: 'switch', name: 'mandatory', label: '必填', value: false },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function buildSchema(): Record<string, unknown> {
|
||||
return {
|
||||
type: 'page',
|
||||
// seed childDerived/childRollup=[] 使 ${...} 恒解析为数组:combo 未触碰时也不会发出未解析占位串
|
||||
// 导致 compile 反序列化 400(后端已另做 Object 容错,此处双保险)。
|
||||
data: { childDerived: [], childRollup: [] },
|
||||
body: {
|
||||
type: 'wizard',
|
||||
mode: 'horizontal',
|
||||
actionPrevLabel: '上一步',
|
||||
actionNextSaveLabel: '保存并下一步',
|
||||
actionFinishLabel: '完成(发布)',
|
||||
steps: [
|
||||
{
|
||||
title: '① 建主实体',
|
||||
subTitle: '主表',
|
||||
hint: '主表的元数据 + 物理表。标准列(主键/审计)后端自动补。',
|
||||
// 主实体的 id/表名 remap 到 master*,避免被②子实体响应覆盖。
|
||||
api: { method: 'post', url: '/api/meta/entity', responseData: { masterEntityId: '${entityId}', masterTable: '${tablename}' } },
|
||||
body: [
|
||||
{ type: 'input-text', name: 'tablename', label: '主表名', required: true, placeholder: 'OA_PURCHASE',
|
||||
description: '大写字母开头,3–41 位', validations: { matchRegexp: '/^[A-Z][A-Z0-9_]{2,40}$/' },
|
||||
validationErrors: { matchRegexp: '表名格式不合法' } },
|
||||
{ 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,
|
||||
description: '主表与子表共用此分类' },
|
||||
attrCombo('attributes'),
|
||||
],
|
||||
},
|
||||
{
|
||||
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'),
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '③ 生成主子页',
|
||||
subTitle: '编译落标准层',
|
||||
// 后端 recipe=master-detail-v1:先 ensureLink(MASTERID/DETAILS) 接线,再编译出主 CRUD + 子表 input-table。
|
||||
// childDerived:派生列(金额=数量×单价 类)→ 编译为只读 tpl 实时预览 + 写流 ?__derive= 服务端权威落库。
|
||||
api: {
|
||||
method: 'post', url: '/api/design/recipe/compile',
|
||||
data: {
|
||||
tableName: '${masterTable}', recipe: 'master-detail-v1', title: '${title}',
|
||||
displayField: '${displayField}', childTable: '${childTablename}',
|
||||
linkColumn: 'MASTERID', listColumn: 'DETAILS', listLabel: '${childName}',
|
||||
childDerived: '${childDerived}', childRollup: '${childRollup}',
|
||||
},
|
||||
responseData: { templateId: '${templateId}' },
|
||||
},
|
||||
body: [
|
||||
{ type: 'static', label: '主表 / 子表', tpl: '${masterTable} / ${childTablename}' },
|
||||
{ type: 'input-text', name: 'title', label: '页面标题', required: true, placeholder: '采购申请(主子)' },
|
||||
{ type: 'input-text', name: 'displayField', label: '主表显示字段', placeholder: '可选,默认主表显示列' },
|
||||
{ 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' }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '④ 发布',
|
||||
subTitle: '五流 + 菜单',
|
||||
api: {
|
||||
method: 'post', url: '/api/design/publish',
|
||||
data: { entityId: '${masterEntityId}', tableName: '${masterTable}', templateId: '${templateId}', menuName: '${menuName}', generateDeploymentPackage: true },
|
||||
},
|
||||
body: [
|
||||
{ type: 'static', label: '已生成模板', name: 'templateId' },
|
||||
{ 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 默认流 + 注册菜单。子表行经主表 _ADD 流随主记录级联落库(引擎按 LIST 列自动回填子表外键),发布恒人审。' },
|
||||
],
|
||||
},
|
||||
],
|
||||
onEvent: { finished: { actions: [{ actionType: 'toast', args: { msgType: 'success', msg: '主子表功能已发布,可在左侧菜单查看。' } }] } },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function MasterDetailShell() {
|
||||
const navigate = useNavigate();
|
||||
const profile = getProfile();
|
||||
const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN';
|
||||
const schema = useMemo(buildSchema, []);
|
||||
|
||||
if (!isAdmin) {
|
||||
return <div style={{ padding: 24, color: 'var(--text-3)' }}>新建主子表功能仅管理员可用。</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }} data-testid="master-detail-shell">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 'var(--pad-lg)', paddingBottom: 8 }}>
|
||||
<button className="btn btn-sm" onClick={() => navigate('/design-center')}>← 返回设计中心</button>
|
||||
<h2 style={{ margin: 0, fontSize: 18, fontWeight: 600 }}>新建主子表功能 · 主表 + 子表 EditGrid</h2>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, overflow: 'auto', padding: '0 var(--pad-lg) var(--pad-lg)' }}>
|
||||
<AmisRenderer schema={schema} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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,62 +20,24 @@ 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<string, unknown> {
|
||||
/** 字段 combo(含引用列:type=引用 → 选 referenceTable,源 /api/meta/entities)。 */
|
||||
function attrCombo(name: string, addButtonText: string): Record<string, unknown> {
|
||||
return {
|
||||
type: 'page',
|
||||
className: 'h-full',
|
||||
body: {
|
||||
type: 'wizard',
|
||||
mode: 'horizontal',
|
||||
actionPrevLabel: '上一步',
|
||||
actionNextLabel: '下一步',
|
||||
actionNextSaveLabel: '保存并下一步',
|
||||
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,
|
||||
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}$/' },
|
||||
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: '标题' },
|
||||
@@ -87,37 +50,145 @@ function buildWizardSchema(): Record<string, unknown> {
|
||||
},
|
||||
{ type: 'switch', name: 'mandatory', label: '必填', value: false },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** 按页面类型构建向导 amis schema(类型已由 React 状态固定,步骤构建时 JS 分支)。 */
|
||||
function buildWizardSchema(recipe: string): Record<string, unknown> {
|
||||
const isMD = recipe === 'master-detail-v1';
|
||||
const isTree = recipe === 'tree-crud-v1';
|
||||
|
||||
const steps: Record<string, unknown>[] = [];
|
||||
|
||||
// ① 建实体(主子表则为主实体)
|
||||
steps.push({
|
||||
title: '① 建实体',
|
||||
subTitle: isMD ? '主表元数据' : '元数据 + 物理表',
|
||||
hint: isTree
|
||||
? '树形请在字段里加 PARENTID 列(自引用父节点);标准列后端自动补。'
|
||||
: '标准列(主键/审计/版本)后端自动补齐,无需在此添加。',
|
||||
api: { method: 'post', url: '/api/meta/entity', responseData: { masterEntityId: '${entityId}', masterTable: '${tablename}' } },
|
||||
body: [
|
||||
{
|
||||
title: '② 生成页面',
|
||||
subTitle: '选 recipe → 落标准层',
|
||||
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/design/recipe/compile',
|
||||
method: 'post', url: '/api/meta/entity',
|
||||
data: {
|
||||
tableName: '${tablename}', recipe: '${recipe}', title: '${title}',
|
||||
displayField: '${displayField}', pageSize: '${pageSize}',
|
||||
tablename: '${childTablename}', name: '${childName}', entitytype: '${entitytype}',
|
||||
tabletype: 1, masterTable: '${masterTable}', attributes: '${childAttributes}',
|
||||
},
|
||||
},
|
||||
body: [
|
||||
{ type: 'static', name: 'tablename', label: '实体表' },
|
||||
{ type: 'static', name: 'masterTable', label: '主表' },
|
||||
{
|
||||
type: 'radios', name: 'recipe', label: '页面模板 recipe',
|
||||
value: 'maintenance-crud-v1', options: RECIPE_OPTIONS,
|
||||
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<string, unknown>[] = [
|
||||
{ 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: '可选,默认取实体显示列' },
|
||||
{ type: 'input-number', name: 'pageSize', label: '每页条数', placeholder: '可选,默认 20', min: 1, max: 200 },
|
||||
);
|
||||
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' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '③ 发布',
|
||||
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<string, unknown> = {
|
||||
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: '${entityId}', tableName: '${tablename}', templateId: '${templateId}',
|
||||
entityId: '${masterEntityId}', tableName: '${masterTable}', templateId: '${templateId}',
|
||||
menuName: '${menuName}', generateDeploymentPackage: true,
|
||||
},
|
||||
},
|
||||
@@ -126,16 +197,29 @@ function buildWizardSchema(): Record<string, unknown> {
|
||||
{ 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}',
|
||||
actionType: 'url', url: '/editor.html?templateId=${templateId}', blank: true, visibleOn: '${templateId}',
|
||||
},
|
||||
{
|
||||
type: 'alert', level: 'info',
|
||||
body: '发布 = 写标准页 + 触发 5 条默认服务流 + 注册菜单(当前环境立即可用),并生成生产部署包供人审上线(发布恒人审)。',
|
||||
},
|
||||
],
|
||||
body: '发布 = 写标准页 + 触发默认服务流 + 注册菜单(当前环境立即可用),并生成生产部署包供人审上线(发布恒人审)。'
|
||||
+ (isMD ? '主子表的子行经主表 _ADD 流随主记录级联落库。' : ''),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'page',
|
||||
className: 'h-full',
|
||||
data: { childDerived: [], childRollup: [] },
|
||||
body: {
|
||||
type: 'wizard',
|
||||
mode: 'horizontal',
|
||||
actionPrevLabel: '上一步',
|
||||
actionNextLabel: '下一步',
|
||||
actionNextSaveLabel: '保存并下一步',
|
||||
actionFinishLabel: '完成(发布)',
|
||||
renderStepIndicator: true,
|
||||
steps,
|
||||
onEvent: {
|
||||
finished: {
|
||||
actions: [{ actionType: 'toast', args: { msgType: 'success', msg: '已发布:菜单已注册,可在左侧菜单查看新功能。' } }],
|
||||
@@ -145,11 +229,35 @@ function buildWizardSchema(): Record<string, unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
/** 页面类型选择卡。 */
|
||||
function RecipeChooser({ onPick }: { onPick: (recipe: string) => void }) {
|
||||
return (
|
||||
<div data-testid="recipe-chooser" style={{ display: 'flex', gap: 16, flexWrap: 'wrap', maxWidth: 980 }}>
|
||||
{RECIPE_CARDS.map((c) => (
|
||||
<button
|
||||
key={c.recipe}
|
||||
data-testid={c.testid}
|
||||
onClick={() => onPick(c.recipe)}
|
||||
style={{
|
||||
flex: '1 1 280px', minWidth: 260, textAlign: 'left', cursor: 'pointer',
|
||||
background: 'var(--surface)', border: '1px solid var(--line)', borderRadius: 10,
|
||||
padding: '18px 20px', display: 'flex', flexDirection: 'column', gap: 8,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 16, fontWeight: 600, color: 'var(--text)' }}>{c.title}</span>
|
||||
<span style={{ fontSize: 13, color: 'var(--text-3)', lineHeight: 1.6 }}>{c.desc}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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<string | null>(null);
|
||||
const schema = useMemo(() => (recipe ? buildWizardSchema(recipe) : null), [recipe]);
|
||||
|
||||
if (!isAdmin) {
|
||||
return <div style={{ padding: 24, color: 'var(--text-3)' }}>新建功能仅管理员可用。</div>;
|
||||
@@ -158,11 +266,20 @@ export function NewFeatureShell() {
|
||||
return (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }} data-testid="new-feature-shell">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 'var(--pad-lg)', paddingBottom: 8 }}>
|
||||
<button className="btn btn-sm" onClick={() => navigate('/design-center')}>← 返回设计中心</button>
|
||||
<button className="btn btn-sm" onClick={() => (recipe ? setRecipe(null) : navigate('/design-center'))}>
|
||||
{recipe ? '← 重选页面类型' : '← 返回设计中心'}
|
||||
</button>
|
||||
<h2 style={{ margin: 0, fontSize: 18, fontWeight: 600 }}>新建功能 · 人走五环</h2>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, overflow: 'auto', padding: '0 var(--pad-lg) var(--pad-lg)' }}>
|
||||
{schema ? (
|
||||
<AmisRenderer schema={schema} />
|
||||
) : (
|
||||
<>
|
||||
<div className="sub-text" style={{ marginBottom: 14 }}>先选页面类型,再走「建实体 → 生成页面 → 发布」。</div>
|
||||
<RecipeChooser onPick={setRecipe} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user