From a4048776ba86c0ee3fef4a4b82b7efdd452aa85d Mon Sep 17 00:00:00 2001 From: a273825743 Date: Sat, 16 May 2026 02:40:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=EF=BC=9A=E8=B4=A2=E5=8A=A1?= =?UTF-8?q?=E6=94=B9=E9=80=A0=E5=89=8D=E7=9A=84=E7=89=88=E6=9C=AC=20-=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=E5=92=8C?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routes/process-templates.js | 3 --- frontend/src/components/layout/MainLayout.tsx | 7 +++++ frontend/src/pages/admin/ProcessTemplates.tsx | 27 +++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/backend/routes/process-templates.js b/backend/routes/process-templates.js index 10a5042..31ccf15 100644 --- a/backend/routes/process-templates.js +++ b/backend/routes/process-templates.js @@ -57,9 +57,6 @@ router.put('/:id', async (req, res) => { if (existing.rows.length === 0) { return res.status(404).json({ success: false, message: '模板不存在' }); } - if (existing.rows[0].is_system) { - return res.status(403).json({ success: false, message: '系统预设模板不可修改' }); - } const { name, description, phases } = req.body; const updates = []; const values = []; diff --git a/frontend/src/components/layout/MainLayout.tsx b/frontend/src/components/layout/MainLayout.tsx index c34e936..b231be8 100644 --- a/frontend/src/components/layout/MainLayout.tsx +++ b/frontend/src/components/layout/MainLayout.tsx @@ -252,6 +252,13 @@ const MainLayout: React.FC = () => { icon: , label: '系统设置' }, + ...(user?.role === 'admin' ? [{ + type: 'divider' as const + }, { + key: '/admin', + icon: , + label: '后台管理' + }] : []), { type: 'divider' as const }, diff --git a/frontend/src/pages/admin/ProcessTemplates.tsx b/frontend/src/pages/admin/ProcessTemplates.tsx index 56f95d6..62177b7 100644 --- a/frontend/src/pages/admin/ProcessTemplates.tsx +++ b/frontend/src/pages/admin/ProcessTemplates.tsx @@ -37,6 +37,7 @@ const ProcessTemplates: React.FC = () => { const [phaseDrawerVisible, setPhaseDrawerVisible] = useState(false); const [editingPhaseIndex, setEditingPhaseIndex] = useState(-1); const [phaseForm] = Form.useForm(); + const [editingTemplateId, setEditingTemplateId] = useState(null); useEffect(() => { fetchTemplates(); }, []); @@ -53,6 +54,15 @@ const ProcessTemplates: React.FC = () => { form.resetFields(); setPhases([]); setCurrentStep(0); + setEditingTemplateId(null); + setCreateModalVisible(true); + }; + + const handleEdit = (t: Template) => { + form.setFieldsValue({ name: t.name, description: t.description }); + setPhases(t.phases || []); + setCurrentStep(1); + setEditingTemplateId(t.id); setCreateModalVisible(true); }; @@ -83,11 +93,17 @@ const ProcessTemplates: React.FC = () => { const description = form.getFieldValue('description'); if (!name) { message.warning('请输入模板名称'); setCurrentStep(0); return; } if (phases.length === 0) { message.warning('请至少添加一个阶段'); setCurrentStep(1); return; } - await apiClient.post('/process-templates', { name, description, phases }); - message.success('模板创建成功'); + if (editingTemplateId) { + await apiClient.put(`/process-templates/${editingTemplateId}`, { name, description, phases }); + message.success('模板更新成功'); + } else { + await apiClient.post('/process-templates', { name, description, phases }); + message.success('模板创建成功'); + } setCreateModalVisible(false); + setEditingTemplateId(null); fetchTemplates(); - } catch (e) { message.error('创建失败'); } + } catch (e) { message.error('保存失败'); } }; const addPhase = () => { @@ -162,6 +178,7 @@ const ProcessTemplates: React.FC = () => { { title: '操作', key: 'action', render: (_: unknown, r: Template) => ( + {!r.is_system && handleDelete(r.id)}>} @@ -174,14 +191,14 @@ const ProcessTemplates: React.FC = () => { - setCreateModalVisible(false)} width={800} footer={[ + setCreateModalVisible(false)} width={800} footer={[ , currentStep > 0 && , currentStep < 2 && , - currentStep === 2 && , + currentStep === 2 && , ]}>