From d6ae9eb36186a924800d7e0433c3eb35c5ccb6f7 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 11 八月 2025 15:10:15 +0800
Subject: [PATCH] fix: 修改登录

---
 apps/cMiniApp/src/stores/modules/user.ts |  158 ++++++++++++++++++++++------------------------------
 1 files changed, 66 insertions(+), 92 deletions(-)

diff --git a/apps/cMiniApp/src/stores/modules/user.ts b/apps/cMiniApp/src/stores/modules/user.ts
index 7e52ace..39b8df7 100644
--- a/apps/cMiniApp/src/stores/modules/user.ts
+++ b/apps/cMiniApp/src/stores/modules/user.ts
@@ -8,12 +8,7 @@
   setUserDetail,
   getUserDetail,
   removeUserDetail,
-  removeMatchMakingIdentity,
-  getMatchMakingIdentity,
-  setMatchMakingIdentity,
 } from '@/utils/storage/auth';
-import * as accountServices from '@12333/services/api/Account';
-import * as userServices from '@12333/services/api/User';
 import Taro, { useRouter } from '@tarojs/taro';
 import { ButtonProps } from '@tarojs/components';
 import { debounce } from 'lodash';
@@ -24,14 +19,16 @@
   setOSSLink,
   getUserCertificationFrontStatusAdapter,
   LocationUtils,
+  md5Encrypt,
 } from '@12333/utils';
 import DefaultAvatar from '@/assets/components/icon-default-avatar.png';
-import { WxMiniAppEnum } from '@12333/constants';
 import { myClient } from '@/constants/query';
 import { globalEventEmitter } from '@12333/hooks';
+import * as authServices from '@12333/services/apiV2/auth';
+import { AppLocalConfig } from '@/constants';
 
 interface UserState {
-  userInfo?: Nullable<API.IdentityModelTokenCacheItem>;
+  userInfo?: Nullable<API.LoginCommandCallback>;
   token?: Nullable<string>;
   refreshToken?: Nullable<string>;
   userDetail?: Nullable<API.UserInfoV2>;
@@ -80,15 +77,6 @@
     };
   },
   getters: {
-    cacheToken: (state) => {
-      if (!state.token) {
-        const storageToken = getCacheToken() as API.IdentityModelTokenCacheItem;
-
-        state.token = storageToken.accessToken;
-      }
-      return state.token || null;
-    },
-
     cacheRefreshToken: (state) => {
       return state.refreshToken;
     },
@@ -97,9 +85,9 @@
       return getAccountInfoFromAccessToken(this.userInfo?.accessToken);
     },
 
-    // matchMakingIdentity(state): MatchMakingIdentityEnum {
-
-    // },
+    userId: (state) => {
+      return state.userInfo?.id ?? '';
+    },
   },
   actions: {
     // 鎵嬫満鍙锋巿鏉僀ode鐧诲綍
@@ -115,7 +103,7 @@
             sessionKey: wxMiniAppUserLoginRes.sessionKey,
             encryptedData: detail.encryptedData,
             iv: detail.iv,
-            wxMiniApp: WxMiniAppEnum.浜哄崟鍚堜竴,
+            wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
           };
           res = await accountServices.wxMiniAppPhoneAuthLogin(params);
           this.loginSuccess(res);
@@ -127,11 +115,13 @@
     },
 
     // 鐢ㄦ埛鎵嬫満楠岃瘉鐮佺櫥鍏�
