返回 AiToEarn
addAutoRun.tsx
1 /*
2 * @Author: nevin
3 * @Date: 2025-03-18 21:02:38
4 * @LastEditTime: 2025-03-25 13:41:14
5 * @LastEditors: nevin
6 * @Description: 添加自动运行
7 */
8 import { ipcCreateAutoRunOfReply, WorkData } from '@/icp/reply';
9 import { Modal } from 'antd';
10 import { forwardRef, useImperativeHandle, useState } from 'react';
11 import { CronSchedule } from '@/components/CronSchedule';
12
13 export interface AddAutoRunRef {
14 init: (accountId: number, data: WorkData) => Promise<void>;
15 }
16
17 const Com = forwardRef<AddAutoRunRef>((props: any, ref) => {
18 const [isModalOpen, setIsModalOpen] = useState(false);
19 const [accountId, setAccountId] = useState<number>(0);
20 const [workData, setWorkData] = useState<WorkData | null>(null);
21
22 // '周期类型 天 day-22 (例:每天22时) 周 week-2 (例:每周周二,周日0) 月 month-22 (例:每月22号)',
23 const [cycleType, setCycleType] = useState<string>('');
24 async function init(accountId: number, data: WorkData) {
25 setAccountId(accountId);
26 setWorkData(data);
27 setIsModalOpen(true);
28 }
29
30 useImperativeHandle(ref, () => ({
31 init: init,
32 }));
33
34 function handleCancel() {
35 setIsModalOpen(false);
36 }
37
38 async function handleCron(cron: string) {
39 console.log('生成的定时表达式:----', cron);
40 if (!workData) return;
41
42 setCycleType(cron);
43 const res = await ipcCreateAutoRunOfReply(accountId, workData, cron);
44 console.log('-------- res', res);
45 }
46
47 return (
48 <>
49 <Modal
50 title="创建自动回复评论任务"
51 open={isModalOpen}
52 onCancel={handleCancel}
53 footer={null}
54 width={400}
55 >
56 <CronSchedule onSubmit={handleCron} />
57 </Modal>
58 </>
59 );
60 });
61 export default Com;
62
62 lines Plain Text