From c2463c02a17f92df55ec77ed2da3fb724290c072 Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期一, 20 十月 2025 17:34:30 +0800
Subject: [PATCH] fix: bug
---
apps/cMiniApp/src/stores/modules/user.ts | 114 +++++++++++++++++++++++++++++++-------------------------
1 files changed, 63 insertions(+), 51 deletions(-)
diff --git a/apps/cMiniApp/src/stores/modules/user.ts b/apps/cMiniApp/src/stores/modules/user.ts
index 20364b5..cf8e0bf 100644
--- a/apps/cMiniApp/src/stores/modules/user.ts
+++ b/apps/cMiniApp/src/stores/modules/user.ts
@@ -9,8 +9,6 @@
getUserDetail,
removeUserDetail,
} 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,18 +22,18 @@
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.PasswordLoginCommandCallback>;
+ userInfo?: Nullable<API.LoginCommandCallback>;
token?: Nullable<string>;
refreshToken?: Nullable<string>;
- userDetail?: Nullable<API.UserInfoV2>;
+ userDetail?: Nullable<API.GetPersonalLoginInfoQueryResult>;
firstGetUserDetail?: boolean;
+ firstLaunch?: boolean;
locationCity?: string;
locationProvince?: string;
@@ -74,6 +72,7 @@
refreshToken: userInfo?.refreshToken ?? '',
userDetail: userDetail,
firstGetUserDetail: true,
+ firstLaunch: true,
locationCity: storageLocation?.city ?? '鍖椾含甯�',
locationProvince: storageLocation?.province ?? '鍖椾含',
firstSetLocation: true,
@@ -87,24 +86,27 @@
accountInfo(): Partial<AccountInfo> {
return getAccountInfoFromAccessToken(this.userInfo?.accessToken);
},
+
+ userId: (state) => {
+ return state.userDetail?.id ?? '';
+ },
},
actions: {
// 鎵嬫満鍙锋巿鏉僀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.C绔皬绋嬪簭,
- };
- res = await accountServices.wxMiniAppPhoneAuthLogin(params);
+ sessionKey: wxMiniAppUserLoginRes.sessionKey,
+ accessToken: wxMiniAppUserLoginRes.accessToken,
+ });
+ res.accessToken = bindRes.accessToken;
this.loginSuccess(res);
}
return res;
@@ -114,11 +116,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 }
);
@@ -134,7 +138,8 @@
let res = await authServices.passwordLogin(
{
userName: params.userName,
- password: md5Encrypt(params.password),
+ // password: md5Encrypt(params.password),
+ password: params.password,
type: AppLocalConfig.userType,
clientType: AppLocalConfig.clientType,
},
@@ -146,7 +151,7 @@
return res;
},
- async loginSuccess(res: API.PasswordLoginCommandCallback) {
+ async loginSuccess(res: API.LoginCommandCallback) {
try {
this.setUserInfoAction(res);
this.setTokenAction(res);
@@ -155,15 +160,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(
@@ -171,47 +176,50 @@
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.C绔皬绋嬪簭,
- });
- 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.getPersonalLoginInfo({}, { 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;
+ res.originalAvatar = res.avatar;
+ res.avatar = res.avatar ? setOSSLink(res.avatar) : DefaultAvatar;
+ this.setUserDetail(res);
+ this.firstGetUserDetail = false;
}
} catch (error) {}
},
- setTokenAction(tokenInfo: API.PasswordLoginCommandCallback) {
+ setTokenAction(tokenInfo: API.LoginCommandCallback) {
this.token = tokenInfo?.accessToken;
this.refreshToken = tokenInfo.refreshToken ?? '';
},
- setUserInfoAction(info: API.PasswordLoginCommandCallback) {
- this.userInfo = info;
- setUserInfo(info);
+ setUserInfoAction(info: API.LoginCommandCallback) {
+ this.userInfo = {
+ ...this.userInfo,
+ ...info,
+ };
+ setUserInfo(this.userInfo);
},
- setUserDetail(detail: API.UserInfoV2) {
+ setUserDetail(detail: API.GetPersonalLoginInfoQueryResult) {
this.userDetail = detail;
setUserDetail(detail);
},
@@ -230,7 +238,7 @@
*/
logout() {
this.resetState();
- myClient.removeQueries();
+ // myClient.removeQueries();
goAuthorization();
},
@@ -271,6 +279,10 @@
// }
LocationUtils.currentProvinceName = provinceName;
},
+
+ setFirstLaunch(firstLaunch: boolean) {
+ this.firstLaunch = firstLaunch;
+ },
},
});
--
Gitblit v1.9.1