feat(master-detail): 主子表向导(amis wizard)+ 设计中心入口 + e2e
新建主子表功能:设计中心「+ 新建主子表」→ MasterDetailShell amis wizard 四步 (建主实体→建子表(传masterTable自动加FK)→生成主子页(compile master-detail-v1, 后端ensureLink+编译出 input-table 子表页)→发布)。子行经主表_ADD流随主记录级联落库。 用 api.responseData 把主实体id/表名 remap 避免被子实体响应覆盖。 Playwright e2e 全程点穿:建主+子→生成→发布→级联_ADD(status0)。1 passed。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ 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';
|
||||
|
||||
@@ -45,6 +46,7 @@ export default function App() {
|
||||
<Route path="/design-center" element={<DesignCenterPage />} />
|
||||
{/* 人走五环编排壳 + 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 />} />
|
||||
|
||||
@@ -81,6 +81,14 @@ export function DesignCenterPage() {
|
||||
>
|
||||
+ 新建功能
|
||||
</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"
|
||||
|
||||
143
src/pages/MasterDetailShell.tsx
Normal file
143
src/pages/MasterDetailShell.tsx
Normal file
@@ -0,0 +1,143 @@
|
||||
// 人走五环 · 主子表编排壳 —— 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',
|
||||
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。
|
||||
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}',
|
||||
},
|
||||
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: '可选,默认主表显示列' },
|
||||
],
|
||||
},
|
||||
{
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user