From e131b8dee9995b34cfe2d16444e0a4c61dd0e891 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Thu, 2 Jul 2026 10:34:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(modeler):=20/process-modeler=20=E9=A1=B5?= =?UTF-8?q?=E9=AA=A8=E6=9E=B6(Modeler+=E6=A0=87=E5=87=86=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF+=E5=AD=98=E9=87=8F=E8=BD=BD=E5=85=A5+?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E4=B8=AD=E5=BF=83=E5=85=A5=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 阶段1 T1.5:admin 门 + 三栏布局(左画布/右上 EIP4 侧板占位/右下标准属性面板) + bpmn-js lib/Modeler 挂载(只载 activiti moddle、只引标准 BpmnPropertiesProvider, 严禁 Camunda provider)+ ?procDefId= 时 fetchProcDefSource→importXML(idMap 存 ref) + 无参时 process-select 存量流程选择器 + 设计中心「流程设计」入口。 api: processModeler.ts(fetchProcDefSource / fetchProcessOptions,裸 JSON 防御性默认)。 - procDefId 用 encodeURIComponent 进 path(真实库 id 形如「总包合同交底:3:」中文+冒号)。 - found:false 先判后返,不解构 bpmnXml/idMap(后端此分支省略这些键)。 tsconfig.app.json 开 resolveJsonModule(首个 app 代码 import json)。 bpmn-js-properties-panel 补 ambient d.ts(包未发布类型)。 测试:ProcessModelerPage.test.tsx 5 例 + processModeler.test.ts 6 例(含中文+冒号 procDefId 断言 URL 已编码 / found:false 只返 found 键 / amis 信封解包); DesignCenterPage.entrances 加 dc-process-modeler admin-only 断言。 全量 vitest 22 文件 112 例绿;tsc -b 干净;npm run build 成功(bpmn-js 进主 bundle)。 Co-Authored-By: Claude Fable 5 --- src/App.tsx | 3 + src/api/processModeler.test.ts | 78 ++++++ src/api/processModeler.ts | 90 +++++++ src/modeler/bpmn-properties-panel.d.ts | 6 + src/pages/DesignCenterPage.entrances.test.tsx | 4 +- src/pages/DesignCenterPage.tsx | 8 + src/pages/ProcessModelerPage.test.tsx | 97 +++++++ src/pages/ProcessModelerPage.tsx | 253 ++++++++++++++++++ tsconfig.app.json | 1 + 9 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 src/api/processModeler.test.ts create mode 100644 src/api/processModeler.ts create mode 100644 src/modeler/bpmn-properties-panel.d.ts create mode 100644 src/pages/ProcessModelerPage.test.tsx create mode 100644 src/pages/ProcessModelerPage.tsx diff --git a/src/App.tsx b/src/App.tsx index 4c4e1dc..e4272b7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,6 +11,7 @@ import { DesignCenterPage } from './pages/DesignCenterPage'; import { NewFeatureShell } from './pages/NewFeatureShell'; import { AiFeatureForm } from './pages/AiFeatureForm'; import { ModelerPage } from './pages/ModelerPage'; +import { ProcessModelerPage } from './pages/ProcessModelerPage'; // 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate) function UnauthorizedBridge() { @@ -48,6 +49,8 @@ export default function App() { } /> {/* 建模器(五环第①环·元数据→表,仅管理员)*/} } /> + {/* 在线流程 Modeler(可编辑 BPMN 设计器,仅管理员)*/} + } /> {/* 根路径默认跳工作台 */} } /> diff --git a/src/api/processModeler.test.ts b/src/api/processModeler.test.ts new file mode 100644 index 0000000..8bfcabb --- /dev/null +++ b/src/api/processModeler.test.ts @@ -0,0 +1,78 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; + +vi.mock('./http', () => ({ http: { get: vi.fn() } })); + +import { http } from './http'; +import { fetchProcDefSource, fetchProcessOptions } from './processModeler'; + +const mGet = vi.mocked(http.get); + +beforeEach(() => { + mGet.mockReset(); +}); + +describe('fetchProcDefSource', () => { + it('中文+冒号 procDefId 必须 encodeURIComponent 进 path', async () => { + mGet.mockResolvedValue({ + data: { found: true, bpmnXml: '', idMap: {}, procDefKey: '总包合同交底', version: 3 }, + }); + // 真实库形态:中文流程名 + 冒号 + uuid + await fetchProcDefSource('总包合同交底:3:9b2f-uuid'); + expect(mGet).toHaveBeenCalledTimes(1); + const url = mGet.mock.calls[0][0] as string; + expect(url).toBe( + '/api/workflow/process-definitions/' + encodeURIComponent('总包合同交底:3:9b2f-uuid') + '/source', + ); + // 未编码的中文与裸冒号不得出现在 path segment 里 + expect(url).not.toContain('总包合同交底'); + expect(url).toContain('%E6%80%BB'); // 「总」的编码 + }); + + it('found:false(后端省略 bpmnXml/idMap 键)不抛,只返回 found:false', async () => { + mGet.mockResolvedValue({ data: { found: false } }); + const r = await fetchProcDefSource('PD-x'); + expect(r).toEqual({ found: false }); + expect('bpmnXml' in r).toBe(false); + }); + + it('found:true 时解构五字段', async () => { + mGet.mockResolvedValue({ + data: { found: true, bpmnXml: '', idMap: { '总包合同交底': 'Proc_zbht' }, procDefKey: '总包合同交底', version: 5 }, + }); + const r = await fetchProcDefSource('PD-1'); + expect(r).toEqual({ + found: true, + bpmnXml: '', + idMap: { '总包合同交底': 'Proc_zbht' }, + procDefKey: '总包合同交底', + version: 5, + }); + }); +}); + +describe('fetchProcessOptions', () => { + it('解 amis 信封 data.options 并映射字段', async () => { + mGet.mockResolvedValue({ + data: { + status: 0, + msg: '', + data: { options: [{ label: '总包合同交底', value: '总包合同交底', id: 'PD:3:u', key: 'zbht', type: 'process' }] }, + }, + }); + const opts = await fetchProcessOptions(); + expect(opts).toEqual([{ label: '总包合同交底', value: '总包合同交底', id: 'PD:3:u', key: 'zbht' }]); + }); + + it('history 来源 id 为空时 id=undefined(前端据此过滤不可载入项)', async () => { + mGet.mockResolvedValue({ + data: { data: { options: [{ label: '历史流程', value: '历史流程', id: null, key: null }] } }, + }); + const opts = await fetchProcessOptions(); + expect(opts[0].id).toBeUndefined(); + }); + + it('缺 options / 非数组时返回空数组不抛', async () => { + mGet.mockResolvedValue({ data: {} }); + expect(await fetchProcessOptions()).toEqual([]); + }); +}); diff --git a/src/api/processModeler.ts b/src/api/processModeler.ts new file mode 100644 index 0000000..3789658 --- /dev/null +++ b/src/api/processModeler.ts @@ -0,0 +1,90 @@ +import { http } from './http'; + +/** + * 流程 Modeler(在线 BPMN 设计器)后端契约。 + * + * 阶段 1 只用到「按 procDefId 取净化源 XML」。裸 JSON 派,防御性默认 found:false, + * 与 diagram.ts 同风格。网关端点由 T1.6 上线,本层照 design 契约先写。 + */ + +/** GET /api/workflow/process-definitions/{id}/source 的返回体。 */ +export interface ProcDefSource { + /** 是否命中流程定义(无则 found:false,不抛)。 */ + found: boolean; + /** BpmnIdSanitizer 净化后的 BPMN 2.0 XML(中文 id 已替换为 ASCII,供 moddle/Modeler 载入)。 */ + bpmnXml?: string; + /** 净化映射 原id→净化id(发布时逆向还原用,本 task 仅存 ref,后续 task 用)。 */ + idMap?: Record; + /** 流程定义 key(存量多为中文,如「总包合同交底」)。 */ + procDefKey?: string; + /** 流程定义版本号。 */ + version?: number; +} + +/** + * 按 procDefId 取净化后的存量流程源 XML(含可逆 idMap)。 + * + * ⚠️ procDefId 必须编码进 path:真实库 1445 个流程的 id 形如「总包合同交底:3:」 + * (中文 + 冒号),不 encodeURIComponent 会破坏 path segment。 + * found:false 时后端省略 bpmnXml/idMap 键——先判 found 再解构,不在 false 分支碰这些键。 + */ +export async function fetchProcDefSource(procDefId: string): Promise { + const { data } = await http.get( + `/api/workflow/process-definitions/${encodeURIComponent(procDefId)}/source`, + ); + if (!data?.found) { + return { found: false }; + } + return { + found: true, + bpmnXml: data.bpmnXml ?? undefined, + idMap: data.idMap ?? undefined, + procDefKey: data.procDefKey ?? undefined, + version: data.version ?? undefined, + }; +} + +/** + * 存量流程选择器的一条选项。复用旧 ProcessSelectDialog 的数据源 + * `/api/process-select/options`(amis 信封 {status,data:{options}})。 + * + * - {@link id} 为 procDefId(source=processDefinition/model 时有值;history 来源为空,不可载入)。 + * - {@link value}/{@link label} 均为流程名称(沿用旧口径 value==label==流程名)。 + */ +export interface ProcessOption { + label: string; + value: string; + id?: string; + key?: string; +} + +interface ProcessSelectEnvelope { + data?: { options?: unknown[] }; + options?: unknown[]; +} + +interface RawOption { + label?: unknown; + value?: unknown; + id?: unknown; + key?: unknown; +} + +/** GET /api/process-select/options —— 取存量流程选项(解 amis 信封,防御性返回数组)。 */ +export async function fetchProcessOptions(q?: string): Promise { + const { data } = await http.get('/api/process-select/options', { + params: q ? { q } : undefined, + }); + const raw = data?.data?.options ?? data?.options ?? []; + if (!Array.isArray(raw)) return []; + return raw.map((o) => { + const opt = (o ?? {}) as RawOption; + const label = opt.label != null ? String(opt.label) : opt.value != null ? String(opt.value) : ''; + return { + label, + value: opt.value != null ? String(opt.value) : label, + id: opt.id != null && String(opt.id) !== '' ? String(opt.id) : undefined, + key: opt.key != null && String(opt.key) !== '' ? String(opt.key) : undefined, + }; + }); +} diff --git a/src/modeler/bpmn-properties-panel.d.ts b/src/modeler/bpmn-properties-panel.d.ts new file mode 100644 index 0000000..ed44dd0 --- /dev/null +++ b/src/modeler/bpmn-properties-panel.d.ts @@ -0,0 +1,6 @@ +// bpmn-js-properties-panel 未随包发布类型声明(无 dist/*.d.ts、无 package.json types 字段)。 +// 只声明本项目用到的两个标准模块(severe: 严禁引 Camunda provider,见 ProcessModelerPage)。 +declare module 'bpmn-js-properties-panel' { + export const BpmnPropertiesPanelModule: unknown; + export const BpmnPropertiesProviderModule: unknown; +} diff --git a/src/pages/DesignCenterPage.entrances.test.tsx b/src/pages/DesignCenterPage.entrances.test.tsx index fa5600f..3cd4ea7 100644 --- a/src/pages/DesignCenterPage.entrances.test.tsx +++ b/src/pages/DesignCenterPage.entrances.test.tsx @@ -30,10 +30,11 @@ describe('DesignCenterPage 入口按钮', () => { profileMock.mockReset(); }); - it('admin 看到 [+ 新建功能] 与 [⚡ AI 建功能]', async () => { + it('admin 看到 [流程设计] [+ 新建功能] 与 [⚡ AI 建功能]', async () => { profileMock.mockReturnValue({ userId: 'ADMIN', account: 'admin', name: 'x', roles: [] }); renderPage(); await waitFor(() => { + expect(screen.getByTestId('dc-process-modeler')).toBeInTheDocument(); expect(screen.getByTestId('dc-new-feature')).toBeInTheDocument(); expect(screen.getByTestId('dc-ai-feature')).toBeInTheDocument(); }); @@ -42,6 +43,7 @@ describe('DesignCenterPage 入口按钮', () => { it('非 admin 不渲染入口(整页降级)', () => { profileMock.mockReturnValue({ userId: 'U1', account: 'zhangsan', name: 'z', roles: [] }); renderPage(); + expect(screen.queryByTestId('dc-process-modeler')).not.toBeInTheDocument(); expect(screen.queryByTestId('dc-new-feature')).not.toBeInTheDocument(); expect(screen.queryByTestId('dc-ai-feature')).not.toBeInTheDocument(); }); diff --git a/src/pages/DesignCenterPage.tsx b/src/pages/DesignCenterPage.tsx index 5ff9236..3db637d 100644 --- a/src/pages/DesignCenterPage.tsx +++ b/src/pages/DesignCenterPage.tsx @@ -73,6 +73,14 @@ export function DesignCenterPage() {
+ + + +
+ + {/* 主体:左画布 + 右栏(上=EIP4 侧板占位 / 下=标准属性面板) */} +
+
+
+ + {/* 未打开任何流程:叠加「打开存量流程」选择器 + 新建占位 */} + {!procDefId ? ( +
+
选择一个存量流程开始编辑
+ + {optionsError ? ( +
{optionsError}
+ ) : null} + +
+ ) : null} + + {/* 载入中 / 载入失败 */} + {procDefId && loadState === 'loading' ? ( +
+ 加载流程中… +
+ ) : null} + {procDefId && loadState === 'error' ? ( +
+ {loadError} +
+ ) : null} +
+ +
+ {/* EIP4 定制侧板占位(办理人/会签/formKey…由 T2.4 接入) */} +
+ EIP4 定制控件(办理人 / 会签 / formKey)将在此叠加,下阶段接入。 +
+ {/* 标准属性面板宿主(bpmn-js-properties-panel 渲染进此容器) */} +
+
+
+
+ ); +} + +function overlayMsgStyle(color: string): React.CSSProperties { + return { + position: 'absolute', + top: 16, + left: 16, + padding: '8px 12px', + background: 'rgba(255,255,255,0.92)', + borderRadius: 4, + color, + fontSize: 13, + }; +} diff --git a/tsconfig.app.json b/tsconfig.app.json index 24ba6ff..37fdd8e 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -8,6 +8,7 @@ "moduleResolution": "bundler", "allowImportingTsExtensions": true, + "resolveJsonModule": true, "isolatedModules": true, "moduleDetection": "force", "noEmit": true,