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:
122
apps/web/src/pages/workflow/ProcessDefinitions.tsx
Normal file
122
apps/web/src/pages/workflow/ProcessDefinitions.tsx
Normal file
@@ -0,0 +1,122 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Button, message, Modal, Space, Table, Tag } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import {
|
||||
listProcessDefinitions,
|
||||
createProcessDefinition,
|
||||
publishProcessDefinition,
|
||||
type ProcessDefinitionInfo,
|
||||
type CreateProcessDefinitionRequest,
|
||||
} from '../../api/workflowDefinitions';
|
||||
import ProcessDesigner from './ProcessDesigner';
|
||||
|
||||
const statusColors: Record<string, string> = {
|
||||
draft: 'default',
|
||||
published: 'green',
|
||||
deprecated: 'red',
|
||||
};
|
||||
|
||||
export default function ProcessDefinitions() {
|
||||
const [data, setData] = useState<ProcessDefinitionInfo[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [page, setPage] = useState(1);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [designerOpen, setDesignerOpen] = useState(false);
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
|
||||
const fetch = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await listProcessDefinitions(page, 20);
|
||||
setData(res.data);
|
||||
setTotal(res.total);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => { fetch(); }, [page]);
|
||||
|
||||
const handleCreate = () => {
|
||||
setEditingId(null);
|
||||
setDesignerOpen(true);
|
||||
};
|
||||
|
||||
const handleEdit = (id: string) => {
|
||||
setEditingId(id);
|
||||
setDesignerOpen(true);
|
||||
};
|
||||
|
||||
const handlePublish = async (id: string) => {
|
||||
try {
|
||||
await publishProcessDefinition(id);
|
||||
message.success('发布成功');
|
||||
fetch();
|
||||
} catch {
|
||||
message.error('发布失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async (req: CreateProcessDefinitionRequest) => {
|
||||
try {
|
||||
await createProcessDefinition(req);
|
||||
message.success('创建成功');
|
||||
setDesignerOpen(false);
|
||||
fetch();
|
||||
} catch {
|
||||
message.error('创建失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ColumnsType<ProcessDefinitionInfo> = [
|
||||
{ title: '名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '编码', dataIndex: 'key', key: 'key' },
|
||||
{ title: '版本', dataIndex: 'version', key: 'version', width: 80 },
|
||||
{ title: '分类', dataIndex: 'category', key: 'category', width: 120 },
|
||||
{
|
||||
title: '状态', dataIndex: 'status', key: 'status', width: 100,
|
||||
render: (s: string) => <Tag color={statusColors[s]}>{s}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '操作', key: 'action', width: 200,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
{record.status === 'draft' && (
|
||||
<>
|
||||
<Button size="small" onClick={() => handleEdit(record.id)}>编辑</Button>
|
||||
<Button size="small" type="primary" onClick={() => handlePublish(record.id)}>发布</Button>
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Button type="primary" onClick={handleCreate}>新建流程</Button>
|
||||
</div>
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
loading={loading}
|
||||
pagination={{ current: page, total, pageSize: 20, onChange: setPage }}
|
||||
/>
|
||||
<Modal
|
||||
title={editingId ? '编辑流程' : '新建流程'}
|
||||
open={designerOpen}
|
||||
onCancel={() => setDesignerOpen(false)}
|
||||
footer={null}
|
||||
width={1200}
|
||||
destroyOnClose
|
||||
>
|
||||
<ProcessDesigner
|
||||
definitionId={editingId}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user