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:
2026-06-20 18:54:16 +08:00
parent 4a107f3969
commit c735f24c64
6 changed files with 276 additions and 361 deletions

View File

@@ -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 />} />

View File

@@ -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"

View File

@@ -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>
);
}

View File

@@ -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<string, unknown> {
/** 字段 combo(含引用列:type=引用 → 选 referenceTable,源 /api/meta/entities)。 */
function attrCombo(name: string, addButtonText: 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',
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<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: [
{
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<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: '可选,默认取实体显示列' },
);
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<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: '${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<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)' }}>
<AmisRenderer schema={schema} />
{schema ? (
<AmisRenderer schema={schema} />
) : (
<>
<div className="sub-text" style={{ marginBottom: 14 }}>先选页面类型,再走「建实体 → 生成页面 → 发布」。</div>
<RecipeChooser onPick={setRecipe} />
</>
)}
</div>
</div>
);