Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 自动化的页面
yikaJasonMic2d9aa68b1ba4
diff --git a/electron/db/models/autoRunRecord.ts b/electron/db/models/autoRunRecord.tsindex 083d7094..4f0895dc 100644--- a/electron/db/models/autoRunRecord.ts+++ b/electron/db/models/autoRunRecord.ts@@ -1,12 +1,13 @@/** @Author: nevin* @Date: 2025-01-20 16:24:16- * @LastEditTime: 2025-03-18 19:44:55+ * @LastEditTime: 2025-03-18 22:13:35* @LastEditors: nevin* @Description: 自动评论 autoComment*/import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';import { TempModel } from './temp';+import { AutoRunType } from './autoRun';// 状态 进行中 失败 完成export enum AutoRunRecordStatus {@@ -15,10 +16,6 @@ export enum AutoRunRecordStatus {SUCCESS = 3, // 完成}-export enum AutoRunType {- ReplyComment = 1, // 回复评论-}-@Entity({ name: 'autoRunRecord' })export class AutoRunRecordModel extends TempModel {@PrimaryGeneratedColumn({ type: 'int', comment: 'id' })diff --git a/electron/main/autoRun/comment.ts b/electron/main/autoRun/comment.tsindex 8500f0bb..6bf376f8 100644--- a/electron/main/autoRun/comment.ts+++ b/electron/main/autoRun/comment.ts@@ -1,27 +1,7 @@/** @Author: nevin* @Date: 2025-01-21 21:12:52- * @LastEditTime: 2025-02-21 21:13:19+ * @LastEditTime: 2025-03-18 21:16:35* @LastEditors: nevin* @Description:*/-import { store } from '../../global/store';-import { IUserStore } from '@/store/user';-import { IUserInfo } from '@/api/types/user-t';-import { StoreKey } from '../../../src/utils/StroeEnum';--// 完整的响应数据接口-interface ResponseData {- state: IUserStore;- version: number;-}--export function getUserInfo(): IUserInfo {- const res: ResponseData = JSON.parse(store.get(StoreKey.User));- return res.state.userInfo!;-}--export function getUserToken() {- const res: ResponseData = JSON.parse(store.get(StoreKey.User));- return res.state.token;-}diff --git a/electron/main/autoRun/controller.ts b/electron/main/autoRun/controller.tsindex bdba5fb0..c4e7566f 100644--- a/electron/main/autoRun/controller.ts+++ b/electron/main/autoRun/controller.ts@@ -1,12 +1,14 @@/** @Author: nevin* @Date: 2025-01-20 22:02:54- * @LastEditTime: 2025-03-18 20:53:55+ * @LastEditTime: 2025-03-18 22:17:16* @LastEditors: nevin* @Description: autoRun AutoRun*/import { Controller, Icp, Inject } from '../core/decorators';import { AutoRunService } from './service';+import { AutoRunType } from '../../db/models/autoRun';+import { getUserInfo } from '../user/comment';@Controller()export class AutoRunController {@@ -17,8 +19,20 @@ export class AutoRunController {* 创建进程*/@Icp('ICP_AUTO_RUN_CREATE')- async createAutoRun(event: Electron.IpcMainInvokeEvent, data: any) {- const autoRun = await this.autoRunService.createAutoRun(data);+ async createAutoRun(+ event: Electron.IpcMainInvokeEvent,+ data: {+ accountId: number;+ type: AutoRunType;+ cycleType: string;+ },+ ) {+ const userInfo = getUserInfo();++ const autoRun = await this.autoRunService.createAutoRun({+ userId: userInfo.id,+ ...data,+ });return autoRun;}@@ -29,7 +43,6 @@ export class AutoRunController {@Icp('ICP_AUTO_RUN_LIST')async getAutoRunList(event: Electron.IpcMainInvokeEvent) {const list = await this.autoRunService.findAutoRunList({});-return list;}@@ -51,7 +64,13 @@ export class AutoRunController {* 创建进程记录*/@Icp('ICP_AUTO_RUN_RECORD_CREATE')- async createAutoRunRecord(event: Electron.IpcMainInvokeEvent, data: any) {+ async createAutoRunRecord(+ event: Electron.IpcMainInvokeEvent,+ data: {+ accountId: number;+ type: AutoRunType;+ },+ ) {const autoRunRecord = await this.autoRunService.createAutoRunRecord(data);return autoRunRecord;@@ -63,9 +82,9 @@ export class AutoRunController {@Icp('ICP_AUTO_RUN_RECORD_STATUS')async updateAutoRunRecordStatus(event: Electron.IpcMainInvokeEvent,- data: { id: number; status: number },+ id: number,+ status: number,) {- const { id, status } = data;const autoRun = await this.autoRunService.updateAutoRunRecordStatus(id,status,diff --git a/electron/main/autoRun/service.ts b/electron/main/autoRun/service.tsindex 48e4449d..b0d79c0b 100644--- a/electron/main/autoRun/service.ts+++ b/electron/main/autoRun/service.ts@@ -25,7 +25,7 @@ export class AutoRunService {}// 创建进程- async createAutoRun(data: AutoRunModel) {+ async createAutoRun(data: Partial<AutoRunModel>) {return await this.autoRunRepository.save(data);}@@ -44,7 +44,7 @@ export class AutoRunService {}// 创建进程记录- async createAutoRunRecord(data: AutoRunRecordModel) {+ async createAutoRunRecord(data: Partial<AutoRunRecordModel>) {return await this.autoRunRecordRepository.save(data);}diff --git a/electron/main/reply/comment.ts b/electron/main/reply/comment.tsindex 8500f0bb..411e3cec 100644--- a/electron/main/reply/comment.ts+++ b/electron/main/reply/comment.ts@@ -1,27 +1,7 @@/** @Author: nevin* @Date: 2025-01-21 21:12:52- * @LastEditTime: 2025-02-21 21:13:19+ * @LastEditTime: 2025-03-18 21:17:03* @LastEditors: nevin* @Description:*/-import { store } from '../../global/store';-import { IUserStore } from '@/store/user';-import { IUserInfo } from '@/api/types/user-t';-import { StoreKey } from '../../../src/utils/StroeEnum';--// 完整的响应数据接口-interface ResponseData {- state: IUserStore;- version: number;-}--export function getUserInfo(): IUserInfo {- const res: ResponseData = JSON.parse(store.get(StoreKey.User));- return res.state.userInfo!;-}--export function getUserToken() {- const res: ResponseData = JSON.parse(store.get(StoreKey.User));- return res.state.token;-}diff --git a/src/icp/autoRun.ts b/src/icp/autoRun.tsnew file mode 100644index 00000000..1a860012--- /dev/null+++ b/src/icp/autoRun.ts@@ -0,0 +1,82 @@+/*+ * @Author: nevin+ * @Date: 2025-01-23 15:48:14+ * @LastEditTime: 2025-03-18 22:23:06+ * @LastEditors: nevin+ * @Description: 自动进程+ */++export enum AutoRunType {+ ReplyComment = 1, // 回复评论+}++// 状态 进行中 暂停 删除+export enum AutoRunStatus {+ DOING = 2, // 进行中+ PAUSE = 3, // 暂停+ DELETE = 4, // 删除+}++export interface AutoRun {+ id: number;+ userId: string;+ accountId: number;+ runCount: number;+ status: AutoRunStatus;+ type: AutoRunType;+ cycleType: string;+ createTime: string;+ updateTime: string;+}++export enum AutoRunRecordStatus {+ DOING = 1, // 进行中+ FAIL = 2, // 失败+ SUCCESS = 3, // 完成+}++export interface AutoRunRecord {+ id: number;+ userId: string;+ status: AutoRunRecordStatus;+ type: AutoRunType;+ cycleType: string;+ createTime: string;+ updateTime: string;+}++/**+ * 创建自动进程+ * @param data+ */+export async function ipcCreateAutoRun(data: {+ accountId: number;+ type: AutoRunType;+ cycleType: string;+}) {+ const res: string = await window.ipcRenderer.invoke(+ 'ICP_AUTO_RUN_CREATE',+ data,+ );+ return res;+}++/**+ * 获取进程列表+ * @param data+ */+export async function ipcGetAutoRunList() {+ const res: AutoRun[] = await window.ipcRenderer.invoke('ICP_AUTO_RUN_LIST');+ return res;+}++/**+ * 获取进程列表+ * @param data+ */+export async function ipcGetAutoRunRecordList() {+ const res: AutoRunRecord[] = await window.ipcRenderer.invoke(+ 'ICP_AUTO_RUN_RECORD_LIST',+ );+ return res;+}diff --git a/src/router/index.tsx b/src/router/index.tsxindex 2685cb94..39231e45 100644--- a/src/router/index.tsx+++ b/src/router/index.tsx@@ -1,7 +1,7 @@/** @Author: nevin* @Date: 2025-02-10 22:20:15- * @LastEditTime: 2025-03-02 22:15:04+ * @LastEditTime: 2025-03-18 22:27:20* @LastEditors: nevin* @Description:*/@@ -46,6 +46,7 @@ import Finance from '@/views/finance/index';import UserWalletRecord from '@/views/finance/userWalletRecord';import Reply from '@/views/reply';import ErrorBoundary from '../components/ErrorBoundary/ErrorBoundary';+import AutoRun from '@/views/autoRun';interface IRouterMeta {// 路由名称@@ -122,6 +123,11 @@ export const router: CustomRouteObject[] = [element: <Reply />,meta: { name: '评论', icon: MessageOutlined },},+ {+ path: '/autoRun',+ element: <AutoRun />,+ meta: { name: '自动化', icon: MessageOutlined },+ },{path: '/statistics',element: <Statistics />,diff --git a/src/views/autoRun/comment.ts b/src/views/autoRun/comment.tsnew file mode 100644index 00000000..1879055d--- /dev/null+++ b/src/views/autoRun/comment.ts@@ -0,0 +1,8 @@+/*+ * @Author: nevin+ * @Date: 2025-03-18 21:08:32+ * @LastEditTime: 2025-03-18 21:21:37+ * @LastEditors: nevin+ * @Description:+ */+diff --git a/src/views/autoRun/components/addAutoRun.tsx b/src/views/autoRun/components/addAutoRun.tsxnew file mode 100644index 00000000..24a1dd20--- /dev/null+++ b/src/views/autoRun/components/addAutoRun.tsx@@ -0,0 +1,94 @@+import { AutoRunType, ipcCreateAutoRun } from '@/icp/autoRun';+import { Button, Form, Input, Modal, Select } from 'antd';+import { forwardRef, useImperativeHandle, useState } from 'react';+const { Option } = Select;++export interface AddAutoRunRef {+ init: (accountId: number) => Promise<void>;+}++interface FormData {+ // '周期类型 天 day-22 (例:每天22时) 周 week-2 (例:每周周二,周日0) 月 month-22 (例:每月22号)',+ cycleType: string;+ type: AutoRunType;+}++const Com = forwardRef<AddAutoRunRef>((props: any, ref) => {+ const [isModalOpen, setIsModalOpen] = useState(false);+ const [accountId, setAccountId] = useState<number>(0);+ const [form] = Form.useForm<FormData>();+ async function init(accountId: number) {+ setAccountId(accountId);+ setIsModalOpen(true);+ }++ useImperativeHandle(ref, () => ({+ init: init,+ }));++ function handleCancel() {+ setIsModalOpen(false);+ }++ async function onFinish(values: FormData) {+ const res = await ipcCreateAutoRun({+ accountId,+ ...values,+ });+ console.log('-------- res', res);++ console.log('Success:', values);+ }++ async function onFinishFailed(errorInfo: any) {+ console.log('Failed:', errorInfo);+ }++ return (+ <>+ <Modal+ title={null}+ open={isModalOpen}+ onCancel={handleCancel}+ footer={null}+ width={800}+ >+ <Form+ form={form}+ name="basic"+ labelCol={{ span: 8 }}+ wrapperCol={{ span: 16 }}+ initialValues={{ remember: true }}+ onFinish={onFinish}+ onFinishFailed={onFinishFailed}+ autoComplete="off"+ >+ <Form.Item+ label="重复周期类型"+ name="cycleType"+ rules={[{ required: true, message: '重复周期类型!' }]}+ >+ <p>+ 周期类型 天 day-22 例:每天22时 周 week-2 例:每周周二,周日0 月+ month-22 例:每月22号+ </p>+ <Input />+ </Form.Item>++ <Form.Item name="gender" label="类型" rules={[{ required: true }]}>+ <Select placeholder="选择任务类型" allowClear>+ <Option value={AutoRunType.ReplyComment}>自动回复评论</Option>+ </Select>+ </Form.Item>++ <Form.Item wrapperCol={{ offset: 8, span: 16 }}>+ <Button type="primary" htmlType="submit">+ 提交+ </Button>+ </Form.Item>+ </Form>+ </Modal>+ </>+ );+});+export default Com;diff --git a/src/views/autoRun/index.tsx b/src/views/autoRun/index.tsxnew file mode 100644index 00000000..a7ae81e0--- /dev/null+++ b/src/views/autoRun/index.tsx@@ -0,0 +1,114 @@+/*+ * @Author: nevin+ * @Date: 2025-02-10 22:20:15+ * @LastEditTime: 2025-03-18 22:25:37+ * @LastEditors: nevin+ * @Description: 评论页面 reply+ */+import { Button, Card, Col, Row } from 'antd';+import { useCallback, useRef, useState } from 'react';+import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';+import styles from './reply.module.scss';+import AddAutoRun, { AddAutoRunRef } from './components/addAutoRun';+import {+ AutoRun,+ AutoRunRecord,+ ipcGetAutoRunList,+ ipcGetAutoRunRecordList,+} from '@/icp/autoRun';++export default function Page() {+ const [autoRunList, setAutoRunList] = useState<AutoRun[]>([]);+ const [autoRunRecordList, setAutoRunRecordList] = useState<AutoRunRecord[]>(+ [],+ );+ const [activeAccountId, setActiveAccountId] = useState<number>(-1);++ const Ref_AddAutoRun = useRef<AddAutoRunRef>(null);++ async function getAutoRunList() {+ if (activeAccountId === -1) return;+ setAutoRunList([]);+ const res = await ipcGetAutoRunList();+ setAutoRunList(res);+ }++ async function getAutoRunRecordList() {+ setAutoRunRecordList([]);+ const res = await ipcGetAutoRunRecordList();+ setAutoRunRecordList(res);+ }++ /**+ * 运行+ */+ async function runAutoRun(data: AutoRun) {+ // const res = await icpCreateCommentList(activeAccountId, data.dataId);+ // console.log('------ res', res);+ }++ /**+ * 打开评论回复+ * @param data+ */+ function openAddAutoRun() {+ Ref_AddAutoRun.current?.init(activeAccountId);+ }++ return (+ <div className={styles.reply}>+ <Button+ type="primary"+ onClick={() => {+ openAddAutoRun();+ }}+ >+ 创建自动化+ </Button>+ <Row>+ <Col span={4}>+ <AccountSidebar+ activeAccountId={activeAccountId}+ onAccountChange={useCallback(+ (info) => {+ setActiveAccountId(info.id);+ getAutoRunList();+ },+ [getAutoRunList],+ )}+ />+ </Col>+ <Col span={10}>+ <div>+ {autoRunList.map((item) => (+ <Card+ key={item.id}+ style={{ width: 300 }}+ actions={[+ <Button type="primary" onClick={() => runAutoRun(item)}>+ 执行+ </Button>,+ <Button type="primary">删除</Button>,+ <Button type="primary" onClick={() => getAutoRunRecordList()}>+ 查看记录+ </Button>,+ ]}+ ></Card>+ ))}+ </div>+ </Col>+ <Col span={10}>+ <div>+ {autoRunRecordList.map((item) => (+ <Card key={item.id} style={{ width: 300 }}>+ {item.cycleType}+ </Card>+ ))}+ </div>+ </Col>+ </Row>++ <AddAutoRun ref={Ref_AddAutoRun} />+ </div>+ );+}diff --git a/src/views/autoRun/reply.module.scss b/src/views/autoRun/reply.module.scssnew file mode 100644index 00000000..be859e55--- /dev/null+++ b/src/views/autoRun/reply.module.scss@@ -0,0 +1,5 @@+.reply {+ height: 100%;+ :global {+ }+}\ No newline at end of file