Skip to content

Let's use AI to Earn!

feat: 任务记录列表

牛文政6acb870ab066
diff --git a/electron/main/autoRun/controller.ts b/electron/main/autoRun/controller.ts
index fa16865c..23f591ed 100644
--- a/electron/main/autoRun/controller.ts
+++ b/electron/main/autoRun/controller.ts
@@ -69,9 +69,9 @@ export class AutoRunController {
@Icp('ICP_AUTO_RUN_STATUS')
async updateAutoRunStatus(
event: Electron.IpcMainInvokeEvent,
- data: { id: number; status: number },
+ id: number,
+ status: AutoRunStatus,
) {
- const { id, status } = data;
const autoRun = await this.autoRunService.updateAutoRunStatus(id, status);
return autoRun;
diff --git a/src/icp/autoRun.ts b/src/icp/autoRun.ts
index 2e9815bb..8a04f76c 100644
--- a/src/icp/autoRun.ts
+++ b/src/icp/autoRun.ts
@@ -91,6 +91,22 @@ export async function ipcGetAutoRunList(
return res;
}
+/**
+ * 更新自动进程状态
+ * @param data
+ */
+export async function ipcUpdateAutoRunStatus(
+ id: number,
+ status: AutoRunStatus,
+) {
+ const res: string = await window.ipcRenderer.invoke(
+ 'ICP_AUTO_RUN_STATUS',
+ id,
+ status,
+ );
+ return res;
+}
+
/**
* 获取进运行记录列表
* @param data
diff --git a/src/views/reply/autoRun.tsx b/src/views/reply/autoRun.tsx
index 4883fcba..28d49e10 100644
--- a/src/views/reply/autoRun.tsx
+++ b/src/views/reply/autoRun.tsx
@@ -1,10 +1,19 @@
-import { AutoRun, AutoRunType, ipcGetAutoRunList } from '@/icp/autoRun';
-import { Space, Table } from 'antd';
+import {
+ AutoRun,
+ AutoRunStatus,
+ AutoRunType,
+ ipcGetAutoRunList,
+ ipcUpdateAutoRunStatus,
+} from '@/icp/autoRun';
+import { Popconfirm, Space, Table } from 'antd';
import React from 'react';
+import AutoRunRecord, { AutoRunRecordRef } from './components/autoRunRecord';
const { Column } = Table;
const Page: React.FC = () => {
+ const Ref_AutoRunRecord = React.useRef<AutoRunRecordRef>(null);
+
const [autoRunList, setAutoRunList] = React.useState<AutoRun[]>([]);
// 分页组件的数据
const [pagination, setPagination] = React.useState({
@@ -34,6 +43,15 @@ const Page: React.FC = () => {
});
}
+ function changeAutoRunStatus(id: number, status: AutoRunStatus) {
+ ipcUpdateAutoRunStatus(id, status);
+ }
+
+ // 打开Ref_AutoRunRecord
+ function openAutoRunRecord(record: AutoRun) {
+ Ref_AutoRunRecord.current?.init(record);
+ }
+
React.useEffect(() => {
getAutoRunList();
}, [pagination.page, pagination.pageSize]);
@@ -73,12 +91,35 @@ const Page: React.FC = () => {
key="action"
render={(_: any, record: AutoRun) => (
<Space size="middle">
- <a>暂停</a>
- <a>删除</a>
+ <Popconfirm
+ title="确认暂停该任务"
+ onConfirm={(e?: React.MouseEvent<HTMLElement>) => {
+ changeAutoRunStatus(record.id, AutoRunStatus.PAUSE);
+ }}
+ okText="是"
+ cancelText="否"
+ >
+ <a>暂停</a>
+ </Popconfirm>
+
+ <Popconfirm
+ title="确认停止该任务"
+ onConfirm={(e?: React.MouseEvent<HTMLElement>) => {
+ changeAutoRunStatus(record.id, AutoRunStatus.DELETE);
+ }}
+ okText="是"
+ cancelText="否"
+ >
+ <a>删除</a>
+ </Popconfirm>
+
+ <a onClick={() => openAutoRunRecord(record)}>打开记录</a>
</Space>
)}
/>
</Table>
+
+ <AutoRunRecord ref={Ref_AutoRunRecord} />
</div>
);
};
diff --git a/src/views/reply/components/autoRunRecord.tsx b/src/views/reply/components/autoRunRecord.tsx
index 33fdf904..b51ed56e 100644
--- a/src/views/reply/components/autoRunRecord.tsx
+++ b/src/views/reply/components/autoRunRecord.tsx
@@ -3,8 +3,11 @@ import { Modal, Table } from 'antd';
import React from 'react';
const { Column } = Table;
+export interface AutoRunRecordRef {
+ init: (inAutoRun: AutoRun) => Promise<void>;
+}
-const Page: React.FC = (props: any, ref) => {
+const Com = React.forwardRef<AutoRunRecordRef>((props: any, ref) => {
const [autoRunRecordList, setAutoRunRecordList] = React.useState<
AutoRunRecord[]
>([]);
@@ -94,6 +97,6 @@ const Page: React.FC = (props: any, ref) => {
</div>
</Modal>
);
-};
+});
-export default Page;
+export default Com;