blob: 46e3313c2f5fce9462953814e4f4770e408d4101 [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001
2import React, { useState, useRef, useEffect } from 'react';
3import { useIntl, FormattedMessage, useAccess, useParams, history } from '@umijs/max';
4import type { FormInstance } from 'antd';
5import { Button, message, Modal } from 'antd';
6import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
7import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
8import { getJobLogList, removeJobLog, exportJobLog } from '@/services/monitor/jobLog';
9import DetailForm from './detail';
10import { getDictValueEnum } from '@/services/system/dict';
11import { getJob } from '@/services/monitor/job';
12import DictTag from '@/components/DictTag';
13
14/**
15 * 定时任务调度日志 List Page
16 *
17 * @author whiteshader
18 * @date 2023-02-07
19 */
20
21/**
22 * 删除节点
23 *
24 * @param selectedRows
25 */
26const handleRemove = async (selectedRows: API.Monitor.JobLog[]) => {
27 const hide = message.loading('正在删除');
28 if (!selectedRows) return true;
29 try {
30 const resp = await removeJobLog(selectedRows.map((row) => row.jobLogId).join(','));
31 hide();
32 if (resp.code === 200) {
33 message.success('删除成功,即将刷新');
34 } else {
35 message.error(resp.msg);
36 }
37 return true;
38 } catch (error) {
39 hide();
40 message.error('删除失败,请重试');
41 return false;
42 }
43};
44
45const handleRemoveOne = async (selectedRow: API.Monitor.JobLog) => {
46 const hide = message.loading('正在删除');
47 if (!selectedRow) return true;
48 try {
49 const params = [selectedRow.jobLogId];
50 const resp = await removeJobLog(params.join(','));
51 hide();
52 if (resp.code === 200) {
53 message.success('删除成功,即将刷新');
54 } else {
55 message.error(resp.msg);
56 }
57 return true;
58 } catch (error) {
59 hide();
60 message.error('删除失败,请重试');
61 return false;
62 }
63};
64
65/**
66 * 清空日志数据
67 *
68 */
69const handleExport = async () => {
70 const hide = message.loading('正在导出');
71 try {
72 await exportJobLog();
73 hide();
74 message.success('导出成功');
75 return true;
76 } catch (error) {
77 hide();
78 message.error('导出失败,请重试');
79 return false;
80 }
81};
82
83
84const JobLogTableList: React.FC = () => {
85 const formTableRef = useRef<FormInstance>();
86
87 const [modalOpen, setModalOpen] = useState<boolean>(false);
88
89 const actionRef = useRef<ActionType>();
90 const [currentRow, setCurrentRow] = useState<API.Monitor.JobLog>();
91 const [selectedRows, setSelectedRows] = useState<API.Monitor.JobLog[]>([]);
92
93 const [jobGroupOptions, setJobGroupOptions] = useState<any>([]);
94 const [statusOptions, setStatusOptions] = useState<any>([]);
95
96 const [queryParams, setQueryParams] = useState<any>([]);
97
98 const access = useAccess();
99
100 /** 国际化配置 */
101 const intl = useIntl();
102
103 const params = useParams();
104 if (params.id === undefined) {
105 history.push('/monitor/job');
106 }
107 const jobId = params.id || 0;
108 useEffect(() => {
109 if (jobId !== undefined && jobId !== 0) {
110 getJob(Number(jobId)).then(response => {
111 setQueryParams({
112 jobName: response.data.jobName,
113 jobGroup: response.data.jobGroup
114 });
115 });
116 }
117 getDictValueEnum('sys_job_status').then((data) => {
118 setStatusOptions(data);
119 });
120 getDictValueEnum('sys_job_group').then((data) => {
121 setJobGroupOptions(data);
122 });
123 }, []);
124
125 const columns: ProColumns<API.Monitor.JobLog>[] = [
126 {
127 title: <FormattedMessage id="monitor.job.log.job_log_id" defaultMessage="任务日志编号" />,
128 dataIndex: 'jobLogId',
129 valueType: 'text',
130 hideInSearch: true,
131 },
132 {
133 title: <FormattedMessage id="monitor.job.log.job_name" defaultMessage="任务名称" />,
134 dataIndex: 'jobName',
135 valueType: 'text',
136 },
137 {
138 title: <FormattedMessage id="monitor.job.log.job_group" defaultMessage="任务组名" />,
139 dataIndex: 'jobGroup',
140 valueType: 'text',
141 },
142 {
143 title: <FormattedMessage id="monitor.job.log.invoke_target" defaultMessage="调用目标字符串" />,
144 dataIndex: 'invokeTarget',
145 valueType: 'textarea',
146 },
147 {
148 title: <FormattedMessage id="monitor.job.log.job_message" defaultMessage="日志信息" />,
149 dataIndex: 'jobMessage',
150 valueType: 'textarea',
151 },
152 {
153 title: <FormattedMessage id="monitor.job.log.status" defaultMessage="执行状态" />,
154 dataIndex: 'status',
155 valueType: 'select',
156 valueEnum: statusOptions,
157 render: (_, record) => {
158 return (<DictTag enums={statusOptions} value={record.status} />);
159 },
160 },
161 {
162 title: <FormattedMessage id="monitor.job.log.create_time" defaultMessage="异常信息" />,
163 dataIndex: 'createTime',
164 valueType: 'text',
165 },
166 {
167 title: <FormattedMessage id="pages.searchTable.titleOption" defaultMessage="操作" />,
168 dataIndex: 'option',
169 width: '120px',
170 valueType: 'option',
171 render: (_, record) => [
172 <Button
173 type="link"
174 size="small"
175 key="edit"
176 hidden={!access.hasPerms('monitor:job-log:edit')}
177 onClick={() => {
178 setModalOpen(true);
179 setCurrentRow(record);
180 }}
181 >
182 编辑
183 </Button>,
184 <Button
185 type="link"
186 size="small"
187 danger
188 key="batchRemove"
189 hidden={!access.hasPerms('monitor:job-log:remove')}
190 onClick={async () => {
191 Modal.confirm({
192 title: '删除',
193 content: '确定删除该项吗?',
194 okText: '确认',
195 cancelText: '取消',
196 onOk: async () => {
197 const success = await handleRemoveOne(record);
198 if (success) {
199 if (actionRef.current) {
200 actionRef.current.reload();
201 }
202 }
203 },
204 });
205 }}
206 >
207 删除
208 </Button>,
209 ],
210 },
211 ];
212
213 return (
214 <PageContainer>
215 <div style={{ width: '100%', float: 'right' }}>
216 <ProTable<API.Monitor.JobLog>
217 headerTitle={intl.formatMessage({
218 id: 'pages.searchTable.title',
219 defaultMessage: '信息',
220 })}
221 actionRef={actionRef}
222 formRef={formTableRef}
223 rowKey="jobLogId"
224 key="job-logList"
225 search={{
226 labelWidth: 120,
227 }}
228 toolBarRender={() => [
229 <Button
230 type="primary"
231 key="add"
232 hidden={!access.hasPerms('monitor:job-log:add')}
233 onClick={async () => {
234 setCurrentRow(undefined);
235 setModalOpen(true);
236 }}
237 >
238 <PlusOutlined /> <FormattedMessage id="pages.searchTable.new" defaultMessage="新建" />
239 </Button>,
240 <Button
241 type="primary"
242 key="remove"
243 danger
244 hidden={selectedRows?.length === 0 || !access.hasPerms('monitor:job-log:remove')}
245 onClick={async () => {
246 Modal.confirm({
247 title: '是否确认删除所选数据项?',
248 icon: <ExclamationCircleOutlined />,
249 content: '请谨慎操作',
250 async onOk() {
251 const success = await handleRemove(selectedRows);
252 if (success) {
253 setSelectedRows([]);
254 actionRef.current?.reloadAndRest?.();
255 }
256 },
257 onCancel() { },
258 });
259 }}
260 >
261 <DeleteOutlined />
262 <FormattedMessage id="pages.searchTable.delete" defaultMessage="删除" />
263 </Button>,
264 <Button
265 type="primary"
266 key="export"
267 hidden={!access.hasPerms('monitor:job-log:export')}
268 onClick={async () => {
269 handleExport();
270 }}
271 >
272 <PlusOutlined />
273 <FormattedMessage id="pages.searchTable.export" defaultMessage="导出" />
274 </Button>,
275 ]}
276 params={queryParams}
277 request={(params) =>
278 getJobLogList({ ...params } as API.Monitor.JobLogListParams).then((res) => {
279 const result = {
280 data: res.rows,
281 total: res.total,
282 success: true,
283 };
284 return result;
285 })
286 }
287 columns={columns}
288 rowSelection={{
289 onChange: (_, selectedRows) => {
290 setSelectedRows(selectedRows);
291 },
292 }}
293 />
294 </div>
295 {selectedRows?.length > 0 && (
296 <FooterToolbar
297 extra={
298 <div>
299 <FormattedMessage id="pages.searchTable.chosen" defaultMessage="已选择" />
300 <a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
301 <FormattedMessage id="pages.searchTable.item" defaultMessage="项" />
302 </div>
303 }
304 >
305 <Button
306 key="remove"
307 danger
308 hidden={!access.hasPerms('monitor:job-log:del')}
309 onClick={async () => {
310 Modal.confirm({
311 title: '删除',
312 content: '确定删除该项吗?',
313 okText: '确认',
314 cancelText: '取消',
315 onOk: async () => {
316 const success = await handleRemove(selectedRows);
317 if (success) {
318 setSelectedRows([]);
319 actionRef.current?.reloadAndRest?.();
320 }
321 },
322 });
323 }}
324 >
325 <FormattedMessage id="pages.searchTable.batchDeletion" defaultMessage="批量删除" />
326 </Button>
327 </FooterToolbar>
328 )}
329 <DetailForm
330 onCancel={() => {
331 setModalOpen(false);
332 setCurrentRow(undefined);
333 }}
334 open={modalOpen}
335 values={currentRow || {}}
336 statusOptions={statusOptions}
337 jobGroupOptions={jobGroupOptions}
338 />
339 </PageContainer>
340 );
341};
342
343export default JobLogTableList;