返回 AiToEarn
account.ts
根目录 / project / aitoearn-electron / src / icp / account.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-23 15:48:14
4 * @LastEditTime: 2025-02-21 11:47:00
5 * @LastEditors: nevin
6 * @Description:
7 */
8
9 import { AccountInfo } from '@/views/account/comment';
10 import { AccountStatus, PlatType } from '@@/AccountEnum';
11 import { DashboardData } from '@/views/statistics/comment';
12 import { AccountGroupModel } from '../../electron/db/models/accountGroup';
13
14 export type AccountGroup = AccountGroupModel;
15
16 // 更新账户状态
17 export async function ipcUpdateAccountStatus(
18 accountId: number,
19 status: AccountStatus,
20 ) {
21 return await window.ipcRenderer.invoke(
22 'ICP_ACCOUNT_UPDATE_STATUS',
23 accountId,
24 status,
25 );
26 }
27
28 /**
29 * 账户登录状态检测
30 * @param pType
31 * @param uid
32 * @param isSendEvent 是否发送账户更新的事件
33 */
34 export async function acpAccountLoginCheck(
35 pType: PlatType,
36 uid: string,
37 isSendEvent: boolean = true,
38 ) {
39 const res: AccountInfo = await window.ipcRenderer.invoke(
40 'ICP_ACCOUNT_LOGIN_CHECK',
41 pType,
42 uid,
43 isSendEvent,
44 );
45 return res;
46 }
47 // 账户登录状态检测,多个账号
48 export async function acpAccountLoginCheckMulti(
49 checkAccounts: {
50 pType: PlatType;
51 uid: string;
52 }[],
53 ) {
54 const res: AccountInfo[] = await window.ipcRenderer.invoke(
55 'ICP_ACCOUNT_LOGIN_CHECK_MULTI',
56 checkAccounts,
57 );
58 return res;
59 }
60
61 /**
62 * 登录账户
63 * @param pType
64 * @returns
65 */
66 export async function accountLogin(pType: PlatType) {
67 const res: AccountInfo = await window.ipcRenderer.invoke(
68 'ICP_ACCOUNT_LOGIN',
69 pType,
70 );
71 return res;
72 }
73
74 // 获取账户信息
75 export async function icpGetAccountInfo(type: PlatType, uid: string) {
76 const res: AccountInfo = await window.ipcRenderer.invoke(
77 'ICP_ACCOUNT_GET_INFO',
78 type,
79 uid,
80 );
81 return res;
82 }
83
84 // 获取我的账户列表
85 export async function icpGetAccountList() {
86 try {
87 const res: AccountInfo[] = await window.ipcRenderer.invoke(
88 'ICP_ACCOUNT_GET_LIST',
89 );
90 return res;
91 } catch (error) {
92 console.error('获取账户列表失败', error);
93 }
94 }
95
96 // 获取我的账户列表(ids)
97 export async function icpGetAccountListByIds(ids: number[]) {
98 try {
99 const res: AccountInfo[] = await window.ipcRenderer.invoke(
100 'ICP_ACCOUNT_GET_LIST_BY_IDS',
101 ids,
102 );
103 return res;
104 } catch (error) {
105 console.error('获取账户列表失败', error);
106 }
107 }
108
109 // 获取账户数量
110 export async function icpGetAccountCount() {
111 const res: number = await window.ipcRenderer.invoke('ICP_ACCOUNT_GET_COUNT');
112 return res;
113 }
114
115 // 获取账户统计
116 export async function icpGetAccountStatistics() {
117 const res = await window.ipcRenderer.invoke('ICP_ACCOUNT_STATISTICS');
118 return res;
119 }
120
121 // 获取账户统计
122 export async function icpGetAccountDashboard(id: number, time?: any) {
123 const res: DashboardData[] = await window.ipcRenderer.invoke(
124 'ICP_ACCOUNT_DASHBOARD',
125 id,
126 time,
127 );
128 return res;
129 }
130
131 // 删除多个账户
132 export async function icpDeleteAccounts(ids: number[]) {
133 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_DELETE', ids);
134 }
135
136 // 添加用户组数据
137 export async function icpAddAccountGroup(data: Partial<AccountGroup>) {
138 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_ADD', data);
139 }
140 // 获取用户组数据
141 export async function icpGetAccountGroup(): Promise<AccountGroup[]> {
142 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_GET');
143 }
144 // 删除用户组数据
145 export async function icpDeleteAccountGroup(id: number) {
146 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_DELETE', id);
147 }
148 // 编辑用户组数据
149 export async function icpEditDeleteAccountGroup(data: Partial<AccountGroup>) {
150 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_EDIT', data);
151 }
152 // 修改账户的账户组
153 export async function icpAccountEditGroup(id: number, groupId: number) {
154 return await window.ipcRenderer.invoke(
155 'ICP_ACCOUNTS_EDIT_GROUP',
156 id,
157 groupId,
158 );
159 }
160
161 // 代理地址有效性检测
162 export async function icpProxyCheck(proxy: string) {
163 return await window.ipcRenderer.invoke('ICP_ACCOUNTS_PROXY_CHECK', proxy);
164 }
165
165 lines TYPESCRIPT