blob: b5bf10680bf37e5dfcd4d45bc637468a4d9995c6 [file] [log] [blame]
86133ec55c542025-04-21 11:51:32 +08001import React, { useState, useRef, useEffect } from 'react';
2import { PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
3import {
4 Button,
5 message,
6 Drawer,
7 Modal,
8 Form,
9 Input,
10 Select,
11 DatePicker,
12 Card,
13 Layout,
14} from 'antd';
15import type { FormInstance } from 'antd';
16import {
17 ProTable,
18 ActionType,
19 ProColumns,
20 FooterToolbar,
21 ProDescriptions,
22 ProDescriptionsItemProps,
23} from '@ant-design/pro-components';
24import type { TrackerProject } from '../data.d.ts';
25import {
26 listTrackerProject,
27 getTrackerProject,
28 addTrackerProject,
29 updateTrackerProject,
30 removeTrackerProject,
31} from '../service';
32
33const { Content } = Layout;
34
35const TrackerProjectPage: React.FC = () => {
36 const actionRef = useRef<ActionType>();
37 const [detailVisible, setDetailVisible] = useState(false);
38 const [editVisible, setEditVisible] = useState(false);
39 const [current, setCurrent] = useState<TrackerProject>();
40 const [form] = Form.useForm();
41
42 const columns: ProColumns<TrackerProject>[] = [
43 {
44 title: '项目ID',
45 dataIndex: 'projectId',
46 render: (_, row) => (
47 <a
48 onClick={async () => {
49 const res = await getTrackerProject(row.projectId!);
50 setCurrent(res.data);
51 setDetailVisible(true);
52 }}
53 >
54 {row.projectId}
55 </a>
56 ),
57 },
58 { title: '项目名称', dataIndex: 'projectName' },
59 { title: '描述', dataIndex: 'description', hideInSearch: true },
60 { title: '状态', dataIndex: 'status', valueEnum: { active: { text: '激活' }, inactive: { text: '不活跃' } } },
61 { title: '创建者', dataIndex: 'createBy', hideInSearch: true },
62 { title: '创建时间', dataIndex: 'createTime', hideInSearch: true },
63 { title: '更新时间', dataIndex: 'updateTime', hideInSearch: true },
64 {
65 title: '操作',
66 valueType: 'option',
67 render: (_, row) => [
68 <Button
69 key="view"
70 type="link"
71 icon={<EyeOutlined />}
72 onClick={async () => {
73 const res = await getTrackerProject(row.projectId!);
74 setCurrent(res.data);
75 setDetailVisible(true);
76 }}
77 >
78 查看
79 </Button>,
80 <Button
81 key="edit"
82 type="link"
83 icon={<EditOutlined />}
84 onClick={() => {
85 setCurrent(row);
86 form.setFieldsValue(row);
87 setEditVisible(true);
88 }}
89 >
90 编辑
91 </Button>,
92 <Button
93 key="delete"
94 type="link"
95 icon={<DeleteOutlined />}
96 danger
97 onClick={() => {
98 Modal.confirm({
99 title: '删除项目',
100 content: '确认删除该项目?',
101 onOk: async () => {
102 await removeTrackerProject([row.projectId!]);
103 message.success('删除成功');
104 actionRef.current?.reload();
105 },
106 });
107 }}
108 >
109 删除
110 </Button>,
111 ],
112 },
113 ];
114
115 /** 新增或更新 */
116 const handleSubmit = async (values: any) => {
117 if (current?.projectId) {
118 await updateTrackerProject({ ...current, ...values });
119 message.success('更新成功');
120 } else {
121 await addTrackerProject(values);
122 message.success('新增成功');
123 }
124 setEditVisible(false);
125 actionRef.current?.reload();
126 };
127
128 return (
129 <Content>
130 <Card bordered={false}>
131 <ProTable<TrackerProject>
132 headerTitle="项目列表"
133 actionRef={actionRef}
134 rowKey="projectId"
135 search={{ labelWidth: 100 }}
136 toolBarRender={() => [
137 <Button
138 key="add"
139 type="primary"
140 icon={<PlusOutlined />}
141 onClick={() => {
142 form.resetFields();
143 setCurrent(undefined);
144 setEditVisible(true);
145 }}
146 >
147 新增
148 </Button>,
149 ]}
150 request={async (params) => {
151 const res = await listTrackerProject(params);
152 return { data: res.rows, success: true, total: res.total };
153 }}
154 columns={columns}
155 />
156
157 {/* 详情 Drawer */}
158 <Drawer
159 width={500}
160 open={detailVisible}
161 onClose={() => setDetailVisible(false)}
162 >
163 {current && (
164 <ProDescriptions<TrackerProject>
165 column={1}
166 title="项目详情"
167 dataSource={current}
168 columns={columns as ProDescriptionsItemProps<TrackerProject>[]}
169 />
170 )}
171 </Drawer>
172
173 {/* 新增/编辑 Modal */}
174 <Modal
175 title={current?.projectId ? '编辑项目' : '新增项目'}
176 open={editVisible}
177 onCancel={() => setEditVisible(false)}
178 onOk={() => {
179 form.validateFields().then(handleSubmit);
180 }}
181 >
182 <Form form={form} layout="vertical">
183 <Form.Item name="projectName" label="项目名称" rules={[{ required: true }]}>
184 <Input />
185 </Form.Item>
186 <Form.Item name="description" label="描述">
187 <Input.TextArea />
188 </Form.Item>
189 <Form.Item name="status" label="状态" initialValue="active">
190 <Select>
191 <Select.Option value="active">激活</Select.Option>
192 <Select.Option value="inactive">不活跃</Select.Option>
193 </Select>
194 </Form.Item>
195 {/* TODO: 补充其他字段 */}
196 </Form>
197 </Modal>
198 </Card>
199 </Content>
200 );
201};
202
203export default TrackerProjectPage;