From a69bf92c8907eb1fed227afb156ff0e1c5821c24 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期日, 19 十月 2025 16:16:12 +0800
Subject: [PATCH] fix: bug
---
apps/bMiniApp/src/stores/modules/user.ts | 140 +++++++++++++++++++---------------------------
1 files changed, 59 insertions(+), 81 deletions(-)
diff --git a/apps/bMiniApp/src/stores/modules/user.ts b/apps/bMiniApp/src/stores/modules/user.ts
index 9425112..58c2255 100644
--- a/apps/bMiniApp/src/stores/modules/user.ts
+++ b/apps/bMiniApp/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,17 +19,19 @@
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>;
+ userDetail?: Nullable<API.GetEnterpriseLoginInfoQueryResult>;
firstGetUserDetail?: boolean;
locationCity?: string;
@@ -80,21 +77,16 @@
};
},
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;
},
accountInfo(): Partial<AccountInfo> {
return getAccountInfoFromAccessToken(this.userInfo?.accessToken);
+ },
+
+ userId: (state) => {
+ return state.userDetail?.id;
},
// matchMakingIdentity(state): MatchMakingIdentityEnum {
@@ -105,19 +97,18 @@
// 鎵嬫満鍙锋巿鏉僀ode鐧诲綍
async getTokenByPhone(
detail: ButtonProps.onGetPhoneNumberEventDetail,
- wxMiniAppUserLoginRes: any
+ wxMiniAppUserLoginRes: API.LoginCommandCallback
) {
try {
- let res: API.IdentityModelTokenCacheItem;
- if (!wxMiniAppUserLoginRes.accessToken) {
- let params: API.WxMiniAppPhoneLoginInput = {
- openId: wxMiniAppUserLoginRes.openId,
- sessionKey: wxMiniAppUserLoginRes.sessionKey,
+ let res: API.LoginCommandCallback = wxMiniAppUserLoginRes;
+ if (!wxMiniAppUserLoginRes?.isBindPhoneNumber) {
+ let bindRes = await authServices.bindWxmpUserInfo({
encryptedData: detail.encryptedData,
iv: detail.iv,
- wxMiniApp: WxMiniAppEnum.浜哄崟鍚堜竴,
- };
- res = await accountServices.wxMiniAppPhoneAuthLogin(params);
+ sessionKey: wxMiniAppUserLoginRes.sessionKey,
+ accessToken: wxMiniAppUserLoginRes.accessToken,
+ });
+ res.accessToken = bindRes.accessToken;
this.loginSuccess(res);
}
return res;
@@ -127,11 +118,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 +136,14 @@
},
// 鐢ㄦ埛璐﹀彿瀵嗙爜鐧诲叆
- 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: params.password,
+ // password: md5Encrypt(params.password),
+ type: AppLocalConfig.userType,
+ clientType: AppLocalConfig.clientType,
},
{ showLoading: false }
);
@@ -166,15 +162,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,30 +178,30 @@
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 });
+ let res = await authServices.getEnterpriseLoginInfo({}, { showLoading: false });
if (res) {
- res.frontStatus = getUserCertificationFrontStatusAdapter(
- res.userCertificationStatus,
- res.userCertificationAuditStatus
- );
- res.originalAvatarUrl = res.avatarUrl;
- res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
+ // res.frontStatus = getUserCertificationFrontStatusAdapter(
+ // res.userCertificationStatus,
+ // res.userCertificationAuditStatus
+ // );
+ res.originalAvatar = res.avatar;
+ res.avatar = res.avatar ? setOSSLink(res.avatar) : DefaultAvatar;
this.setUserDetail(res);
this.firstGetUserDetail = false;
}
@@ -222,7 +218,7 @@
setUserInfo(info);
},
- setUserDetail(detail: API.UserInfoV2) {
+ setUserDetail(detail: API.GetEnterpriseLoginInfoQueryResult) {
this.userDetail = detail;
setUserDetail(detail);
},
@@ -234,7 +230,6 @@
this.userDetail = null;
removeUserInfo();
removeUserDetail();
- removeMatchMakingIdentity();
},
/**
@@ -242,7 +237,7 @@
*/
logout() {
this.resetState();
- myClient.removeQueries();
+ // myClient.removeQueries();
goAuthorization();
},
@@ -268,23 +263,6 @@
Taro.redirectTo({
url: `/packageLogin/authLogin/index`,
});
- }
- },
-
- 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');
}
},
--
Gitblit v1.9.1