From dd0a3e0ed394983c4fbacdab64cad6f8de5b4884 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期三, 06 八月 2025 18:03:56 +0800
Subject: [PATCH] fix: 对接字典

---
 apps/cMiniApp/src/stores/modules/user.ts |  130 +++++++++---------------------------------
 1 files changed, 29 insertions(+), 101 deletions(-)

diff --git a/apps/cMiniApp/src/stores/modules/user.ts b/apps/cMiniApp/src/stores/modules/user.ts
index 43f3e84..20364b5 100644
--- a/apps/cMiniApp/src/stores/modules/user.ts
+++ b/apps/cMiniApp/src/stores/modules/user.ts
@@ -8,9 +8,6 @@
   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';
@@ -24,21 +21,21 @@
   setOSSLink,
   getUserCertificationFrontStatusAdapter,
   LocationUtils,
+  md5Encrypt,
 } from '@12333/utils';
 import DefaultAvatar from '@/assets/components/icon-default-avatar.png';
-import { MatchMakingIdentityEnum, WxMiniAppEnum } from '@12333/constants';
+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.PasswordLoginCommandCallback>;
   token?: Nullable<string>;
   refreshToken?: Nullable<string>;
   userDetail?: Nullable<API.UserInfoV2>;
   firstGetUserDetail?: boolean;
-  matchMakingIdentity?: MatchMakingIdentityEnum;
-  /**鏄惁鏈夎缃繃韬唤 */
-  isSetMatchMakingIdentity?: boolean;
 
   locationCity?: string;
   locationProvince?: string;
@@ -61,18 +58,6 @@
   }
 );
 
-function initMatchMakingIdentity(userDetail: API.UserInfoV2): MatchMakingIdentityEnum {
-  if (!userDetail) {
-    const cacheMatchMakingIdentity = getMatchMakingIdentity();
-    return cacheMatchMakingIdentity
-      ? cacheMatchMakingIdentity
-      : MatchMakingIdentityEnum.Contributors;
-  } else if (!userDetail?.matchMakingIdentity) {
-    return MatchMakingIdentityEnum.Contributors;
-  }
-  return userDetail?.matchMakingIdentity;
-}
-
 export const useUserStore = defineStore({
   id: 'app-user',
   state: (): UserState => {
@@ -89,25 +74,12 @@
       refreshToken: userInfo?.refreshToken ?? '',
       userDetail: userDetail,
       firstGetUserDetail: true,
-      matchMakingIdentity: initMatchMakingIdentity(userDetail),
-      isSetMatchMakingIdentity: userDetail
-        ? !!userDetail.matchMakingIdentity || !!getMatchMakingIdentity()
-        : !!getMatchMakingIdentity(),
       locationCity: storageLocation?.city ?? '鍖椾含甯�',
       locationProvince: storageLocation?.province ?? '鍖椾含',
       firstSetLocation: true,
     };
   },
   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;
     },
@@ -115,10 +87,6 @@
     accountInfo(): Partial<AccountInfo> {
       return getAccountInfoFromAccessToken(this.userInfo?.accessToken);
     },
-
-    // matchMakingIdentity(state): MatchMakingIdentityEnum {
-
-    // },
   },
   actions: {
     // 鎵嬫満鍙锋巿鏉僀ode鐧诲綍
@@ -134,7 +102,7 @@
             sessionKey: wxMiniAppUserLoginRes.sessionKey,
             encryptedData: detail.encryptedData,
             iv: detail.iv,
-            wxMiniApp: WxMiniAppEnum.浜哄崟鍚堜竴,
+            wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
           };
           res = await accountServices.wxMiniAppPhoneAuthLogin(params);
           this.loginSuccess(res);
@@ -162,11 +130,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 }
       );
@@ -176,7 +146,7 @@
       return res;
     },
 
-    async loginSuccess(res: API.IdentityModelTokenCacheItem) {
+    async loginSuccess(res: API.PasswordLoginCommandCallback) {
       try {
         this.setUserInfoAction(res);
         this.setTokenAction(res);
@@ -208,7 +178,7 @@
           sessionKey: wxIndentityRes.sessionKey,
           encryptedData: detail.encryptedData,
           iv: detail.iv,
-          wxMiniApp: WxMiniAppEnum.浜哄崟鍚堜竴,
+          wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
         });
         this.loginSuccess(res);
         return res;
@@ -219,26 +189,24 @@
       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;
-          this.matchMakingIdentity = initMatchMakingIdentity(res);
-          this.isSetMatchMakingIdentity = true;
+          // 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.PasswordLoginCommandCallback) {
       this.token = tokenInfo?.accessToken;
       this.refreshToken = tokenInfo.refreshToken ?? '';
     },
 
-    setUserInfoAction(info: API.IdentityModelTokenCacheItem) {
+    setUserInfoAction(info: API.PasswordLoginCommandCallback) {
       this.userInfo = info;
       setUserInfo(info);
     },
@@ -255,7 +223,6 @@
       this.userDetail = null;
       removeUserInfo();
       removeUserDetail();
-      removeMatchMakingIdentity();
     },
 
     /**
@@ -292,55 +259,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');
-      }
-    },
-
-    async setMatchMakingIdentity(params: API.SetMatchMakingIdentityInput) {
-      try {
-        let res = 1;
-        if (this.userDetail) {
-          res = await userServices.setMatchMakingIdentity(params);
-        }
-        if (res) {
-          if (!this.userDetail) {
-            setMatchMakingIdentity(params.matchMakingIdentity);
-          }
-          this.matchMakingIdentity = params.matchMakingIdentity;
-          this.isSetMatchMakingIdentity = true;
-          return res;
-        }
-      } 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