import { useEffect, useState, useCallback } from 'react'; import { Button, message, Modal, Space, Table, Tag, theme } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import { listProcessDefinitions, createProcessDefinition, updateProcessDefinition, publishProcessDefinition, type ProcessDefinitionInfo, type CreateProcessDefinitionRequest, } from '../../api/workflowDefinitions'; import ProcessDesigner from './ProcessDesigner'; const statusColors: Record = { draft: { bg: '#f6f5f4', color: '#615d59', text: '草稿' }, published: { bg: '#ecfdf5', color: '#1aae39', text: '已发布' }, deprecated: { bg: '#fef2f2', color: '#e5534b', text: '已弃用' }, }; export default function ProcessDefinitions() { const [data, setData] = useState([]); const [total, setTotal] = useState(0); const [page, setPage] = useState(1); const [loading, setLoading] = useState(false); const [designerOpen, setDesignerOpen] = useState(false); const [editingId, setEditingId] = useState(null); const { token } = theme.useToken(); const isDark = token.colorBgContainer === '#111827' || token.colorBgContainer === 'rgb(17, 24, 39)'; const fetchData = useCallback(async (p = page) => { setLoading(true); try { const res = await listProcessDefinitions(p, 20); setData(res.data); setTotal(res.total); } finally { setLoading(false); } }, [page]); useEffect(() => { fetchData(); }, [fetchData]); 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('发布成功'); fetchData(); } catch { message.error('发布失败'); } }; const handleSave = async (req: CreateProcessDefinitionRequest, id?: string) => { try { if (id) { await updateProcessDefinition(id, req); message.success('更新成功'); } else { await createProcessDefinition(req); message.success('创建成功'); } setDesignerOpen(false); fetchData(); } catch { message.error(id ? '更新失败' : '创建失败'); } }; const columns: ColumnsType = [ { title: '名称', dataIndex: 'name', key: 'name', render: (v: string) => {v}, }, { title: '编码', dataIndex: 'key', key: 'key', render: (v: string) => ( {v} ), }, { title: '版本', dataIndex: 'version', key: 'version', width: 80 }, { title: '分类', dataIndex: 'category', key: 'category', width: 120 }, { title: '状态', dataIndex: 'status', key: 'status', width: 100, render: (s: string) => { const info = statusColors[s] || { bg: '#f6f5f4', color: '#615d59', text: s }; return ( {info.text} ); }, }, { title: '操作', key: 'action', width: 200, render: (_, record) => ( {record.status === 'draft' && ( <> )} ), }, ]; return ( <>
共 {total} 个流程定义
`共 ${t} 条记录`, }} /> setDesignerOpen(false)} footer={null} width={1200} destroyOnHidden > ); }