| | |
| | | setStorageVirtualUserId, |
| | | getStorageVirtualUserId, |
| | | removeStorageVirtualUserId, |
| | | LoginVirtualRes, |
| | | } from '@/utils/storage/auth'; |
| | | import * as accountServices from '@life-payment/services/api/Account'; |
| | | import * as userServices from '@life-payment/services/api/User'; |
| | | import Taro, { useRouter } from '@tarojs/taro'; |
| | | import { ButtonProps } from '@tarojs/components'; |
| | | import { debounce } from 'lodash'; |
| | |
| | | firstSetLocation?: boolean; |
| | | |
| | | virtualUserId?: string; |
| | | virtualPhoneNumber?: string; |
| | | |
| | | wxCode?: string; |
| | | wxOpenId?: string; |
| | | } |
| | | |
| | | const goAuthorization = debounce( |
| | | () => { |
| | | const route = Taro.getCurrentInstance().router; |
| | | if (route.path !== RouterPath.authorization) { |
| | | Taro.navigateTo({ |
| | | RouteHelper.navigateTo({ |
| | | url: RouterPath.authorization, |
| | | }); |
| | | } |
| | |
| | | state: (): UserState => { |
| | | const userInfo = getCacheUserInfo(); |
| | | const userDetail = getUserDetail(); |
| | | const storageVirtualUser = getStorageVirtualUserId(); |
| | | |
| | | return { |
| | | // user info |
| | |
| | | userDetail: userDetail, |
| | | firstGetUserDetail: true, |
| | | |
| | | virtualUserId: getStorageVirtualUserId() ?? '', |
| | | virtualUserId: storageVirtualUser?.virtualUserId ?? '', |
| | | virtualPhoneNumber: storageVirtualUser?.virtualPhoneNumber ?? '', |
| | | |
| | | wxCode: '', |
| | | wxOpenId: '', |
| | | }; |
| | | }, |
| | | getters: { |
| | |
| | | wxMiniAppUserLoginRes: any |
| | | ) { |
| | | try { |
| | | let res: API.IdentityModelTokenCacheItem; |
| | | if (!wxMiniAppUserLoginRes.accessToken) { |
| | | let params: API.WxMiniAppPhoneLoginInput = { |
| | | openId: wxMiniAppUserLoginRes.openId, |
| | | sessionKey: wxMiniAppUserLoginRes.sessionKey, |
| | | encryptedData: detail.encryptedData, |
| | | iv: detail.iv, |
| | | // wxMiniApp: WxMiniAppEnum.C端小程序, |
| | | }; |
| | | res = await accountServices.wxMiniAppPhoneAuthLogin(params); |
| | | this.loginSuccess(res); |
| | | } |
| | | return res; |
| | | // let res: API.IdentityModelTokenCacheItem; |
| | | // if (!wxMiniAppUserLoginRes.accessToken) { |
| | | // let params: API.WxMiniAppPhoneLoginInput = { |
| | | // openId: wxMiniAppUserLoginRes.openId, |
| | | // sessionKey: wxMiniAppUserLoginRes.sessionKey, |
| | | // encryptedData: detail.encryptedData, |
| | | // iv: detail.iv, |
| | | // // wxMiniApp: WxMiniAppEnum.C端小程序, |
| | | // }; |
| | | // res = await accountServices.wxMiniAppPhoneAuthLogin(params); |
| | | // this.loginSuccess(res); |
| | | // } |
| | | // return res; |
| | | return 1; |
| | | } catch (error) { |
| | | console.log('error3: ', error); |
| | | } |
| | | }, |
| | | |
| | | // 用户手机验证码登入 |
| | | async loginByUsername(data: API.PhoneMesssageCodeLoginInput) { |
| | | async loginByUsername(data: any) { |
| | | let res = await accountServices.lifePayPhoneMesssageCodeLogin( |
| | | { |
| | | phoneNumber: data.phoneNumber, |
| | | code: data.code, |
| | | // code: data.code, |
| | | }, |
| | | { showLoading: false } |
| | | ); |
| | | |
| | | if (res) { |
| | | this.loginVirtualSuccess(res); |
| | | this.loginVirtualSuccess({ |
| | | virtualUserId: res.userId, |
| | | virtualPhoneNumber: data.phoneNumber, |
| | | }); |
| | | } |
| | | return res; |
| | | }, |
| | | |
| | | // 用户账号密码登入 |
| | | async loginByPassword(data: API.AccessRequestDto) { |
| | | let res = await accountServices.passwordLogin( |
| | | { |
| | | loginName: data.userName, |
| | | password: data.userPassword, |
| | | }, |
| | | { showLoading: false } |
| | | ); |
| | | if (res) { |
| | | this.loginSuccess(res); |
| | | } |
| | | return res; |
| | | // let res = await accountServices.passwordLogin( |
| | | // { |
| | | // loginName: data.userName, |
| | | // password: data.userPassword, |
| | | // }, |
| | | // { showLoading: false } |
| | | // ); |
| | | // if (res) { |
| | | // this.loginSuccess(res); |
| | | // } |
| | | // return res; |
| | | }, |
| | | |
| | | async loginSuccess(res: API.IdentityModelTokenCacheItem) { |
| | |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | async loginVirtualSuccess(virtualUserId: string) { |
| | | async loginVirtualSuccess(virtualUserRes: LoginVirtualRes) { |
| | | try { |
| | | this.setVirtualUserId(virtualUserId); |
| | | this.setVirtualUserId(virtualUserRes); |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | setVirtualUserId(virtualUserId: string) { |
| | | this.virtualUserId = virtualUserId; |
| | | setStorageVirtualUserId(virtualUserId); |
| | | setVirtualUserId(virtualUserRes: LoginVirtualRes) { |
| | | this.virtualUserId = virtualUserRes.virtualUserId; |
| | | this.virtualPhoneNumber = virtualUserRes.virtualPhoneNumber; |
| | | setStorageVirtualUserId(virtualUserRes); |
| | | }, |
| | | |
| | | 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; |
| | | // let res = await accountServices.wxMiniAppUserLoginFromScan({ |
| | | // uId: uuid, |
| | | // userName: wxIndentityRes.userName, |
| | | // openId: wxIndentityRes.openId, |
| | | // }); |
| | | // this.loginSuccess(res); |
| | | // return res; |
| | | return 1; |
| | | } catch (error) {} |
| | | }, |
| | | |
| | |
| | | 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; |
| | | // 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; |
| | | return 1; |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | async getCurrentUserInfo() { |
| | | try { |
| | | let res = await userServices.getUserInfo({ showLoading: false }); |
| | | if (res) { |
| | | res.originalAvatarUrl = res.avatarUrl; |
| | | res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar; |
| | | this.setUserDetail(res); |
| | | this.firstGetUserDetail = false; |
| | | } |
| | | // let res = await userServices.getUserInfo({ showLoading: false }); |
| | | // if (res) { |
| | | // this.setUserDetail(res); |
| | | // this.firstGetUserDetail = false; |
| | | // } |
| | | } catch (error) {} |
| | | }, |
| | | |
| | |
| | | setUserDetail(detail); |
| | | }, |
| | | |
| | | setWxCode(code: string) { |
| | | this.wxCode = code; |
| | | }, |
| | | setWxOpenId(openId: string) { |
| | | this.wxOpenId = openId; |
| | | }, |
| | | |
| | | resetState() { |
| | | this.userInfo = null; |
| | | this.token = ''; |
| | | this.refreshToken = ''; |
| | | this.userDetail = null; |
| | | this.virtualUserId = ''; |
| | | this.virtualPhoneNumber = ''; |
| | | this.wxCode = ''; |
| | | this.wxOpenId = ''; |
| | | removeUserInfo(); |
| | | removeUserDetail(); |
| | | removeStorageVirtualUserId(); |
| | |
| | | logout() { |
| | | this.resetState(); |
| | | myClient.removeQueries(); |
| | | goAuthorization(); |
| | | // goAuthorization(); |
| | | }, |
| | | |
| | | logoutAndToHome() { |