diff --git a/api-report/packages/contracts/src/api/governance.d.ts b/api-report/packages/contracts/src/api/governance.d.ts index 620c9a6..eb4b777 100644 --- a/api-report/packages/contracts/src/api/governance.d.ts +++ b/api-report/packages/contracts/src/api/governance.d.ts @@ -498,16 +498,6 @@ export declare const listProcessPackagesRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -682,16 +672,6 @@ export declare const saveProcessRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -854,16 +834,6 @@ export declare const saveProcessRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -1065,16 +1035,6 @@ export declare const setProcessStateRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -1242,16 +1202,6 @@ export declare const validateProcessRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -2271,16 +2221,6 @@ export declare const govWorkflowRoute: { in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ diff --git a/api-report/packages/contracts/src/process-package.d.ts b/api-report/packages/contracts/src/process-package.d.ts index 300b0c2..cf91a7c 100644 --- a/api-report/packages/contracts/src/process-package.d.ts +++ b/api-report/packages/contracts/src/process-package.d.ts @@ -157,16 +157,6 @@ export declare const processNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ @@ -311,16 +301,6 @@ export declare const processPackageSchema: z.ZodObject<{ in: z.ZodOptional>; out: z.ZodOptional>; activityVersion: z.ZodOptional; - owner: z.ZodObject<{ - position: z.ZodString; - strategy: z.ZodDefault>; - staffId: z.ZodOptional>; - }, z.core.$strip>; failure: z.ZodDefault; }, z.core.$strip>, z.ZodObject<{ diff --git a/apps/api/src/app/__tests__/seed-mvp-flow.test.ts b/apps/api/src/app/__tests__/seed-mvp-flow.test.ts index abcfcb3..ed7d6e4 100644 --- a/apps/api/src/app/__tests__/seed-mvp-flow.test.ts +++ b/apps/api/src/app/__tests__/seed-mvp-flow.test.ts @@ -1,14 +1,14 @@ /** - * 流程包(无网关版)—— 守四件事:拓扑齐且零网关、分支即条件出边、 - * 审批点两个去向都由图表达、回边标了 reopen。 + * 流程包(纯编排版)—— 守四件事:拓扑齐、分支即条件出边、 + * 审批点两个去向都由图表达、图上每条语义边都画成真边(卡点画法已废)。 */ import { describe, expect, it } from 'vitest'; import { MVP_PACKAGE } from '../seed-mvp-flow.ts'; describe('MVP_PACKAGE', () => { - it('10 语义节点 · 14 边 · 一审批点双终点(网关在 schema 里已不存在)', () => { + it('10 语义节点 · 14 边编号 E1–E14 · 一审批点双终点', () => { expect(MVP_PACKAGE.nodes).toHaveLength(10); - expect(MVP_PACKAGE.edges).toHaveLength(14); + expect(MVP_PACKAGE.edges.map((e) => e.id)).toEqual(Array.from({ length: 14 }, (_, i) => `E${i + 1}`)); expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'approval')).toHaveLength(1); expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'end')).toHaveLength(2); }); @@ -62,35 +62,29 @@ describe('MVP_PACKAGE', () => { ]); }); - it('手绘图存证:10 语义节点 + 4 卡点(直达两枚是正向边的呈现,回跳两枚照旧)', () => { + it('手绘图存证:恰是 10 个语义节点,零卡点(卡点画法已废)', () => { const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string }[] }).nodes; - expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(4); - expect(nodes).toHaveLength(14); + expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(0); + expect(nodes).toHaveLength(10); const drawn = new Set(nodes.map((n) => n.id)); for (const n of MVP_PACKAGE.nodes) expect(drawn.has(n.id), `图上缺 ${n.id}`).toBe(true); }); /* - * 语义边必须**每条都画在图上**(直连线,或指向带 `to` 卡点的线)—— - * 画布保存由画出来的边反推语义边,没画的那条会在第一次存盘时被静默丢掉 + * 语义边必须**每条都画成真边** —— 画布保存由画出来的边反推语义边, + * 没画的那条会在第一次存盘时被静默丢掉 * (实测:A1→A3「直接寻源」漏画,mergeGraphIntoPackage 一过就没了)。 */ - it('图边对账:每条语义边都有画出来的对应(直连或经卡点)', () => { - const dia = MVP_PACKAGE.diagram as { - nodes: { id: string; kind: string; to?: string }[]; - edges: { from: string; to: string }[]; - }; - const calloutTo = new Map(dia.nodes.filter((n) => n.kind === 'callout').map((n) => [n.id, n.to])); - const drawnPairs = new Set(dia.edges.map((e) => `${e.from}→${calloutTo.get(e.to) ?? e.to}`)); - for (const e of MVP_PACKAGE.edges) { - expect(drawnPairs.has(`${e.from}→${e.to}`), `语义边 ${e.id}(${e.from}→${e.to})没画在图上`).toBe(true); - } + it('图边对账:每条语义边都画成真边,一一对应', () => { + const dia = MVP_PACKAGE.diagram as { edges: { from: string; to: string }[] }; + const drawnPairs = dia.edges.map((e) => `${e.from}→${e.to}`).sort(); + const semPairs = MVP_PACKAGE.edges.map((e) => `${e.from}→${e.to}`).sort(); + expect(drawnPairs).toEqual(semPairs); }); it('几何:坐标吸附 10px 珊格,框不重叠', () => { const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string; x: number; y: number }[] }).nodes; - const size = (kind: string) => - kind === 'callout' ? { w: 100, h: 30 } : kind === 'activity' ? { w: 100, h: 40 } : { w: 20, h: 20 }; + const size = (kind: string) => (kind === 'activity' ? { w: 100, h: 40 } : { w: 20, h: 20 }); for (const n of nodes) { expect(n.x % 10, `${n.id} x`).toBe(0); expect(n.y % 10, `${n.id} y`).toBe(0); diff --git a/apps/api/src/app/routes/desk.ts b/apps/api/src/app/routes/desk.ts index a5b1393..7d63b38 100644 --- a/apps/api/src/app/routes/desk.ts +++ b/apps/api/src/app/routes/desk.ts @@ -93,29 +93,39 @@ export function registerDeskRoutes(app: Hono, container: Container): voi return await Promise.all( nodes.map(async (n) => { - const spec = n.kind === 'approval' ? n.approver : n.owner; - /* - * 报谁,要和**真正派单时的口径一致**(ADR-011:绑定先于策略)。 - * 只按岗位报人的话,装了工作组的单会当面说谎:整条流实际都归起单人, - * 链上却写着各岗位的常驻人。所以这里也先看工作组绑定,再退回岗位解析。 + * 报谁,要和**真正派单时的口径一致**。 + * 审批点:ADR-011 绑定先于策略 —— 先看工作组绑定,再退回岗位解析。 + * 活动点:契约不带岗位(分派归运营)—— 起了单的报**实际承接人**(任务上的), + * 还没起的如实报「轮值待派」,不编造具体承接人。 */ - const bound = workflow.workGroup?.[spec.position]; - const boundStaff = - bound === undefined - ? undefined - : await container.org.getStaff(staffIdSchema.parse(bound)).catch(() => undefined); - - // 岗位唯一解析(sole)即报人名;否则只报岗位 —— 不编造具体承接人 - const holders = - boundStaff !== undefined ? [] : await container.org.staffOfPosition(spec.position).catch(() => []); - const who = boundStaff ?? (holders.length === 1 ? holders[0] : undefined); + let who; + let fallbackName = '轮值待派'; + let fallbackRole = '全员轮值'; + if (n.kind === 'approval') { + const spec = n.approver; + fallbackName = spec.position; + fallbackRole = spec.position; + const bound = workflow.workGroup?.[spec.position]; + const boundStaff = + bound === undefined + ? undefined + : await container.org.getStaff(staffIdSchema.parse(bound)).catch(() => undefined); + // 岗位唯一解析(sole)即报人名;否则只报岗位 + const holders = + boundStaff !== undefined ? [] : await container.org.staffOfPosition(spec.position).catch(() => []); + who = boundStaff ?? (holders.length === 1 ? holders[0] : undefined); + } else { + const inst = instances.find((x) => x.nodeId === n.id && x.taskId !== undefined); + const owned = inst?.taskId === undefined ? undefined : await container.task.get(taskIdSchema.parse(inst.taskId)).catch(() => undefined); + who = owned === undefined ? undefined : await container.org.getStaff(owned.ownerId).catch(() => undefined); + } return { nodeId: n.id, label: n.label, kind: n.kind === 'approval' ? ('approval' as const) : ('activity' as const), - ownerName: who?.name ?? spec.position, - ownerRole: who?.position.name ?? spec.position, + ownerName: who?.name ?? fallbackName, + ownerRole: who?.position.name ?? fallbackRole, state: n.id === task.nodeId ? ('current' as const) diff --git a/apps/api/src/app/seed-mvp-flow.ts b/apps/api/src/app/seed-mvp-flow.ts index 964c009..18da8e1 100644 --- a/apps/api/src/app/seed-mvp-flow.ts +++ b/apps/api/src/app/seed-mvp-flow.ts @@ -1,34 +1,23 @@ /** - * 「统一报价」流程包 —— **无网关**:语义取自 `docs/MVP示例工作流.html`,结构按新模型展开。 + * 「统一报价」流程包 —— **纯编排**:语义取自 `docs/MVP示例工作流.html`,结构按新模型展开。 * - * 分支 = 源节点的条件出边(恰取一条,无条件边作默认兜底);汇合 = 多入边异或。 - * FIG.1 的 G1/G2/G4 各自消失成 A1/A2/A6 的条件出边;G2J 与 G3 整颗不再需要。 - * 10 节点 14 边;审批点 A5 的两个去向就是它自己的两条条件出边(verdict 由引擎注入)。 + * 节点只分活动点与审批点(起止是结构件);分支 = 源节点的条件出边(恰取一条, + * 无条件边作默认兜底);汇合 = 多入边异或。活动契约不带负责人岗位 —— 分派归运营。 + * 10 节点 14 边(E1–E14);审批点 A5 的两个去向就是它自己的两条条件出边(verdict 由引擎注入)。 * - * 几何:两带换行、零交叉;直达与回跳都用**卡点**表达(不画长线)—— - * 卡点带 `to`,`mergeGraphIntoPackage` 只认语义边已存在的还原,编辑器保存不丢边。 + * 几何:顺序流一律画成**真边**(卡点画法已废除,2026-07-28 第三轮),零交叉: + * 直达与回跳各占一条车道,长线避框走 —— 见 diagram 里逐段注记。 */ import { processPackageSchema, triggerConfigSchema } from '@contracts'; import type { ProcessPackage } from '@contracts'; import type { Container } from './container.ts'; -/** 活动节点:岗位独任、失败即终止 —— 槽位期不谈容忍 */ -const activityNode = ( - id: string, - label: string, - activityId: string, - position: string, - col: number, - row: number, - x: number, - y: number, -) => ({ +/** 活动节点:失败即终止(槽位期不谈容忍);岗位不入契约 —— 分派归运营 */ +const activityNode = (id: string, label: string, activityId: string, col: number, row: number, x: number, y: number) => ({ id, kind: 'activity' as const, label, - sub: position, activityId, - owner: { position, strategy: 'sole' as const }, failure: { kind: 'terminate' as const }, layout: { row, col, x, y }, }); @@ -60,21 +49,16 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ output: { type: 'object', properties: { landingRate: { type: 'number' } } }, }, /* - * **无网关**(产品决策 2026-07-28):分支 = 源节点的多条条件出边(恰取一条, - * 无条件边作默认兜底),汇合 = 多入边异或(上游互斥,只会来一条)。 - * 与 Mastra 同构:条件挂在步与步之间,步保持纯粹。 - * FIG.1 的 G1/G2/G4 于是各自消失成 A1/A2/A6 的条件出边; - * G2J(当年为绕「隐式合并」禁令而生的显式汇合点)与 G3(审批结果)整颗不再需要 —— - * A4 的三条正向入边互斥即合法,A5 的裁决就是它自己的两条条件出边。 - * * 10 节点:start · A1 受理 · A2 选型 · A3 寻源 · A4 定价 · A5 审批 · A6 议价 · A7 归档 · 双终点。 + * 原 G1/G2/G4 各自消失成 A1/A2/A6 的条件出边;G2J 与 G3 整颗不再需要 —— + * A4 的三条正向入边互斥即合法,A5 的裁决就是它自己的两条条件出边。 */ nodes: [ { id: 'start', kind: 'start', label: '客户RFQ询价', layout: { row: 0, col: 0, x: 30, y: 70 } }, - activityNode('A1', '客户RFQ受理', 'rfq-intake', 'BD', 1, 0, 110, 60), - activityNode('A2', '替代选型', 'alt-selection', 'FAE', 2, 0, 290, 60), - activityNode('A3', '寻源询价', 'sourcing-inquiry', 'PRM', 3, 0, 470, 60), - activityNode('A4', '成本定价', 'cost-pricing', 'BD', 4, 1, 110, 310), + activityNode('A1', '客户RFQ受理', 'rfq-intake', 1, 0, 110, 60), + activityNode('A2', '替代选型', 'alt-selection', 2, 0, 290, 60), + activityNode('A3', '寻源询价', 'sourcing-inquiry', 3, 0, 470, 60), + activityNode('A4', '成本定价', 'cost-pricing', 4, 1, 110, 310), { id: 'A5', kind: 'approval', @@ -83,7 +67,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ approver: { position: 'PM', strategy: 'sole' }, /* * 驳回走向声明式,不由临场决定:退回 A4 重新定价。 - * 图上由 A5 自己的 `verdict = "reject"` 条件出边**显式表达同一件事**, + * 图上由 A5 自己的 `verdict = "reject"` 条件出边(E10)**显式表达同一件事**, * 引擎先看图(有边走边,没边才退回本声明),两处须字字对齐 —— 有测试守着。 * 本声明不能删:schema 必填,且它是通用机制(不是每条流都把驳回画成边)。 */ @@ -91,14 +75,14 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ nudge: { steps: [{ after: 'PT20M', action: 'nudge' }], deadline: 'PT30M' }, layout: { row: 1, col: 5, x: 290, y: 310 }, }, - activityNode('A6', '报价议价', 'quote-negotiation', 'BD', 6, 1, 470, 310), - activityNode('A7', '情报归档', 'intel-archive', 'BD', 7, 2, 630, 410), + activityNode('A6', '报价议价', 'quote-negotiation', 6, 1, 470, 310), + activityNode('A7', '情报归档', 'intel-archive', 7, 2, 630, 410), { id: 'end_won', kind: 'end', label: '转订单履约', layout: { row: 1, col: 7, x: 630, y: 320 } }, { id: 'end_arch', kind: 'end', label: '归档闭环', layout: { row: 2, col: 8, x: 790, y: 420 } }, ], edges: [ { - id: 'e-start-a1', + id: 'E1', from: 'start', to: 'A1', mapping: [ @@ -113,7 +97,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ /* A1 的三条出边 —— 原 G1「是否需要选型」+ G2「是否需要寻源」在直达路径上的合并展开 */ { - id: 'e-a1-a2', + id: 'E2', from: 'A1', to: 'A2', condition: 'needAlternative = true', @@ -126,7 +110,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ reopen: false, }, { - id: 'e-a1-a3', + id: 'E3', from: 'A1', to: 'A3', condition: 'needAlternative = false and needSourcing = true', @@ -135,11 +119,11 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ reopen: false, }, // 默认兜底:不选型不寻源 → 直接定价(条件全不中时走它,旗齐时它就是第三种情形) - { id: 'e-a1-a4', from: 'A1', to: 'A4', label: '直接定价', mapping: REENTER_A4, reopen: false }, + { id: 'E4', from: 'A1', to: 'A4', label: '直接定价', mapping: REENTER_A4, reopen: false }, /* A2 的两条出边 —— 原 G2 在选型路径上的那一问 */ { - id: 'e-a2-a3', + id: 'E5', from: 'A2', to: 'A3', condition: 'needSourcing = true', @@ -147,10 +131,10 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ mapping: [{ target: 'pn', source: { from: 'output-port', port: 'intake', path: 'pn' } }], reopen: false, }, - { id: 'e-a2-a4', from: 'A2', to: 'A4', label: '选型后定价', mapping: REENTER_A4, reopen: false }, + { id: 'E6', from: 'A2', to: 'A4', label: '选型后定价', mapping: REENTER_A4, reopen: false }, { - id: 'e-a3-a4', + id: 'E7', from: 'A3', to: 'A4', label: '供应商底价表', @@ -161,11 +145,11 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ ], reopen: false, }, - { id: 'e-a4-a5', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false }, + { id: 'E8', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false }, /* A5 审批点自己的两条条件出边 —— 裁决(verdict)由引擎在裁决时放进载荷 */ { - id: 'e-a5-a6', + id: 'E9', from: 'A5', to: 'A6', condition: 'verdict = "pass"', @@ -179,7 +163,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ reopen: false, }, { - id: 'e-a5-a4', + id: 'E10', from: 'A5', to: 'A4', condition: 'verdict = "reject"', @@ -192,7 +176,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ /* A6 的三条条件出边 —— outcome 由放行选口给出(选择组恰选一口) */ { - id: 'e-a6-won', + id: 'E11', from: 'A6', to: 'end_won', condition: 'outcome = "won"', @@ -202,7 +186,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ reopen: false, }, { - id: 'e-a6-a4', + id: 'E12', from: 'A6', to: 'A4', condition: 'outcome = "revise"', @@ -212,7 +196,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ reopen: true, }, { - id: 'e-a6-a7', + id: 'E13', from: 'A6', to: 'A7', condition: 'outcome = "lost"', @@ -227,17 +211,19 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ ], reopen: false, }, - { id: 'e-a7-end', from: 'A7', to: 'end_arch', mapping: [], label: '归档闭环', reopen: false }, + { id: 'E14', from: 'A7', to: 'end_arch', mapping: [], label: '归档闭环', reopen: false }, ], variables: [], /* - * 手绘几何存证 —— 呈现以它为真相。两带换行、零交叉: - * 顶车道 y30:A1「直接寻源」跨过 A2 直达 A3(带上方,不碰任何框) - * 带 0(y60) start → A1 → A2 → A3 受理 · 选型 · 寻源 - * 换行车道 y190:A3 右探下折横扫回左,进 A4 北口 - * 带 1(y310) A4 → A5 → A6 → end_won 定价 · 审批 · 议价 · 成交 - * 带 2(y410) A7 → end_arch 未成交闭环 - * 直达与回跳都用**卡点**表达(不画长线):A1/A2 的「直接定价」牌与 A5/A6 的回 A4 牌。 + * 手绘几何存证 —— 呈现以它为真相。顺序流全是真边,零交叉: + * 顶车道 y30:E3 直接寻源(A1 北口 → A3 北口,跨过 A2) + * 带 0(y60–100) start → A1 → A2 → A3 + * E4 直接定价:A1 南口 x130 直落 A4 北口(x130 在所有横车道的左端之外) + * 车道 y190:E6 选型后定价(A2 南口 x310 落下,西行,x160 进 A4 北口) + * 车道 y230:E7 供应商底价表(A3 东探 x610 下行,西扫,x200 进 A4 北口) + * 带 1(y310–350) A4 → A5 → A6 → end_won;E8/E10 在 A4–A5 缝隙里一上一下对开 + * 车道 y380:E12 有异议(A6 南口 x500 落下,西扫,x160 上顶 A4 南口) + * E13 拒绝/超时:A6 南口 x520 下行右拐进 A7;带 2(y410+) A7 → end_arch */ diagram: { manual: true, @@ -245,25 +231,20 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ anchors: [], nodes: [ { id: 'start', kind: 'start', label: '客户RFQ询价', x: 30, y: 70, lx: 44, ly: 104 }, - { id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', owner: 'BD', x: 110, y: 60 }, - { id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', owner: 'FAE', x: 290, y: 60 }, - { id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', owner: 'PRM', x: 470, y: 60 }, - { id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', owner: 'BD', x: 110, y: 310 }, + { id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', x: 110, y: 60 }, + { id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', x: 290, y: 60 }, + { id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', x: 470, y: 60 }, + { id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', x: 110, y: 310 }, { id: 'A5', kind: 'activity', label: '定价审批', code: 'A5', owner: 'PM', flavor: 'approval', x: 290, y: 310 }, - { id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', owner: 'BD', x: 470, y: 310 }, - { id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', owner: 'BD', x: 630, y: 410 }, + { id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', x: 470, y: 310 }, + { id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', x: 630, y: 410 }, { id: 'end_won', kind: 'end', label: '转订单履约', x: 630, y: 320, lx: 640, ly: 352 }, { id: 'end_arch', kind: 'end-bad', label: '归档闭环', x: 790, y: 420, lx: 800, ly: 452 }, - /* 四枚卡点:直达两枚(正向,语义边真实存在)、回跳两枚 —— 全在各自源节点的上下车道 */ - { id: 'c_d1', kind: 'callout', label: '直接定价', to: 'A4', x: 110, y: 170 }, - { id: 'c_d2', kind: 'callout', label: '选型后定价', to: 'A4', x: 290, y: 170 }, - { id: 'c_reject', kind: 'callout', label: '退回调整', to: 'A4', x: 290, y: 240 }, - { id: 'c_revise', kind: 'callout', label: '返回调整', to: 'A4', x: 470, y: 240 }, ], edges: [ { from: 'start', to: 'A1', points: [{ x: 50, y: 80 }, { x: 110, y: 80 }] }, { from: 'A1', to: 'A2', label: '需要选型', points: [{ x: 210, y: 80 }, { x: 290, y: 80 }] }, - // 直接寻源走顶车道 y30(A1 北口 → A3 北口):画布保存只认画出来的边,这条不画就会丢 + // E3 顶车道:跨过 A2 直达 A3 北口 { from: 'A1', to: 'A3', @@ -275,32 +256,59 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({ { x: 520, y: 60 }, ], }, + // E4 直落:x130 在 E6(x160 起)与 E7(x200 起)两条横车道左端之外,零交叉 + { from: 'A1', to: 'A4', label: '直接定价', lx: 88, ly: 200, points: [{ x: 130, y: 100 }, { x: 130, y: 310 }] }, { from: 'A2', to: 'A3', label: '仍需寻源', points: [{ x: 390, y: 80 }, { x: 470, y: 80 }] }, - // 换行那一笔:A3 右探 → 降到 190 车道 → 横扫回左 → 落 A4 北口 + // E6 车道 y190:A2 南口下行、西行、进 A4 北口 { - from: 'A3', + from: 'A2', to: 'A4', - label: '供应商底价表', - // 标注钉在 y190 车道的空档(x390–610)—— 默认取折线中点,会被「选型后定价→A4」卡点压住 - lx: 450, - ly: 183, + label: '选型后定价', + lx: 235, + ly: 182, points: [ - { x: 570, y: 80 }, - { x: 610, y: 80 }, - { x: 610, y: 190 }, + { x: 310, y: 100 }, + { x: 310, y: 190 }, { x: 160, y: 190 }, { x: 160, y: 310 }, ], }, - // 直达两枚卡点(正向):不选不寻 → 直接定价;选完不寻 → 定价 - { from: 'A1', to: 'c_d1', label: '不选不寻', points: [{ x: 160, y: 100 }, { x: 160, y: 170 }] }, - { from: 'A2', to: 'c_d2', label: '不再寻源', points: [{ x: 340, y: 100 }, { x: 340, y: 170 }] }, - { from: 'A4', to: 'A5', label: '报价草案提审', points: [{ x: 210, y: 330 }, { x: 290, y: 330 }] }, + // E7 车道 y230:A3 东探绕行(x610),在 E6 之下、A5 上行线之上零交叉扫回 + { + from: 'A3', + to: 'A4', + label: '供应商底价表', + lx: 420, + ly: 222, + points: [ + { x: 570, y: 80 }, + { x: 610, y: 80 }, + { x: 610, y: 230 }, + { x: 200, y: 230 }, + { x: 200, y: 310 }, + ], + }, + // E8/E10:A4–A5 缝隙里一上一下对开(y320 提审,y340 退回) + { from: 'A4', to: 'A5', label: '报价草案提审', lx: 250, ly: 312, points: [{ x: 210, y: 320 }, { x: 290, y: 320 }] }, { from: 'A5', to: 'A6', label: '通过', tone: 'ok', points: [{ x: 390, y: 330 }, { x: 470, y: 330 }] }, - { from: 'A5', to: 'c_reject', label: '不通过', tone: 'bad', points: [{ x: 340, y: 310 }, { x: 340, y: 270 }], lx: 310, ly: 292 }, + { from: 'A5', to: 'A4', label: '不通过', tone: 'bad', lx: 250, ly: 352, points: [{ x: 290, y: 340 }, { x: 210, y: 340 }] }, { from: 'A6', to: 'end_won', label: '成交', tone: 'ok', points: [{ x: 570, y: 330 }, { x: 630, y: 330 }] }, - { from: 'A6', to: 'c_revise', label: '有异议', tone: 'bad', points: [{ x: 520, y: 310 }, { x: 520, y: 270 }], lx: 545, ly: 292 }, - { from: 'A6', to: 'A7', label: '拒绝/超时', tone: 'bad', points: [{ x: 520, y: 350 }, { x: 520, y: 430 }, { x: 630, y: 430 }], lx: 545, ly: 388 }, + // E12 车道 y380:A6 南口西扫,上顶 A4 南口 + { + from: 'A6', + to: 'A4', + label: '有异议', + tone: 'bad', + lx: 330, + ly: 372, + points: [ + { x: 500, y: 350 }, + { x: 500, y: 380 }, + { x: 160, y: 380 }, + { x: 160, y: 350 }, + ], + }, + { from: 'A6', to: 'A7', label: '拒绝/超时', tone: 'bad', lx: 560, ly: 405, points: [{ x: 520, y: 350 }, { x: 520, y: 430 }, { x: 630, y: 430 }] }, { from: 'A7', to: 'end_arch', label: '归档闭环', points: [{ x: 730, y: 430 }, { x: 790, y: 430 }] }, ], }, diff --git a/apps/api/src/modules/process/CONTRACT.md b/apps/api/src/modules/process/CONTRACT.md index a850a5b..5983ecd 100644 --- a/apps/api/src/modules/process/CONTRACT.md +++ b/apps/api/src/modules/process/CONTRACT.md @@ -29,14 +29,22 @@ 随手画的半成品也存得进来(存出来即 `retired`,不生效);`setPackageState` 激活时 跑 `checkClosure`,不闭合抛 `NotClosedError`(HTTP 412 带整份报告)。 违规项:未完成边、必填未映射、类型冲突、孤立节点、多默认出边、 - 活动未装载、岗位不存在、容忍分支被下游必填依赖 —— 任一即 `closed = false`,激活被拒。 - - **纯编排模型**(产品决策 2026-07-28 第二轮):流程包只决定**活动编排**与 + 活动未装载、审批岗位不存在、容忍分支被下游必填依赖 —— 任一即 `closed = false`,激活被拒。 + (活动点不核岗位 —— 契约不带负责人,`missing-owner-position` 只出自审批点。) + - **纯编排模型**(产品决策 2026-07-28 二、三轮):流程包只决定**活动编排**与 **活动传递的契约**,不决定活动的实现方式(范式/版本住活动库,节点仅以 - `activityId` 链接)。节点只分**活动点**与**审批点**(起点/终点是结构件); - `kind: 'gateway'` 已从 schema 摘除(库经外科手术清空,无历史包袱)。 + `activityId` 链接),**也不带负责人岗位**(分派归运营;运营分派机制未建前, + 活动任务运行时默认全员轮值 —— 在岗候选并集、最闲者先、staffId 稳定排序。 + 审批点例外:「卡到人的工位」是它的功能语义,`approver` 留在声明里, + 工作组绑定 ADR-011 也只对它生效)。节点只分**活动点**与**审批点** + (起点/终点是结构件);`kind: 'gateway'` 已从 schema 摘除。 分支 = 源节点的多条条件出边(恰取一条,无条件边作默认兜底、至多一条), 汇合 = 多入边异或(上游互斥,只会来一条 —— `joinReady` 已删,没有「等回齐」)。 AND 并行暂无声明机制,将来以「并行组」加回(对应 Mastra `.parallel`,见 debt.md)。 + - **边有编号身份**:语义边 id 即边号(E1、E2…,服务端/合并器铸号,旧边保号、 + 新边取下一个空号);画布线标带号、边在图上可选中,条件与映射住属性面。 + 顺序流一律画成**真边**(卡点画法已废除)—— 画布保存由画出来的边反推语义边, + 图上没画的语义边会在存盘时丢失,种子与测试按「一一对应」守着。 - **激活双判据**:①图编排闭合完善(结构 + 属性 + 传递契约,`checkClosure` 的 非 unknown-activity 项)②活动装载(节点链接的实现已安装,`unknown-activity` 项)。 两面都清零才可激活;图照画照存,未装载不拦保存。 diff --git a/apps/api/src/modules/process/__tests__/closure.test.ts b/apps/api/src/modules/process/__tests__/closure.test.ts index f543678..55c7c3d 100644 --- a/apps/api/src/modules/process/__tests__/closure.test.ts +++ b/apps/api/src/modules/process/__tests__/closure.test.ts @@ -34,7 +34,6 @@ const pkg = (over: Partial = {}): ProcessPackage => kind: 'activity', label: 'A4 成本定价', activityId: 'a4' as never, - owner: { position: 'BD', strategy: 'sole' }, failure: { kind: 'terminate' }, }, { id: 'end' as never, kind: 'end', label: '终点' }, @@ -101,9 +100,31 @@ describe('checkClosure —— 不闭合不得激活', () => { expect(report.violations.map((v) => v.kind)).toContain('unknown-activity'); }); - it('岗位不存在即拦', () => { - const report = checkClosure({ pkg: pkg(), contracts, positions: new Set(['PM']) }); - expect(report.violations.map((v) => v.kind)).toContain('missing-owner-position'); + /* 活动点不核岗位(契约不带负责人);审批点的岗位是功能语义,不存在即拦 */ + it('审批点岗位不存在即拦;活动点没有岗位可核', () => { + const withApproval = pkg({ + nodes: [ + ...pkg().nodes, + { + id: 'AP' as never, + kind: 'approval', + label: '审批', + approver: { position: 'GONE', strategy: 'sole' }, + reject: { kind: 'terminate' }, + }, + ], + edges: [ + ...pkg().edges.filter((e) => e.id !== 'e2'), + { id: 'e2', from: 'A4' as never, to: 'AP' as never, mapping: [], reopen: false }, + { id: 'e3', from: 'AP' as never, to: 'end' as never, mapping: [], reopen: false }, + ], + }); + const violations = checkClosure({ pkg: withApproval, contracts, positions }).violations; + expect(violations.filter((v) => v.kind === 'missing-owner-position').map((v) => v.nodeId)).toEqual(['AP']); + + // 活动节点引用的岗位集合再小也与它无关 —— 不产生岗位类违规 + const noPositions = checkClosure({ pkg: pkg(), contracts, positions: new Set() }).violations; + expect(noPositions.filter((v) => v.kind === 'missing-owner-position')).toEqual([]); }); it('孤立节点即拦', () => { @@ -115,7 +136,6 @@ describe('checkClosure —— 不闭合不得激活', () => { kind: 'activity', label: '游离节点', activityId: 'a4' as never, - owner: { position: 'BD', strategy: 'sole' }, failure: { kind: 'terminate' }, }, ], @@ -156,7 +176,6 @@ describe('checkClosure —— 不闭合不得激活', () => { kind: 'activity', label: 'A3 渠道寻源', activityId: 'a4' as never, - owner: { position: 'PRM', strategy: 'sole' }, failure: { kind: 'tolerate' }, }, { @@ -164,7 +183,6 @@ describe('checkClosure —— 不闭合不得激活', () => { kind: 'activity', label: 'A4 成本定价', activityId: 'a4' as never, - owner: { position: 'BD', strategy: 'sole' }, failure: { kind: 'terminate' }, }, { id: 'end' as never, kind: 'end', label: '终点' }, diff --git a/apps/api/src/modules/process/internal/adapter/process-store.ts b/apps/api/src/modules/process/internal/adapter/process-store.ts index 8eef1d7..6b85b28 100644 --- a/apps/api/src/modules/process/internal/adapter/process-store.ts +++ b/apps/api/src/modules/process/internal/adapter/process-store.ts @@ -126,6 +126,8 @@ export function createProcessStore(db: Db): ProcessStore { activated: r.activated, ...(r.terminal === null ? {} : { terminal: r.terminal as TerminalState }), ...(r.failureDigested === null ? {} : { failureDigested: r.failureDigested }), + ...(r.taskId === null ? {} : { taskId: r.taskId }), + ...(r.approvalId === null ? {} : { approvalId: r.approvalId }), }), ); }, diff --git a/apps/api/src/modules/process/internal/domain/closure.ts b/apps/api/src/modules/process/internal/domain/closure.ts index d6904ac..10000ea 100644 --- a/apps/api/src/modules/process/internal/domain/closure.ts +++ b/apps/api/src/modules/process/internal/domain/closure.ts @@ -57,8 +57,9 @@ export function checkClosure(input: ClosureInput): ClosureReport { } if (node.kind === 'activity') { - violations.push(...checkActivityNode(node, incoming.get(node.id) ?? [], contracts, positions)); + violations.push(...checkActivityNode(node, incoming.get(node.id) ?? [], contracts)); } + // 活动点不核岗位(契约不带负责人 —— 分派归运营);审批点的岗位是功能语义,照核 if (node.kind === 'approval' && !positions.has(node.approver.position)) { violations.push({ kind: 'missing-owner-position', @@ -94,7 +95,6 @@ function checkActivityNode( node: Extract, inbound: readonly Edge[], contracts: ReadonlyMap, - positions: ReadonlySet, ): ClosureViolation[] { const out: ClosureViolation[] = []; const face = contracts.get(node.activityId); @@ -108,14 +108,6 @@ function checkActivityNode( return out; } - if (!positions.has(node.owner.position)) { - out.push({ - kind: 'missing-owner-position', - nodeId: node.id, - message: `节点「${node.label}」的岗位不存在:${node.owner.position}`, - }); - } - // 连一条边即须完成该边映射 for (const edge of inbound) { if (edge.mapping.length === 0) { diff --git a/apps/api/src/modules/process/internal/domain/owner-resolution.ts b/apps/api/src/modules/process/internal/domain/owner-resolution.ts index a4e0936..dafcd19 100644 --- a/apps/api/src/modules/process/internal/domain/owner-resolution.ts +++ b/apps/api/src/modules/process/internal/domain/owner-resolution.ts @@ -120,6 +120,9 @@ export type NodeInstance = { readonly failureDigested?: boolean; /** XOR 未选分支从未激活 —— 不入集合 */ readonly activated: boolean; + /** 该实例派出的任务 / 审批(结构件与终点没有)—— 链条视图按它报实际承接人 */ + readonly taskId?: string; + readonly approvalId?: string; }; export function aggregateWorkflowState( diff --git a/apps/api/src/modules/process/internal/usecase/process-service.ts b/apps/api/src/modules/process/internal/usecase/process-service.ts index 8d10637..21e3928 100644 --- a/apps/api/src/modules/process/internal/usecase/process-service.ts +++ b/apps/api/src/modules/process/internal/usecase/process-service.ts @@ -1,7 +1,7 @@ /** * process 用例 —— 流程引擎:确定性流转,**零 LLM、零临场**(编码规范 §5.3;语义出处 OS 03 / 04)。 * - * 起单 · 调度节点 · 审批点卡工位 · 网关分合 · 每次流转记入事件。 + * 起单 · 调度节点 · 审批点卡工位 · 条件出边选路 · 每次流转记入事件。 */ import type { ProcessNode, ProcessPackage, StaffId, TerminalState, WorkflowState } from '@contracts'; import type { ProcessService, StartWorkflowInput } from '../../contract.ts'; @@ -87,7 +87,7 @@ export function createProcessService(deps: ProcessServiceDeps): ProcessService { const dispatch = dispatchOf(node, payload); if (dispatch === undefined) { - // 网关本身不是责任单元:直接继续流转 + // 只剩起点会走到这(结构件无调度):被指为目标时直通,不建实例 await advanceFrom(record, pkg, node.id, payload); return; } @@ -122,15 +122,31 @@ export function createProcessService(deps: ProcessServiceDeps): ProcessService { return; } - // 负责人 / 审批人:编排声明岗位,起单时确定性解析;结果与依据留痕 - const spec = dispatch.kind === 'start-task' ? dispatch.node.owner : dispatch.node.approver; - const candidates = await deps.org.candidates(spec.position); /* - * 绑定先于策略:工作组说了这个岗位是谁,策略就无从发问(ADR-011)。 - * 在岗与否在这里核 —— 绑定是**跨岗位**指派,拿该岗位的候选集核不了它。 + * 谁来干:**活动契约不带岗位**(纯编排,2026-07-28 第三轮)—— 分派是运营的事。 + * 运营分派机制未建前,活动任务默认**全员轮值**(在岗候选并集,最闲者先, + * staffId 稳定排序保证同输入必同结果);审批点例外,「卡到人的工位」是它的 + * 功能语义,仍按 approver 岗位解析,工作组绑定(ADR-011)也只对它生效。 */ - const boundTo = record.workGroup?.[spec.position]; - const bound = boundTo !== undefined && (await deps.org.isActive(boundTo)) ? boundTo : undefined; + let spec; + let candidates; + let bound; + if (dispatch.kind === 'start-task') { + spec = { position: '(全员轮值)', strategy: 'sole' as const }; + const seen = new Map(); + for (const position of await deps.org.positions()) { + for (const c of await deps.org.candidates(position)) if (!seen.has(c.staffId)) seen.set(c.staffId, c); + } + candidates = [...seen.values()]; + bound = undefined; + } else { + spec = dispatch.node.approver; + candidates = await deps.org.candidates(spec.position); + // 绑定先于策略:工作组说了这个岗位是谁,策略就无从发问(ADR-011)。 + // 在岗与否在这里核 —— 绑定是**跨岗位**指派,拿该岗位的候选集核不了它。 + const boundTo = record.workGroup?.[spec.position]; + bound = boundTo !== undefined && (await deps.org.isActive(boundTo)) ? boundTo : undefined; + } const resolution = resolveOwner(spec, { candidates, ...(bound === undefined ? {} : { bound }) }); if (resolution.kind === 'vacant') throw new PositionVacantError(spec.position); diff --git a/apps/web/src/features/gov-process/internal/panel.tsx b/apps/web/src/features/gov-process/internal/panel.tsx index c50f1fc..bbf5b4b 100644 --- a/apps/web/src/features/gov-process/internal/panel.tsx +++ b/apps/web/src/features/gov-process/internal/panel.tsx @@ -68,14 +68,6 @@ function flowsOf(packages: readonly ProcessPackage[]) { /* ── 边属性:传递契约(条件 + 映射)──────────────────────────────────── */ -/** 卡点 id → 去向节点 id(边属性按语义对端认亲:A5→c_reject 即 A5→A4) */ -function calloutToOf(graph: FlowGraph | null): Map | undefined { - if (graph === null) return undefined; - return new Map( - graph.nodes.filter((n) => n.kind === 'callout' && n.to !== undefined).map((n) => [n.id, n.to!]), - ); -} - /** 映射行的工作形状 —— 语义边 mapping 的元素;设计者只见三种来源,其余是系统隐性上下文 */ type MapRow = { target: string; source: Record & { from: string } }; const SOURCE_KINDS = [ @@ -84,21 +76,13 @@ const SOURCE_KINDS = [ { k: 'constant', label: '常量' }, ] as const; -function EdgeProps({ - edge, - toSem, - onPatch, -}: { - edge: FlowEdge; - toSem: string; - onPatch: (f: (e: FlowEdge) => FlowEdge) => void; -}) { +function EdgeProps({ edge, onPatch }: { edge: FlowEdge; onPatch: (f: (e: FlowEdge) => FlowEdge) => void }) { const rows = (edge.mapping ?? []) as MapRow[]; const setRows = (next: MapRow[]) => onPatch((e) => ({ ...e, mapping: next })); const patchRow = (i: number, f: (r: MapRow) => MapRow) => setRows(rows.map((r, j) => (j === i ? f(r) : r))); return (
- + - n.kind === 'activity' - ? n.flavor === 'approval' - ? '审批点' - : '活动点' - : n.kind === 'callout' - ? '卡点' - : n.kind === 'start' - ? '调用接口' - : '显式终点'; - const kindTone = (n: FlowNode) => - n.kind === 'activity' ? (n.flavor === 'approval' ? 'warn' : 'auto') : n.kind === 'callout' ? 'danger' : 'mute'; + n.kind === 'activity' ? (n.flavor === 'approval' ? '审批点' : '活动点') : n.kind === 'start' ? '调用接口' : '显式终点'; + const kindTone = (n: FlowNode) => (n.kind === 'activity' ? (n.flavor === 'approval' ? 'warn' : 'auto') : 'mute'); // 画布上的选中态:diagram-js 给每个形状挂了 data-element-id,外挂一个类,不改画布件 useEffect(() => { @@ -680,7 +655,7 @@ function FlowLab({ nodeId: n.id, label: n.label, activityId: n.activityId, - owner: n.owner, + // 契约不带负责人岗位 —— 分派归运营,依赖文件只描述干什么 // 编排上手写的注记(给人读) declaredIn: n.in ?? [], declaredOut: n.out ?? [], @@ -825,7 +800,7 @@ function FlowLab({ n.kind === 'activity').map((n) => n.id)} /* @@ -835,6 +810,12 @@ function FlowLab({ */ canEdit onNodeClick={(nid) => { setSel(nid); setSelEdge(null); }} + onEdgeClick={(edge) => { + const i = (graph?.edges ?? []).findIndex( + (x) => x.from === edge.from && x.to === edge.to && x.code === edge.code, + ); + if (i >= 0) { setSelEdge(i); setSel(null); } + }} onEditNodeText={async (nid, p2) => { setGraph((g) => g === null @@ -949,22 +930,18 @@ function FlowLab({ ))}
- {/* 边拣选条:边属性 = 传递契约(条件 + 映射)—— 图只定顺序,契约在这儿填 */} + {/* 边拣选条:边号立牌(E1、E2…),条件住属性面不上按钮 —— 图只定顺序,契约在属性里填 */}
- {(graph?.edges ?? []).map((e, i) => { - const toSem = calloutToOf(graph)?.get(e.to) ?? e.to; - const brief = e.condition !== undefined && e.condition !== '' ? ` [${e.condition}]` : ''; - return ( - - ); - })} + {(graph?.edges ?? []).map((e, i) => ( + + ))}
{node === null && selEdge === null ? ( @@ -974,7 +951,6 @@ function FlowLab({ ) : node === null && selEdge !== null && graph !== null ? ( { setGraph((g) => g === null ? g : { ...g, edges: g.edges.map((e, i) => (i === selEdge ? f(e) : e)) }, @@ -1036,25 +1012,29 @@ function FlowLab({ /> )} - - - + {node.flavor === 'approval' && ( + + + + )} + {node.flavor !== 'approval' && ( + + 活动点不带岗位 —— 谁来干是运营的事(分派机制未建前,运行时全员轮值、最闲者先)。 + + )} {node.kind === 'activity' && node.flavor === 'approval' && ( 审批点是系统内置要素,不是活动 —— 声明即用、零开发、不进活动库(一个流程包里需要开发的 @@ -1062,11 +1042,8 @@ function FlowLab({ (声明式:回指定节点重开新实例 / 终止)· 催办阶梯。运行时它产出审批单而非任务。 )} - {node.owner === undefined && ( - - 这个节点还没指定岗位 —— 不指定,起单时就不知道 - {node.flavor === 'approval' ? '审批单' : '任务'}该派给谁。 - + {node.flavor === 'approval' && node.owner === undefined && ( + 这个审批点还没指定岗位 —— 不指定,起单时就不知道审批单该派给谁。 )} @@ -1088,28 +1065,6 @@ function FlowLab({ /> )} - {node.kind === 'callout' && ( - - - - - - )} {node.kind === 'activity' && node.flavor !== 'approval' && ( diff --git a/apps/web/src/shared/gov/flow/FlowDiagram.tsx b/apps/web/src/shared/gov/flow/FlowDiagram.tsx index 9ca75b0..a8832d3 100644 --- a/apps/web/src/shared/gov/flow/FlowDiagram.tsx +++ b/apps/web/src/shared/gov/flow/FlowDiagram.tsx @@ -9,6 +9,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { layoutFlow, type ConnectionLayout, + type FlowEdge, type FlowGraph, type FlowLayoutResult, type FlowNode, @@ -68,13 +69,25 @@ const rendererModule = { }; /** 连线 + 箭头 + 线上标签,画进注解图层(几何全部来自布局引擎)。 */ -function drawConnection(layer: SVGElement, connection: ConnectionLayout, variant: FlowVariant): void { +function drawConnection( + layer: SVGElement, + connection: ConnectionLayout, + variant: FlowVariant, + onEdgeClick?: (edge: FlowEdge) => void, +): void { const color = TONE_COLOR[connection.tone]; const [first, ...rest] = connection.waypoints; if (first === undefined) return; const d = `M${first.x},${first.y} ${rest.map((p) => `L${p.x},${p.y}`).join(" ")}`; - layer.append(svg("path", { d, fill: "none", stroke: color, "stroke-width": 1.4 })); - layer.append(svg("polygon", { points: arrowHeadPoints(connection.waypoints), fill: color })); + if (onEdgeClick !== undefined) { + // 加宽透明命中垫:线太细点不着 —— 边在图上可选中,属性(条件/映射)去属性卡改 + const hit = svg("path", { d, fill: "none", stroke: "transparent", "stroke-width": 12, cursor: "pointer" }); + (hit as SVGElement & { style: CSSStyleDeclaration }).style.pointerEvents = "stroke"; + hit.addEventListener("click", () => onEdgeClick(connection.edge)); + layer.append(hit); + } + layer.append(svg("path", { d, fill: "none", stroke: color, "stroke-width": 1.4, "pointer-events": "none" })); + layer.append(svg("polygon", { points: arrowHeadPoints(connection.waypoints), fill: color, "pointer-events": "none" })); if (connection.label) { layer.append( @@ -94,8 +107,13 @@ function drawConnection(layer: SVGElement, connection: ConnectionLayout, variant } } -function drawAnnotations(layer: SVGElement, layout: FlowLayoutResult, variant: FlowVariant): void { - for (const connection of layout.connections) drawConnection(layer, connection, variant); +function drawAnnotations( + layer: SVGElement, + layout: FlowLayoutResult, + variant: FlowVariant, + onEdgeClick?: (edge: FlowEdge) => void, +): void { + for (const connection of layout.connections) drawConnection(layer, connection, variant, onEdgeClick); for (const caption of layout.captions) { const style = CAPTION_STYLE[caption.role]; // 严格索引:未知 role 不画注记,而不是画一个半成品 @@ -124,6 +142,8 @@ export interface FlowDiagramProps { variant: FlowVariant; /** 点击活动节点(下钻);不传则节点不可点。 */ onNodeClick?: (nodeId: string) => void; + /** 点击连线(选中边,按边号/两端认);不传则边不可点。 */ + onEdgeClick?: ((edge: FlowEdge) => void) | undefined; /** 双击活动节点就地改文字(标题/小字/主办);不传则不可改。 */ onEditNode?: ((nodeId: string, patch: { label: string; owner?: string }) => Promise) | undefined; /** 执行人候选(L1 业务能力)——传了则执行字段只能下拉选缩写,不开自由填。 */ @@ -137,11 +157,13 @@ interface NodeEdit { top: number; } -export function FlowDiagram({ graph, variant, onNodeClick, onEditNode, ownerOptions, ariaLabel }: FlowDiagramProps) { +export function FlowDiagram({ graph, variant, onNodeClick, onEdgeClick, onEditNode, ownerOptions, ariaLabel }: FlowDiagramProps) { const containerRef = useRef(null); const editRef = useRef(null); const clickRef = useRef(onNodeClick); clickRef.current = onNodeClick; + const edgeClickRef = useRef(onEdgeClick); + edgeClickRef.current = onEdgeClick; const editNodeRef = useRef(onEditNode); editNodeRef.current = onEditNode; // 单击下钻延时:等一拍看是否双击(双击=改文字,取消下钻)。 @@ -189,9 +211,10 @@ export function FlowDiagram({ graph, variant, onNodeClick, onEditNode, ownerOpti ); } - // 连线与标注画在形状之下的图层(层序号小于默认元素层)。 - const annotationLayer = canvas.getLayer("flow-annotations", -1); - drawAnnotations(annotationLayer as SVGElement, layout, variant); + // 连线与标注画在形状之下的图层(层序号小于默认元素层); + // 边可点时提到形状层之上(层序 1),命中垫才接得到点击 —— 线避框走,不遮节点 + const annotationLayer = canvas.getLayer("flow-annotations", edgeClickRef.current === undefined ? -1 : 1); + drawAnnotations(annotationLayer as SVGElement, layout, variant, (edge) => edgeClickRef.current?.(edge)); if (layout.ghost) { (canvas.getContainer().querySelector(".djs-container svg, svg") as SVGElement | null)?.setAttribute( "opacity", diff --git a/apps/web/src/shared/gov/flow/FlowFigure.tsx b/apps/web/src/shared/gov/flow/FlowFigure.tsx index 5d98c69..979cd5e 100644 --- a/apps/web/src/shared/gov/flow/FlowFigure.tsx +++ b/apps/web/src/shared/gov/flow/FlowFigure.tsx @@ -13,7 +13,7 @@ import type { ProcessPackage } from '@contracts'; import { Ico } from '@ui'; import { FlowDiagram } from './FlowDiagram.tsx'; import { FlowEditor } from './FlowEditor.tsx'; -import type { FlowGraph } from './flow-layout.ts'; +import type { FlowEdge, FlowGraph } from './flow-layout.ts'; import type { SpPosition } from './support.tsx'; import { packageToGraph } from './pkg-to-graph.ts'; import type { InstanceMark } from './pkg-to-graph.ts'; @@ -27,6 +27,7 @@ export function FlowFigureBlock({ positions, canEdit, onNodeClick, + onEdgeClick, onEditNodeText, onSaveFlowGraph, }: { @@ -38,6 +39,8 @@ export function FlowFigureBlock({ positions?: SpPosition[] | undefined; canEdit: boolean; onNodeClick: (nodeId: string) => void; + /** 点击连线选中边(属性卡随之切到该边);不传则边不可点 */ + onEdgeClick?: ((edge: FlowEdge) => void) | undefined; /** 双击流程图活动就地改文字(标题 / 主办) */ onEditNodeText?: ((nodeId: string, patch: { label: string; owner?: string }) => Promise) | undefined; /** 手工绘图:整图保存(idMap = 本次编辑会话 原id→现id,宿主用它重键下钻内容) */ @@ -52,7 +55,7 @@ export function FlowFigureBlock({