返回 AiToEarn
autoRunRecord.tsx
根目录 / project / aitoearn-electron / src / views / reply / components / autoRunRecord.tsx
1 import { AutoRun, AutoRunRecord, ipcGetAutoRunRecordList } from '@/icp/autoRun';
2 import { Modal, Table } from 'antd';
3 import React from 'react';
4 import { ParseCronSchedule } from '@/components/CronSchedule';
5
6 const { Column } = Table;
7 export interface AutoRunRecordRef {
8 init: (inAutoRun: AutoRun) => Promise<void>;
9 }
10
11 const Com = React.forwardRef<AutoRunRecordRef>((props: any, ref) => {
12 const [autoRunRecordList, setAutoRunRecordList] = React.useState<
13 AutoRunRecord[]
14 >([]);
15 const [autoRun, setAutoRun] = React.useState<AutoRun | null>(null);
16 const [pagination, setPagination] = React.useState({
17 page: 1,
18 pageSize: 10,
19 total: 0,
20 });
21 const [isModalOpen, setIsModalOpen] = React.useState(false);
22
23 async function init(inAutoRun: AutoRun) {
24 setAutoRun(inAutoRun);
25 getAutoRunRecordList(inAutoRun);
26 setIsModalOpen(true);
27 }
28
29 React.useImperativeHandle(ref, () => ({
30 init: init,
31 }));
32
33 /**
34 * 获取自动运行的列表
35 */
36 async function getAutoRunRecordList(inAutoRun: AutoRun) {
37 if (!inAutoRun) return;
38
39 const res = await ipcGetAutoRunRecordList(
40 {
41 page: pagination.page,
42 pageSize: pagination.pageSize,
43 },
44 {
45 autoRunId: inAutoRun.id,
46 },
47 );
48
49 console.log('----- res', res);
50
51 setAutoRunRecordList(res.list);
52 setPagination({
53 ...pagination,
54 total: res.total,
55 });
56 }
57
58 return (
59 <Modal
60 title="任务记录"
61 open={isModalOpen}
62 onCancel={() => {
63 setIsModalOpen(false);
64 }}
65 footer={null}
66 width={600}
67 >
68 <div style={{ width: '100%' }} className="bg-slate-500">
69 <Table
70 key={autoRun?.id}
71 dataSource={autoRunRecordList}
72 style={{ width: '100%' }}
73 className="bg-slate-500"
74 pagination={pagination}
75 onChange={(newPagination) => {
76 setPagination({
77 ...pagination,
78 page: newPagination.current!,
79 pageSize: newPagination.pageSize!,
80 });
81 }}
82 >
83 <Column title="ID" dataIndex="id" key="id" />
84 <Column title="任务DI" dataIndex="autoRunId" key="autoRunId" />
85 <Column title="状态" dataIndex="status" key="status" />
86 <Column title="类型" dataIndex="type" key="type" />
87 <Column
88 title="触发周期"
89 key="cycleType"
90 dataIndex="cycleType"
91 render={(cycleType: string) => (
92 <ParseCronSchedule cronExpression={cycleType} />
93 )}
94 />
95 <Column
96 title="创建时间"
97 key="createTime"
98 dataIndex="createTime"
99 render={(_: any, record: AutoRun) => (
100 <p>{new Date(record.createTime).toLocaleString()}</p>
101 )}
102 />
103 </Table>
104 </div>
105 </Modal>
106 );
107 });
108
109 export default Com;
110
110 lines Plain Text