feat(workflow): add workflow engine module (Phase 4)

Implement complete workflow engine with BPMN subset support:

Backend (erp-workflow crate):
- Token-driven execution engine with exclusive/parallel gateway support
- BPMN parser with flow graph validation
- Expression evaluator for conditional branching
- Process definition CRUD with draft/publish lifecycle
- Process instance management (start, suspend, terminate)
- Task service (pending, complete, delegate)
- PostgreSQL advisory locks for concurrent safety
- 5 database tables: process_definitions, process_instances,
  tokens, tasks, process_variables
- 13 API endpoints with RBAC protection
- Timeout checker framework (placeholder)

Frontend:
- Workflow page with 4 tabs (definitions, pending, completed, monitor)
- React Flow visual process designer (@xyflow/react)
- Process viewer with active node highlighting
- 3 API client modules for workflow endpoints
- Sidebar menu integration
This commit is contained in:
iven
2026-04-11 09:54:02 +08:00
parent 0cbd08eb78
commit 91ecaa3ed7
51 changed files with 4826 additions and 12 deletions

View File

@@ -0,0 +1,78 @@
import { useEffect, useState } from 'react';
import { Button, message, Space, Table, Tag } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import {
listInstances,
terminateInstance,
type ProcessInstanceInfo,
} from '../../api/workflowInstances';
const statusColors: Record<string, string> = {
running: 'processing',
suspended: 'warning',
completed: 'green',
terminated: 'red',
};
export default function InstanceMonitor() {
const [data, setData] = useState<ProcessInstanceInfo[]>([]);
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);
const fetch = async () => {
setLoading(true);
try {
const res = await listInstances(page, 20);
setData(res.data);
setTotal(res.total);
} finally {
setLoading(false);
}
};
useEffect(() => { fetch(); }, [page]);
const handleTerminate = async (id: string) => {
try {
await terminateInstance(id);
message.success('已终止');
fetch();
} catch {
message.error('操作失败');
}
};
const columns: ColumnsType<ProcessInstanceInfo> = [
{ title: '流程', dataIndex: 'definition_name', key: 'definition_name' },
{ title: '业务键', dataIndex: 'business_key', key: 'business_key' },
{
title: '状态', dataIndex: 'status', key: 'status', width: 100,
render: (s: string) => <Tag color={statusColors[s]}>{s}</Tag>,
},
{ title: '当前节点', key: 'current_nodes', width: 150,
render: (_, record) => record.active_tokens.map(t => t.node_id).join(', ') || '-',
},
{ title: '发起时间', dataIndex: 'started_at', key: 'started_at', width: 180,
render: (v: string) => new Date(v).toLocaleString(),
},
{
title: '操作', key: 'action', width: 100,
render: (_, record) => (
record.status === 'running' ? (
<Button size="small" danger onClick={() => handleTerminate(record.id)}></Button>
) : null
),
},
];
return (
<Table
rowKey="id"
columns={columns}
dataSource={data}
loading={loading}
pagination={{ current: page, total, pageSize: 20, onChange: setPage }}
/>
);
}