| | |
| | | import { AppLocalConfig } from '@/constants'; |
| | | |
| | | interface UserState { |
| | | userInfo?: Nullable<API.PasswordLoginCommandCallback>; |
| | | userInfo?: Nullable<API.LoginCommandCallback>; |
| | | token?: Nullable<string>; |
| | | refreshToken?: Nullable<string>; |
| | | userDetail?: Nullable<API.UserInfoV2>; |
| | |
| | | accountInfo(): Partial<AccountInfo> { |
| | | return getAccountInfoFromAccessToken(this.userInfo?.accessToken); |
| | | }, |
| | | |
| | | userId: (state) => { |
| | | return state.userInfo?.id ?? ''; |
| | | }, |
| | | }, |
| | | actions: { |
| | | // 手机号授权Code登录 |
| | |
| | | }, |
| | | |
| | | // 用户手机验证码登入 |
| | | 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 } |
| | | ); |
| | |
| | | return res; |
| | | }, |
| | | |
| | | async loginSuccess(res: API.PasswordLoginCommandCallback) { |
| | | async loginSuccess(res: API.LoginCommandCallback) { |
| | | try { |
| | | this.setUserInfoAction(res); |
| | | this.setTokenAction(res); |
| | |
| | | }, |
| | | |
| | | 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.PasswordLoginCommandCallback) { |
| | | setTokenAction(tokenInfo: API.LoginCommandCallback) { |
| | | this.token = tokenInfo?.accessToken; |
| | | this.refreshToken = tokenInfo.refreshToken ?? ''; |
| | | }, |
| | | |
| | | setUserInfoAction(info: API.PasswordLoginCommandCallback) { |
| | | setUserInfoAction(info: API.LoginCommandCallback) { |
| | | this.userInfo = info; |
| | | setUserInfo(info); |
| | | }, |