-    async loginByUsername(data: API.PhoneMesssageCodeLoginInput) {
-      let res = await accountServices.phoneMesssageCodeLogin(
+    async loginByUsername(data: API.SmsLoginCommand) {
+      let res = await authServices.smsLogin(
         {
           phoneNumber: data.phoneNumber,
-          code: data.code,
+          verifyCode: data.verifyCode,
+          type: AppLocalConfig.userType,
+          clientType: AppLocalConfig.clientType,
         },
         { showLoading: false }
       );
@@ -143,11 +133,13 @@
     },
 
     // 鐢ㄦ埛璐﹀彿瀵嗙爜鐧诲叆
-    async loginByPassword(data: API.AccessRequestDto) {
-      let res = await accountServices.passwordLogin(
+    async loginByPassword(params: API.PasswordLoginCommand) {
+      let res = await authServices.passwordLogin(
         {
-          loginName: data.userName,
-          password: data.userPassword,
+          userName: params.userName,
+          password: md5Encrypt(params.password),
+          type: AppLocalConfig.userType,
+          clientType: AppLocalConfig.clientType,
         },
         { showLoading: false }
       );
@@ -157,7 +149,7 @@
       return res;
     },
 
-    async loginSuccess(res: API.IdentityModelTokenCacheItem) {
+    async loginSuccess(res: API.LoginCommandCallback) {
       try {
         this.setUserInfoAction(res);
         this.setTokenAction(res);
@@ -166,15 +158,15 @@
     },
 
     async wxMiniAppUserLoginFromScan(wxIndentityRes: API.WxMiniAppIndentityInfo, uuid: string) {
-      try {
-        let res = await accountServices.wxMiniAppUserLoginFromScan({
-          uId: uuid,
-          userName: wxIndentityRes.userName,
-          openId: wxIndentityRes.openId,
-        });
-        this.loginSuccess(res);
-        return res;
-      } catch (error) {}
+      // try {
+      //   let res = await accountServices.wxMiniAppUserLoginFromScan({
+      //     uId: uuid,
+      //     userName: wxIndentityRes.userName,
+      //     openId: wxIndentityRes.openId,
+      //   });
+      //   this.loginSuccess(res);
+      //   return res;
+      // } catch (error) {}
     },
 
     async wxMiniAppPhoneAuthLoginFromScan(
@@ -182,44 +174,47 @@
       wxIndentityRes: API.WxMiniAppIndentityInfo,
       uuid: string
     ) {
-      try {
-        let res = await accountServices.wxMiniAppPhoneAuthLoginFromScan({
-          uId: uuid,
-          openId: wxIndentityRes.openId,
-          sessionKey: wxIndentityRes.sessionKey,
-          encryptedData: detail.encryptedData,
-          iv: detail.iv,
-          wxMiniApp: WxMiniAppEnum.浜哄崟鍚堜竴,
-        });
-        this.loginSuccess(res);
-        return res;
-      } catch (error) {}
+      // try {
+      //   let res = await accountServices.wxMiniAppPhoneAuthLoginFromScan({
+      //     uId: uuid,
+      //     openId: wxIndentityRes.openId,
+      //     sessionKey: wxIndentityRes.sessionKey,
+      //     encryptedData: detail.encryptedData,
+      //     iv: detail.iv,
+      //     wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
+      //   });
+      //   this.loginSuccess(res);
+      //   return res;
+      // } catch (error) {}
     },
 
     async getCurrentUserInfo() {
-      try {
-        let res = await userServices.getUserInfo({ showLoading: false });
-        if (res) {
-          res.frontStatus = getUserCertificationFrontStatusAdapter(
-            res.userCertificationStatus,
-            res.userCertificationAuditStatus
-          );
-          res.originalAvatarUrl = res.avatarUrl;
-          res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
-          this.setUserDetail(res);
-          this.firstGetUserDetail = false;
-        }
-      } catch (error) {}
+      // try {
+      //   let res = await userServices.getUserInfo({ showLoading: false });
+      //   if (res) {
+      //     res.frontStatus = getUserCertificationFrontStatusAdapter(
+      //       res.userCertificationStatus,
+      //       res.userCertificationAuditStatus
+      //     );
+      //     res.originalAvatarUrl = res.avatarUrl;
+      //     res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
+      //     this.setUserDetail(res);
+      //     this.firstGetUserDetail = false;
+      //   }
+      // } catch (error) {}
     },
 
-    setTokenAction(tokenInfo: API.IdentityModelTokenCacheItem) {
+    setTokenAction(tokenInfo: API.LoginCommandCallback) {
       this.token = tokenInfo?.accessToken;
       this.refreshToken = tokenInfo.refreshToken ?? '';
     },
 
-    setUserInfoAction(info: API.IdentityModelTokenCacheItem) {
-      this.userInfo = info;
-      setUserInfo(info);
+    setUserInfoAction(info: API.LoginCommandCallback) {
+      this.userInfo = {
+        ...this.userInfo,
+        ...info,
+      };
+      setUserInfo(this.userInfo);
     },
 
     setUserDetail(detail: API.UserInfoV2) {
@@ -234,7 +229,6 @@
       this.userDetail = null;
       removeUserInfo();
       removeUserDetail();
-      removeMatchMakingIdentity();
     },
 
     /**
@@ -271,36 +265,16 @@
       }
     },
 
-    async getTokenByRefreshToken(params: API.AccessRefreshToken) {
-      try {
-        const res = await accountServices.getTokenByRefreshToken(params, {
-          showLoading: false,
-        });
-        if (res) {
-          this.setTokenAction(res);
-          this.setUserInfoAction(res);
-          return res;
-        } else {
-          throw new Error('鍒锋柊token澶辫触');
-        }
-      } catch (error) {
-        throw new Error('error');
-      }
-    },
-
     setLocationCity(cityName: string, provinceName: string) {
       this.locationCity = cityName;
       this.locationProvince = provinceName;
       this.firstSetLocation = false;
       setStorageLocationCity({ city: cityName, province: provinceName });
-      if (LocationUtils.isProvinceChange(provinceName)) {
-        this.resetState();
-        myClient.removeQueries();
-        globalEventEmitter.trigger('logout/refresh');
-        // myClient.invalidateQueries({
-        //   queryKey: ['logout/refresh'],
-        // });
-      }
+      // if (LocationUtils.isProvinceChange(provinceName)) {
+      //   this.resetState();
+      //   myClient.removeQueries();
+      //   globalEventEmitter.trigger('logout/refresh');
+      // }
       LocationUtils.currentProvinceName = provinceName;
     },
   },

--
Gitblit v1.9.1