Skip to content

Let's use AI to Earn!

feat: 前端处理用户组

gaoSira94268bc967d
diff --git a/src/store/account.ts b/src/store/account.ts
index fb29b029..acb1cadf 100644
--- a/src/store/account.ts
+++ b/src/store/account.ts
@@ -2,17 +2,26 @@ import { create } from 'zustand';
import { combine } from 'zustand/middleware';
import lodash from 'lodash';
import { AccountInfo } from '../views/account/comment';
-import { icpGetAccountList } from '../icp/account';
+import { icpGetAccountGroup, icpGetAccountList } from '../icp/account';
import { onAccountLoginFinish } from '../icp/receiveMsg';
+import { AccountGroupModel } from '../../electron/db/models/accountGroup';
+
+export interface AccountGroupItem extends AccountGroupModel {
+ children: AccountInfo[];
+}
export interface IAccountStore {
accountList: AccountInfo[];
accountMap: Map<number, AccountInfo>;
unBindFn?: () => void;
+ accountGroupList: AccountGroupItem[];
}
const store: IAccountStore = {
+ // 不分组的账户数据
accountList: [],
+ // 分组的账户数据
+ accountGroupList: [],
accountMap: new Map([]),
unBindFn: undefined,
};
@@ -49,6 +58,30 @@ export const useAccountStore = create(
accountList: result,
accountMap,
});
+ await methods.getAccountGroup();
+ },
+
+ // 获取用户组的数据并且将用户放到对应组下
+ async getAccountGroup() {
+ const groupList = await icpGetAccountGroup();
+ if (groupList.length === 0) return;
+ const accountGroupList: AccountGroupItem[] = [];
+ // key=组ID,val=账户ID
+ const accountGroupMap = new Map<number, AccountGroupItem>();
+ groupList.map((v) => {
+ const accountGroupItem = {
+ ...v,
+ children: [],
+ };
+ accountGroupList.push(accountGroupItem);
+ accountGroupMap.set(v.id, accountGroupItem);
+ });
+ get().accountList.map((v) => {
+ accountGroupMap.get(v.groupId!)!.children.push(v);
+ });
+ set({
+ accountGroupList,
+ });
},
async init() {
diff --git a/src/store/user.ts b/src/store/user.ts
index b59f0969..dce9566d 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -36,6 +36,7 @@ export const useUserStore = createPersistStore(
// 退出登录
logout() {
+ console.log('登出!');
this.clearLoginStatus();
if (window.location.href !== 'login') {
router.navigate('/login');
@@ -49,7 +50,6 @@ export const useUserStore = createPersistStore(
return;
}
const res = await userApi.getUserInfo();
- console.log('user:', res);
if (!res) return;
set({ userInfo: res });
return res;