+
外部 AI agent 起草,产物恒人审;点「审阅草稿」进设计器,平台不自动发布。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- {run ? (
-
-
- 状态:{run.status}{' '}
- taskId={run.taskId}
-
- {reviewTemplateId ? (
-
- ) : (
-
-
未生成可审阅的页面草稿,运行信息:
-
- {(run.messages ?? ['(无消息)']).map((m, i) => (
- - {m}
- ))}
-
-
- )}
-
- ) : null}
);
}
diff --git a/src/pages/NewFeatureShell.test.tsx b/src/pages/NewFeatureShell.test.tsx
index c51aa71..2875775 100644
--- a/src/pages/NewFeatureShell.test.tsx
+++ b/src/pages/NewFeatureShell.test.tsx
@@ -1,37 +1,17 @@
import '@testing-library/jest-dom';
-import { render, screen, waitFor, fireEvent } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
-import { vi, describe, it, expect, beforeEach } from 'vitest';
+import { vi, describe, it, expect } from 'vitest';
+
+// NewFeatureShell 现以 amis wizard 渲染(
)。amis SDK(amisRequire) 是 index.html 注入的
+// 全局 UMD,jsdom 下不存在 → wizard 内部不在单测渲染;其端到端行为由 Playwright(e2e/five-ring.spec) 覆盖。
+// 单测仅守:① admin 守卫;② admin 下渲染壳容器 + 返回设计中心入口 + amis 挂载点。
+let mockProfile: { userId: string; account: string; name: string; roles: string[] } | null = null;
+vi.mock('../auth/token', () => ({ getProfile: () => mockProfile }));
+vi.mock('../components/AmisRenderer', () => ({ AmisRenderer: () => }));
+
import { NewFeatureShell } from './NewFeatureShell';
-vi.mock('../auth/token', () => ({
- getProfile: () => ({ userId: 'ADMIN', account: 'admin', name: 'x', roles: [] }),
-}));
-
-const listEntities = vi.fn();
-const createEntity = vi.fn();
-vi.mock('../api/meta', () => ({
- listEntities: (...a: unknown[]) => listEntities(...a),
- createEntity: (...a: unknown[]) => createEntity(...a),
-}));
-
-// listRecipes 在模块加载期被 NewFeatureShell 同步调用(const RECIPES = listRecipes()),
-// 故 mock 工厂直接返回静态数组(不能引用尚未初始化的外层 const,否则 hoist 期 ReferenceError)。
-const compileRecipe = vi.fn();
-vi.mock('../api/recipe', () => ({
- listRecipes: () => [
- { id: 'maintenance-crud-v1', label: '维护型 CRUD' },
- { id: 'tree-crud-v1', label: '树型 CRUD' },
- ],
- compileRecipe: (...a: unknown[]) => compileRecipe(...a),
-}));
-
-const publishFeature = vi.fn();
-vi.mock('../api/publish', () => ({ publishFeature: (...a: unknown[]) => publishFeature(...a) }));
-
-const fetchMenu = vi.fn();
-vi.mock('../api/menu', () => ({ fetchMenu: (...a: unknown[]) => fetchMenu(...a), collectLeaves: vi.fn() }));
-
function renderShell() {
return render(
@@ -40,103 +20,20 @@ function renderShell() {
);
}
-describe('NewFeatureShell happy path', () => {
- beforeEach(() => {
- listEntities.mockReset().mockResolvedValue([
- { entityId: 'E1', tablename: 'OA_DEMO', name: '演示表' },
- ]);
- createEntity.mockReset();
- compileRecipe.mockReset().mockResolvedValue({ templateId: 'TPL-NEW-1', etag: 'e1' });
- publishFeature.mockReset().mockResolvedValue({ menuId: 'M9', flows: ['OA_DEMO_ADD'] });
- fetchMenu.mockReset().mockResolvedValue({ roots: [] });
+describe('NewFeatureShell(amis wizard 壳)', () => {
+ it('非管理员:降级提示,不渲染壳', () => {
+ mockProfile = { userId: 'U1', account: 'user', name: 'u', roles: [] };
+ renderShell();
+ expect(screen.getByText(/仅管理员可用/)).toBeInTheDocument();
+ expect(screen.queryByTestId('new-feature-shell')).toBeNull();
});
- it('选实体→选 recipe→compile→进设计器按钮可用→发布', async () => {
- const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
+ it('管理员:渲染壳容器 + 返回设计中心 + amis 挂载点', () => {
+ mockProfile = { userId: 'ADMIN', account: 'admin', name: 'x', roles: [] };
renderShell();
-
- // step entity:等实体列表加载,选中第一个
- await waitFor(() => expect(screen.getByTestId('nf-entity-OA_DEMO')).toBeInTheDocument());
- fireEvent.click(screen.getByTestId('nf-entity-OA_DEMO'));
- fireEvent.click(screen.getByTestId('nf-next-entity'));
-
- // step recipe:默认选了第一个 recipe;填标题;compile
- await waitFor(() => expect(screen.getByTestId('nf-recipe-maintenance-crud-v1')).toBeInTheDocument());
- fireEvent.change(screen.getByTestId('nf-title'), { target: { value: '演示功能' } });
- fireEvent.click(screen.getByTestId('nf-compile'));
-
- await waitFor(() => expect(compileRecipe).toHaveBeenCalledWith({
- tableName: 'OA_DEMO',
- recipe: 'maintenance-crud-v1',
- title: '演示功能',
- }));
-
- // compile 成功 → 进设计器按钮出现且可用
- const designBtn = await screen.findByTestId('nf-open-designer');
- expect(designBtn).not.toBeDisabled();
- fireEvent.click(designBtn);
- expect(openSpy).toHaveBeenCalledWith('/editor.html?templateId=TPL-NEW-1', '_blank');
-
- // 发布
- fireEvent.change(screen.getByTestId('nf-menu-name'), { target: { value: '演示功能' } });
- fireEvent.click(screen.getByTestId('nf-publish'));
- await waitFor(() => expect(publishFeature).toHaveBeenCalledWith(expect.objectContaining({
- entityId: 'E1',
- tableName: 'OA_DEMO',
- templateId: 'TPL-NEW-1',
- menuName: '演示功能',
- })));
- await waitFor(() => expect(fetchMenu).toHaveBeenCalled());
-
- openSpy.mockRestore();
- });
-
- it('compile 之前进设计器按钮不存在/禁用', async () => {
- renderShell();
- await waitFor(() => expect(screen.getByTestId('nf-entity-OA_DEMO')).toBeInTheDocument());
- fireEvent.click(screen.getByTestId('nf-entity-OA_DEMO'));
- fireEvent.click(screen.getByTestId('nf-next-entity'));
- await waitFor(() => expect(screen.getByTestId('nf-recipe-maintenance-crud-v1')).toBeInTheDocument());
- // 还没 compile:进设计器按钮要么不存在要么 disabled
- const btn = screen.queryByTestId('nf-open-designer');
- expect(btn === null || (btn as HTMLButtonElement).disabled).toBe(true);
- });
-});
-
-describe('NewFeatureShell §B.9-4 新建实体可达(含引用列)', () => {
- beforeEach(() => {
- listEntities.mockReset().mockResolvedValue([
- { entityId: 'E1', tablename: 'OA_DEMO', name: '演示表' },
- ]);
- createEntity.mockReset().mockResolvedValue({
- entityId: 'E-NEW',
- tablename: 'OA_FRESH',
- attributeCount: 1,
- indexCount: 0,
- listApi: '/api/entity/OA_FRESH/list',
- });
- compileRecipe.mockReset();
- publishFeature.mockReset();
- fetchMenu.mockReset();
- });
-
- it('实体步有 [+ 新建实体] 按钮,建成后用返回的 entity 进入 recipe 步', async () => {
- renderShell();
- await waitFor(() => expect(screen.getByTestId('nf-new-entity')).toBeInTheDocument());
-
- fireEvent.click(screen.getByTestId('nf-new-entity'));
- // Dialog 打开:复用 ModelerFields/ReferencePicker(建模器表单 → field-add 证明复用)
- await waitFor(() => expect(screen.getByTestId('nf-create-tablename')).toBeInTheDocument());
- expect(screen.getByTestId('field-add')).toBeInTheDocument();
-
- fireEvent.change(screen.getByTestId('nf-create-tablename'), { target: { value: 'OA_FRESH' } });
- fireEvent.click(screen.getByTestId('nf-create-submit'));
-
- await waitFor(() => expect(createEntity).toHaveBeenCalledWith(
- expect.objectContaining({ tablename: 'OA_FRESH' }),
- ));
- // 建成回填 selectedEntity 并进入 recipe 步
- await waitFor(() => expect(screen.getByTestId('nf-recipe-maintenance-crud-v1')).toBeInTheDocument());
- expect(screen.getAllByText(/OA_FRESH/).length).toBeGreaterThan(0);
+ expect(screen.getByTestId('new-feature-shell')).toBeInTheDocument();
+ expect(screen.getByText('新建功能 · 人走五环')).toBeInTheDocument();
+ expect(screen.getByText('← 返回设计中心')).toBeInTheDocument();
+ expect(screen.getByTestId('amis-mount')).toBeInTheDocument();
});
});
diff --git a/src/pages/NewFeatureShell.tsx b/src/pages/NewFeatureShell.tsx
index a3cf7fd..f843836 100644
--- a/src/pages/NewFeatureShell.tsx
+++ b/src/pages/NewFeatureShell.tsx
@@ -1,361 +1,163 @@
-// 人走五环 · 编排壳 —— 从零搭建一个新功能页。
-// 步骤:① 选/建实体(元数据+表)→ ② 选 recipe + 填页面参数 → compileRecipe 写 standard 层拿 templateId
-// → ③ 可选「进设计器微调」(editor.html 是 edit-only,模板已存在才允许) → ④ 发布(menu+5默认流)。
-// 红线:发布恒人审;standard 写入恒走后端 PageSchemaWriter.upsertStandard(前端只调 compileRecipe)。
-// §B.9-4:实体步内置 [+ 新建实体] Dialog,复用 ModelerFields(FieldTable)/ReferencePicker,
-// 使「建含引用列的新实体」在编排流里可达;建成用返回 {entityId,tablename} 回填进入下一步。
-import { useEffect, useState } from 'react';
+// 人走五环 · 编排壳 —— 用 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';
import { useNavigate } from 'react-router-dom';
import { getProfile } from '../auth/token';
-import { listEntities, createEntity, type EntityAttr } from '../api/meta';
-import { listRecipes, compileRecipe } from '../api/recipe';
-import { publishFeature } from '../api/publish';
-import { fetchMenu } from '../api/menu';
-import { toast } from '../components/ui/Toast';
-import { Dialog } from '../components/ui/Dialog';
-import { FieldTable, buildAttribute, type FieldRow } from './ModelerFields';
-import { validateTableName } from './ModelerPage';
+import { AmisRenderer } from '../components/AmisRenderer';
-interface EntityRow {
- entityId: string;
- tablename: string;
- name: string;
+const TYPE_OPTIONS = [
+ { label: '文本', value: 'string' },
+ { label: '整数', value: 'integer' },
+ { label: '小数', value: 'number' },
+ { label: '日期', value: 'date' },
+ { label: '日期时间', value: 'datetime' },
+ { label: '布尔', value: 'boolean' },
+ { label: '引用(外键)', value: 'reference' },
+];
+
+const RECIPE_OPTIONS = [
+ { label: '维护型 CRUD(列表 + 增删改)', value: 'maintenance-crud-v1' },
+ { label: '树形 CRUD(自引用层级)', value: 'tree-crud-v1' },
+];
+
+/** 人走五环建新功能向导 amis schema。 */
+function buildWizardSchema(): Record {
+ 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: '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 条默认服务流 + 注册菜单(当前环境立即可用),并生成生产部署包供人审上线(发布恒人审)。',
+ },
+ ],
+ },
+ ],
+ onEvent: {
+ finished: {
+ actions: [{ actionType: 'toast', args: { msgType: 'success', msg: '已发布:菜单已注册,可在左侧菜单查看新功能。' } }],
+ },
+ },
+ },
+ };
}
-type Step = 'entity' | 'recipe';
-
-const RECIPES = listRecipes(); // 静态清单(maintenance-crud-v1 / tree-crud-v1)
-
export function NewFeatureShell() {
const navigate = useNavigate();
const profile = getProfile();
const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN';
-
- const [step, setStep] = useState('entity');
- const [entities, setEntities] = useState([]);
- const [loadErr, setLoadErr] = useState('');
- const [selectedEntity, setSelectedEntity] = useState(null);
-
- const [recipe, setRecipe] = useState(RECIPES[0]?.id ?? 'maintenance-crud-v1');
- const [title, setTitle] = useState('');
- const [displayField, setDisplayField] = useState('');
- const [pageSize, setPageSize] = useState('');
-
- const [templateId, setTemplateId] = useState('');
- const [compiling, setCompiling] = useState(false);
- const [menuName, setMenuName] = useState('');
- const [publishing, setPublishing] = useState(false);
-
- // §B.9-4 新建实体 Dialog 态
- const [createOpen, setCreateOpen] = useState(false);
- const [newTable, setNewTable] = useState('');
- const [newName, setNewName] = useState('');
- const [newRows, setNewRows] = useState([]);
- const [creating, setCreating] = useState(false);
- const [createErr, setCreateErr] = useState('');
-
- useEffect(() => {
- if (!isAdmin) return;
- let alive = true;
- listEntities()
- .then((rows) => alive && setEntities(rows))
- .catch((e: Error) => alive && setLoadErr(e.message ?? '实体加载失败'));
- return () => {
- alive = false;
- };
- }, [isAdmin]);
+ const schema = useMemo(buildWizardSchema, []);
if (!isAdmin) {
return 新建功能仅管理员可用。
;
}
- const newTableValid = validateTableName(newTable);
- const newRowsValid = newRows.every((r) => r.type !== '引用' || !!r.referenceTable);
- const canCreate = newTableValid && newRowsValid && !creating;
-
- function openCreate() {
- setNewTable('');
- setNewName('');
- setNewRows([]);
- setCreateErr('');
- setCreateOpen(true);
- }
-
- async function doCreateEntity() {
- setCreating(true);
- setCreateErr('');
- try {
- const attributes: EntityAttr[] = newRows.map(buildAttribute);
- const res = await createEntity({ tablename: newTable, name: newName || undefined, attributes });
- // 用返回的 {entityId,tablename} 回填,并进入 recipe 步
- const created: EntityRow = { entityId: res.entityId, tablename: res.tablename, name: newName || res.tablename };
- setCreateOpen(false);
- setSelectedEntity(created);
- setStep('recipe');
- // 刷新实体清单(后台异步,失败不阻塞)
- listEntities()
- .then((rows) => setEntities(rows))
- .catch(() => undefined);
- toast(`已新建实体 ${res.tablename}`, 'ok');
- } catch (e) {
- setCreateErr((e as Error).message ?? '建表失败');
- } finally {
- setCreating(false);
- }
- }
-
- async function doCompile() {
- if (!selectedEntity || !title.trim()) {
- toast('请先选实体并填写页面标题', 'warn');
- return;
- }
- setCompiling(true);
- try {
- const body: { tableName: string; recipe: string; title: string; displayField?: string; pageSize?: number } = {
- tableName: selectedEntity.tablename,
- recipe,
- title: title.trim(),
- };
- if (displayField.trim()) body.displayField = displayField.trim();
- if (pageSize !== '') body.pageSize = Number(pageSize);
- const res = await compileRecipe(body as Parameters[0]);
- setTemplateId(res.templateId);
- if (!menuName.trim()) setMenuName(title.trim());
- toast('已生成页面,可进设计器微调或直接发布', 'ok');
- } catch (e) {
- toast((e as Error).message ?? '生成失败', 'err');
- } finally {
- setCompiling(false);
- }
- }
-
- function openDesigner() {
- if (!templateId) return;
- window.open(`/editor.html?templateId=${encodeURIComponent(templateId)}`, '_blank');
- }
-
- async function doPublish() {
- if (!selectedEntity || !templateId || !menuName.trim()) {
- toast('发布需先生成页面并填写菜单名', 'warn');
- return;
- }
- setPublishing(true);
- try {
- const res = await publishFeature({
- entityId: selectedEntity.entityId,
- tableName: selectedEntity.tablename,
- templateId,
- menuName: menuName.trim(),
- generateDeploymentPackage: true,
- });
- await fetchMenu(); // 刷新左侧菜单缓存(新节点)
- toast(`已发布:菜单 ${res.menuId},默认流 ${res.flows.join('、')}`, 'ok');
- } catch (e) {
- toast((e as Error).message ?? '发布失败', 'err');
- } finally {
- setPublishing(false);
- }
- }
-
return (
-
-
-
+
+
+
新建功能 · 人走五环
-
- {/* 步骤指示 */}
-
- {step === 'entity' ? '步骤 1 / 2 :选择或新建实体(元数据+表)' : '步骤 2 / 2 :选 recipe、生成页面、发布'}
+
-
- {loadErr ?
实体加载失败:{loadErr}
: null}
-
- {step === 'entity' ? (
-
-
-
-
-
- | 名称 |
- 表名 |
- |
-
-
-
- {entities.map((en) => (
-
- | {en.name} |
- {en.tablename} |
-
-
- |
-
- ))}
-
-
-
-
-
-
- ) : (
-
-
- 实体:{selectedEntity?.name}{' '}
- ({selectedEntity?.tablename}){' '}
- setStep('entity')}>更换
-
-
-
-
页面模板 recipe
- {RECIPES.map((r) => (
-
- ))}
-
-
-
-
-
-
-
-
-
- {templateId ? (
-
-
- 已生成模板:{templateId}
-
-
-
-
-
-
- 发布 = 写标准页 + 触发 5 条默认流 + 注册菜单(当前后端立即可用);并生成生产部署包供人审上线。
-
-
- ) : null}
-
- )}
-
- {createOpen ? (
-
- ) : null}
);
}