From 675e9d9e998412c0777427d36124e340463bb56f Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 05 八月 2025 14:32:27 +0800
Subject: [PATCH] fix: 修改功能模块

---
 src/store/modules/user.ts |  121 +++++++++++++++++++---------------------
 1 files changed, 57 insertions(+), 64 deletions(-)

diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index 4cf1068..85c8aae 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -1,31 +1,32 @@
 import { defineStore } from 'pinia';
 import { store } from '@/store';
-import { getToken, setToken, removeToken, removeUserInfo, setUserInfo, getUserInfo } from '@/utils';
+import {
+  getToken,
+  setToken,
+  removeToken,
+  removeUserInfo,
+  setUserInfo,
+  getUserInfo,
+  md5Encrypt,
+} from '@/utils';
 import { resetRouter, router } from '@/router';
 import { useTagsViewStoreHook } from './tagsView';
-import * as accountServices from '@/services/api/Account';
-import * as userServices from '@/services/api/User';
 import { usePermissionStoreHook } from './permission';
-import { getAccountInfoFromAccessToken, AccountInfo } from '@bole-core/core';
 import { useClearSubModule } from '@/hooks';
 import { myClient } from '@/constants/query';
+import * as authServices from '@/services/api/auth';
 
 export interface UserState {
   token: string;
-  userInfo: API.IdentityModelTokenCacheItem;
-  accountInfo: Partial<AccountInfo>;
-  name: string;
+  userInfo: API.PasswordLoginCommandCallback;
 }
 
 function getDefaultState() {
   const accessToken = getToken();
   const userInfo = getUserInfo();
-  const accountInfo = getAccountInfoFromAccessToken(accessToken);
 
   return {
     token: accessToken,
-    name: accountInfo.name,
-    accountInfo: accountInfo || {},
     userInfo: userInfo || {},
   } as UserState;
 }
@@ -41,51 +42,37 @@
       return state.userInfo;
     },
 
-    userId(state) {
-      return state.accountInfo.sub;
-    },
+    // userId(state) {
+    //   return state.accountInfo.sub;
+    // },
   },
   actions: {
     setToken(token: string) {
       this.token = token;
       setToken(token);
     },
-    setName(name: string) {
-      this.name = name;
-    },
-    setUserInfo(userInfo: API.IdentityModelTokenCacheItem) {
+    setUserInfo(userInfo: API.PasswordLoginCommandCallback) {
       this.userInfo = userInfo;
       setUserInfo(userInfo);
     },
-    setAccountInfo(accountInfo: Partial<AccountInfo>) {
-      this.accountInfo = accountInfo;
-    },
 
     // 鐢ㄦ埛鐧诲叆
-    loginByUsername(data: API.AccessRequestDto) {
-      return new Promise<void>((resolve, reject) => {
-        userServices
-          .getTokenForWeb(data, { showLoading: false })
-          .then((res) => {
-            if (res) {
-              console.log('res: ', res);
-              this.setToken(res.accessToken);
-
-              const accountInfo = getAccountInfoFromAccessToken(res.accessToken);
-
-              this.setName(accountInfo.name);
-              this.setAccountInfo(accountInfo);
-
-              // 鑾峰彇鐢ㄦ埛淇℃伅
-              this.setUserInfo(res);
-
-              resolve();
-            }
-          })
-          .catch((error) => {
-            reject(error);
-          });
-      });
+    async loginByUsername(params: API.PasswordLoginCommand) {
+      let res = await authServices.passwordLogin(
+        {
+          ...params,
+          password: md5Encrypt(params.password),
+          type: EnumUserType.Operation,
+          clientType: EnumClientType.PcWeb,
+        },
+        {
+          showLoading: false,
+        }
+      );
+      if (res) {
+        this.setToken(res.accessToken);
+        this.setUserInfo(res);
+      }
     },
 
     // 鐧诲嚭 娓呯┖缂撳瓨
@@ -120,26 +107,32 @@
       Object.assign(this, getDefaultState());
     },
 
-    refreshToken(params: API.AccessRefreshToken) {
-      return new Promise<API.IdentityModelTokenCacheItem>(
-        // eslint-disable-next-line no-async-promise-executor
-        async (resolve, reject) => {
-          try {
-            const res = await accountServices.getTokenByRefreshToken(params, {
-              showLoading: false,
-            });
-            if (res) {
-              this.setToken(res.accessToken);
-              this.setUserInfo(res);
-              resolve(res);
-              return;
-            }
-            reject('鍑洪敊浜�');
-          } catch (error) {
-            reject(error);
-          }
-        }
-      );
+    async refreshToken(params: any) {
+      return Promise.resolve({
+        accessToken: '1222',
+        expiresIn: 1000 * 60 * 24 * 60,
+        creationTime: '2025-08-04 00:00:00',
+        refreshToken: '1222',
+      });
+      // return new Promise<API.IdentityModelTokenCacheItem>(
+      //   // eslint-disable-next-line no-async-promise-executor
+      //   async (resolve, reject) => {
+      //     try {
+      //       const res = await accountServices.getTokenByRefreshToken(params, {
+      //         showLoading: false,
+      //       });
+      //       if (res) {
+      //         this.setToken(res.accessToken);
+      //         this.setUserInfo(res);
+      //         resolve(res);
+      //         return;
+      //       }
+      //       reject('鍑洪敊浜�');
+      //     } catch (error) {
+      //       reject(error);
+      //     }
+      //   }
+      // );
     },
   },
 });

--
Gitblit v1.9.1