index.tsx
6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* @Date: 2021-03-23 17:47:45
* @LastEditors: wangqiang@feewee.cn
* @LastEditTime: 2023-01-30 11:19:10
*/
import React, { useEffect, useState } from "react";
import {
Modal,
Button,
Row,
Input,
Popconfirm,
message,
Card,
ConfigProvider,
Table,
Divider,
Form,
Spin,
} from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { getWorkTypeListApi, saveWorkTypeApi, deleteWorkTypeApi } from "./api";
import { debounce } from "lodash";
import usePagination from "@/hooks/usePagination";
import { PageHeaderWrapper } from "@ant-design/pro-layout";
import zhCN from "antd/lib/locale-provider/zh_CN";
import { history } from "umi";
import FeeweeFilterOption from "@/pages/notice/components/FeeweeFilterOption";
export default function WorkTypeSettings() {
const systemDefine = history.location.pathname.includes(
"workTypeSetting_private"
);
const workTypePagination = usePagination(getWorkTypeListApi, {
systemDefine,
});
const {
list,
loading,
setLoading,
paginationConfig,
setParams: setExamTypeParams,
} = workTypePagination;
const [form] = Form.useForm();
const [confirmLoading, setConfirmLoading] = useState(false);
const [current, setCurrent] = useState<WorkTypeSetting.WorkTypeItemVO>();
const [open, setOpen] = useState(false);
useEffect(() => {
if (open) {
current &&
form.setFieldsValue({
...current,
});
} else {
form.resetFields();
}
}, [open, current]);
const delItem = (id: number) => {
deleteWorkTypeApi(id)
.then((res) => {
message.success("删除成功");
setLoading(true);
})
.catch((error) => message.error(error.message));
};
const onSearch = debounce(
(name: string) => setExamTypeParams({ name, current: 1 }, true),
500
);
const onOk = (val: any) => {
const params: WorkTypeSetting.WorkTypeItemVO = {
id: current?.id,
name: val.name,
key: val?.key,
pageLink: val.pageLink,
systemDefine,
};
setConfirmLoading(true);
saveWorkTypeApi(params)
.then((res) => {
setConfirmLoading(false);
message.success(res.result);
setOpen(false);
setLoading(true);
})
.catch((error) => {
setConfirmLoading(false);
message.error(error.message || "保存工作类型失败");
});
};
return (
<PageHeaderWrapper title={`工作类型设置${systemDefine ? "(内部)" : ""}`}>
<ConfigProvider locale={zhCN}>
<Card bordered={false}>
<Row justify="space-between" style={{ marginBottom: 20 }}>
<FeeweeFilterOption title="工作类型">
<Input
placeholder="输入工作类型查询"
allowClear
style={{ minWidth: 260 }}
onChange={(e) => onSearch(e.target.value)}
/>
</FeeweeFilterOption>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => {
setCurrent(undefined);
setOpen(true);
}}
>
添加
</Button>
</Row>
<Table
dataSource={list}
pagination={paginationConfig}
loading={loading}
rowKey="id"
>
<Table.Column title="工作类型" dataIndex="name" align="left" />
{systemDefine ? (
<>
<Table.Column
title="业务详情key"
dataIndex="key"
align="left"
render={(key: string) => key || "-"}
/>
<Table.Column
title="业务详情APP路径"
dataIndex="pageLink"
align="left"
render={(pageLink: string) => pageLink || "-"}
/>
</>
) : null}
<Table.Column
title="操作"
align="left"
render={(record: WorkTypeSetting.WorkTypeItemVO) => (
<>
<a
onClick={() => {
setCurrent(record);
setOpen(true);
}}
>
编辑
</a>
{/* <Divider type="vertical" />
<Popconfirm
title={`确定删除【${record.name}】工作类型?`}
onConfirm={() => delItem(record.id!)}
>
<a style={{ color: "#F0492C" }}>删除</a>
</Popconfirm> */}
</>
)}
/>
</Table>
<Modal
title={`${current ? "编辑" : "添加"}工作类型`}
open={open}
maskClosable={false}
onOk={form.submit}
onCancel={() => setOpen(false)}
afterClose={() => {
setCurrent(undefined);
}}
confirmLoading={confirmLoading}
>
<Spin spinning={confirmLoading}>
<Form form={form} onFinish={onOk}>
<Form.Item
name="name"
label="工作类型"
rules={[{ required: true, message: "请输入工作类型" }]}
>
<Input placeholder="请输入工作类型" allowClear />
</Form.Item>
{systemDefine ? (
<>
<Form.Item
name="key"
label="业务详情key"
rules={[{ required: true, message: "请输入业务详情key" }]}
>
<Input placeholder="请输入业务详情key" allowClear />
</Form.Item>
<Form.Item
name="pageLink"
label="业务详情APP路径"
rules={[
{ required: true, message: "请输入业务详情APP路径" },
]}
>
<Input placeholder="请输入业务详情APP路径" allowClear />
</Form.Item>
</>
) : null}
</Form>
</Spin>
</Modal>
</Card>
</ConfigProvider>
</PageHeaderWrapper>
);
}