备份:财务改造前的版本 - 模板编辑功能和管理员入口
This commit is contained in:
@@ -57,9 +57,6 @@ router.put('/:id', async (req, res) => {
|
|||||||
if (existing.rows.length === 0) {
|
if (existing.rows.length === 0) {
|
||||||
return res.status(404).json({ success: false, message: '模板不存在' });
|
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 { name, description, phases } = req.body;
|
||||||
const updates = [];
|
const updates = [];
|
||||||
const values = [];
|
const values = [];
|
||||||
|
|||||||
@@ -252,6 +252,13 @@ const MainLayout: React.FC = () => {
|
|||||||
icon: <SettingOutlined />,
|
icon: <SettingOutlined />,
|
||||||
label: '系统设置'
|
label: '系统设置'
|
||||||
},
|
},
|
||||||
|
...(user?.role === 'admin' ? [{
|
||||||
|
type: 'divider' as const
|
||||||
|
}, {
|
||||||
|
key: '/admin',
|
||||||
|
icon: <SettingOutlined />,
|
||||||
|
label: '后台管理'
|
||||||
|
}] : []),
|
||||||
{
|
{
|
||||||
type: 'divider' as const
|
type: 'divider' as const
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const ProcessTemplates: React.FC = () => {
|
|||||||
const [phaseDrawerVisible, setPhaseDrawerVisible] = useState(false);
|
const [phaseDrawerVisible, setPhaseDrawerVisible] = useState(false);
|
||||||
const [editingPhaseIndex, setEditingPhaseIndex] = useState<number>(-1);
|
const [editingPhaseIndex, setEditingPhaseIndex] = useState<number>(-1);
|
||||||
const [phaseForm] = Form.useForm();
|
const [phaseForm] = Form.useForm();
|
||||||
|
const [editingTemplateId, setEditingTemplateId] = useState<number | null>(null);
|
||||||
|
|
||||||
useEffect(() => { fetchTemplates(); }, []);
|
useEffect(() => { fetchTemplates(); }, []);
|
||||||
|
|
||||||
@@ -53,6 +54,15 @@ const ProcessTemplates: React.FC = () => {
|
|||||||
form.resetFields();
|
form.resetFields();
|
||||||
setPhases([]);
|
setPhases([]);
|
||||||
setCurrentStep(0);
|
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);
|
setCreateModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,11 +93,17 @@ const ProcessTemplates: React.FC = () => {
|
|||||||
const description = form.getFieldValue('description');
|
const description = form.getFieldValue('description');
|
||||||
if (!name) { message.warning('请输入模板名称'); setCurrentStep(0); return; }
|
if (!name) { message.warning('请输入模板名称'); setCurrentStep(0); return; }
|
||||||
if (phases.length === 0) { message.warning('请至少添加一个阶段'); setCurrentStep(1); return; }
|
if (phases.length === 0) { message.warning('请至少添加一个阶段'); setCurrentStep(1); return; }
|
||||||
await apiClient.post('/process-templates', { name, description, phases });
|
if (editingTemplateId) {
|
||||||
message.success('模板创建成功');
|
await apiClient.put(`/process-templates/${editingTemplateId}`, { name, description, phases });
|
||||||
|
message.success('模板更新成功');
|
||||||
|
} else {
|
||||||
|
await apiClient.post('/process-templates', { name, description, phases });
|
||||||
|
message.success('模板创建成功');
|
||||||
|
}
|
||||||
setCreateModalVisible(false);
|
setCreateModalVisible(false);
|
||||||
|
setEditingTemplateId(null);
|
||||||
fetchTemplates();
|
fetchTemplates();
|
||||||
} catch (e) { message.error('创建失败'); }
|
} catch (e) { message.error('保存失败'); }
|
||||||
};
|
};
|
||||||
|
|
||||||
const addPhase = () => {
|
const addPhase = () => {
|
||||||
@@ -162,6 +178,7 @@ const ProcessTemplates: React.FC = () => {
|
|||||||
{ title: '操作', key: 'action', render: (_: unknown, r: Template) => (
|
{ title: '操作', key: 'action', render: (_: unknown, r: Template) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button size="small" icon={<EyeOutlined />} onClick={() => handleView(r)}>查看</Button>
|
<Button size="small" icon={<EyeOutlined />} onClick={() => handleView(r)}>查看</Button>
|
||||||
|
<Button size="small" type="primary" icon={<EditOutlined />} onClick={() => handleEdit(r)}>编辑</Button>
|
||||||
<Button size="small" icon={<CopyOutlined />} onClick={() => handleCopy(r)}>复制</Button>
|
<Button size="small" icon={<CopyOutlined />} onClick={() => handleCopy(r)}>复制</Button>
|
||||||
{!r.is_system && <Popconfirm title="确定删除?" onConfirm={() => handleDelete(r.id)}><Button size="small" danger icon={<DeleteOutlined />}>删除</Button></Popconfirm>}
|
{!r.is_system && <Popconfirm title="确定删除?" onConfirm={() => handleDelete(r.id)}><Button size="small" danger icon={<DeleteOutlined />}>删除</Button></Popconfirm>}
|
||||||
</Space>
|
</Space>
|
||||||
@@ -174,14 +191,14 @@ const ProcessTemplates: React.FC = () => {
|
|||||||
<Table columns={columns} dataSource={templates} rowKey="id" loading={loading} pagination={false} />
|
<Table columns={columns} dataSource={templates} rowKey="id" loading={loading} pagination={false} />
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Modal title="新建工程模板" open={createModalVisible} onCancel={() => setCreateModalVisible(false)} width={800} footer={[
|
<Modal title={editingTemplateId ? "编辑工程模板" : "新建工程模板"} open={createModalVisible} onCancel={() => setCreateModalVisible(false)} width={800} footer={[
|
||||||
<Button key="cancel" onClick={() => setCreateModalVisible(false)}>取消</Button>,
|
<Button key="cancel" onClick={() => setCreateModalVisible(false)}>取消</Button>,
|
||||||
currentStep > 0 && <Button key="prev" onClick={() => setCurrentStep(currentStep - 1)}>上一步</Button>,
|
currentStep > 0 && <Button key="prev" onClick={() => setCurrentStep(currentStep - 1)}>上一步</Button>,
|
||||||
currentStep < 2 && <Button key="next" type="primary" onClick={() => {
|
currentStep < 2 && <Button key="next" type="primary" onClick={() => {
|
||||||
if (currentStep === 0 && !form.getFieldValue('name')) { message.warning('请输入模板名称'); return; }
|
if (currentStep === 0 && !form.getFieldValue('name')) { message.warning('请输入模板名称'); return; }
|
||||||
setCurrentStep(currentStep + 1);
|
setCurrentStep(currentStep + 1);
|
||||||
}}>下一步</Button>,
|
}}>下一步</Button>,
|
||||||
currentStep === 2 && <Button key="save" type="primary" onClick={handleSaveTemplate}>确认创建</Button>,
|
currentStep === 2 && <Button key="save" type="primary" onClick={handleSaveTemplate}>{editingTemplateId ? '保存修改' : '确认创建'}</Button>,
|
||||||
]}>
|
]}>
|
||||||
<Steps current={currentStep} size="small" style={{ marginBottom: 24 }}>
|
<Steps current={currentStep} size="small" style={{ marginBottom: 24 }}>
|
||||||
<Steps.Step title="基本信息" />
|
<Steps.Step title="基本信息" />
|
||||||
|
|||||||
Reference in New Issue
Block a user