| | |
| | | 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'; |
| | |
| | | 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.PasswordLoginCommandCallback>; |
| | | token?: Nullable<string>; |
| | | refreshToken?: Nullable<string>; |
| | | userDetail?: Nullable<API.UserInfoV2>; |
| | |
| | | }; |
| | | }, |
| | | 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); |
| | | }, |
| | | |
| | | // matchMakingIdentity(state): MatchMakingIdentityEnum { |
| | | |
| | | // }, |
| | | }, |
| | | actions: { |
| | | // 手机号授权Code登录 |
| | |
| | | }, |
| | | |
| | | // 用户账号密码登入 |
| | | 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 } |
| | | ); |
| | |
| | | return res; |
| | | }, |
| | | |
| | | async loginSuccess(res: API.IdentityModelTokenCacheItem) { |
| | | async loginSuccess(res: API.PasswordLoginCommandCallback) { |
| | | try { |
| | | this.setUserInfoAction(res); |
| | | this.setTokenAction(res); |
| | |
| | | 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; |
| | | // 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); |
| | | }, |
| | |
| | | this.userDetail = null; |
| | | removeUserInfo(); |
| | | removeUserDetail(); |
| | | removeMatchMakingIdentity(); |
| | | }, |
| | | |
| | | /** |
| | |
| | | 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'); |
| | | } |
| | | }, |
| | | |