| | |
| | | import { myClient } from '@/constants/query'; |
| | | import { VueLifeRechargePlugin } from '@life-payment/components'; |
| | | import { blLifeRecharge } from '@/utils/blLifeRecharge'; |
| | | import { isWeChat } from '@/utils/env'; |
| | | |
| | | window.uni = Taro; |
| | | |
| | |
| | | |
| | | // 对应 onShow |
| | | onShow(options) { |
| | | updateVersions(); |
| | | if (isWeChat) { |
| | | updateVersions(); |
| | | } |
| | | }, |
| | | |
| | | // 对应 onHide |
| | |
| | | if (!isLogin.value) { |
| | | Message.confirm({ message: '请前往登录' }).then(() => { |
| | | Taro.navigateTo({ |
| | | url: `${RouterPath.authorization}`, |
| | | // url: `${RouterPath.authorization}`, |
| | | url: `${RouterPath.loginByForm}`, |
| | | }); |
| | | }); |
| | | return; |
| | |
| | | export function useUser() { |
| | | const userStore = useUserStore(); |
| | | |
| | | const { userDetail, userInfo, locationCity } = storeToRefs(userStore); |
| | | const { userDetail, userInfo, locationCity, virtualUserId } = storeToRefs(userStore); |
| | | |
| | | function updateUserInfo() { |
| | | return userStore.getCurrentUserInfo(); |
| | |
| | | userDetail: userDetail, |
| | | updateUserInfo, |
| | | locationCity, |
| | | virtualUserId, |
| | | }; |
| | | } |
| | | |
| | | export function useIsLogin() { |
| | | const { user, userDetail } = useUser(); |
| | | return computed(() => !!user.value); |
| | | // return user?.isPersonal ? !!user : !!user && !!enterpriseInfo; |
| | | const { virtualUserId } = useUser(); |
| | | // return computed(() => !!user.value); |
| | | return computed(() => !!virtualUserId.value); |
| | | } |
| | | |
| | | type UseAuthOptions = { |
| | |
| | | |
| | | Taro.useReady(async () => { |
| | | if (isLogin.value && userStore.firstGetUserDetail) { |
| | | userStore.getCurrentUserInfo(); |
| | | // userStore.getCurrentUserInfo(); |
| | | } |
| | | if (needAuth && !isLogin.value) { |
| | | Taro.navigateTo({ |
| | |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import { useUser, useInfiniteLoading } from '@/hooks'; |
| | | import { useUser, useAccessLogin } from '@/hooks'; |
| | | import { useUserStore } from '@/stores/modules/user'; |
| | | import Taro from '@tarojs/taro'; |
| | | import IconLogo from '@/assets/home/icon-logo.png'; |
| | | import { OrderInputType } from '@life-payment/constants'; |
| | | import { RechargeGrid } from '@life-payment/components'; |
| | | |
| | | function goPhoneBillRecharge() { |
| | | const goPhoneBillRecharge = useAccessLogin(() => { |
| | | Taro.navigateTo({ |
| | | url: `${RouterPath.phoneBillRecharge}`, |
| | | }) |
| | | .then(() => { |
| | | console.log('Navigate successfully'); |
| | | }) |
| | | .catch((err) => { |
| | | console.error('Navigation failed:', err); |
| | | }); |
| | | } |
| | | }); |
| | | }); |
| | | </script> |
| | | |
| | | <style lang="scss"> |
| | |
| | | setUserDetail, |
| | | getUserDetail, |
| | | removeUserDetail, |
| | | setStorageVirtualUserId, |
| | | getStorageVirtualUserId, |
| | | removeStorageVirtualUserId, |
| | | } from '@/utils/storage/auth'; |
| | | import * as accountServices from '@life-payment/services/api/Account'; |
| | | import * as userServices from '@life-payment/services/api/User'; |
| | |
| | | locationCity?: string; |
| | | locationProvince?: string; |
| | | firstSetLocation?: boolean; |
| | | |
| | | virtualUserId?: string; |
| | | } |
| | | |
| | | const goAuthorization = debounce( |
| | |
| | | refreshToken: userInfo?.refreshToken ?? '', |
| | | userDetail: userDetail, |
| | | firstGetUserDetail: true, |
| | | |
| | | virtualUserId: getStorageVirtualUserId() ?? '', |
| | | }; |
| | | }, |
| | | getters: { |
| | |
| | | ); |
| | | |
| | | if (res) { |
| | | this.loginSuccess(res); |
| | | this.loginVirtualSuccess(res); |
| | | } |
| | | return res; |
| | | }, |
| | |
| | | return res; |
| | | }, |
| | | |
| | | async loginSuccess(res: API.IdentityModelTokenCacheItem | string) { |
| | | async loginSuccess(res: API.IdentityModelTokenCacheItem) { |
| | | console.log('res: ', res); |
| | | // try { |
| | | // this.setUserInfoAction(res); |
| | | // this.setTokenAction(res); |
| | | // await this.getCurrentUserInfo(); |
| | | // } catch (error) {} |
| | | try { |
| | | this.setUserInfoAction(res); |
| | | this.setTokenAction(res); |
| | | await this.getCurrentUserInfo(); |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | async loginVirtualSuccess(virtualUserId: string) { |
| | | try { |
| | | this.setVirtualUserId(virtualUserId); |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | setVirtualUserId(virtualUserId: string) { |
| | | this.virtualUserId = virtualUserId; |
| | | setStorageVirtualUserId(virtualUserId); |
| | | }, |
| | | |
| | | async wxMiniAppUserLoginFromScan(wxIndentityRes: API.WxMiniAppIndentityInfo, uuid: string) { |
| | |
| | | this.userDetail = null; |
| | | removeUserInfo(); |
| | | removeUserDetail(); |
| | | removeStorageVirtualUserId(); |
| | | }, |
| | | |
| | | /** |
| | |
| | | <img :src="OssAssets.login.AuthBg" class="authorization-page-auth" /> |
| | | </template> |
| | | |
| | | <div class="authorization-page-title">欢迎使用818平台</div> |
| | | <div class="authorization-page-title">欢迎使用生活缴费平台</div> |
| | | |
| | | <slot></slot> |
| | | </PageLayout> |
| | |
| | | import { useLoginedJump } from '@/hooks'; |
| | | import { useUserStore } from '@/stores/modules/user'; |
| | | import Taro from '@tarojs/taro'; |
| | | import { useLifeRechargeContext } from '@life-payment/components'; |
| | | |
| | | defineOptions({ |
| | | name: 'verificationCodeLoginForm', |
| | |
| | | const props = withDefaults(defineProps<Props>(), {}); |
| | | |
| | | const userStore = useUserStore(); |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | |
| | | const { jump } = useLoginedJump(); |
| | | |
| | |
| | | const { valid } = await formRef.value.validate(); |
| | | if (valid) { |
| | | form.loading = true; |
| | | await userStore.loginByUsername({ |
| | | phoneNumber: form.phoneNumber, |
| | | code: form.verificationCode, |
| | | }); |
| | | // await userStore.loginByUsername({ |
| | | // phoneNumber: form.phoneNumber, |
| | | // code: form.verificationCode, |
| | | // }); |
| | | let res = await blLifeRecharge.login( |
| | | { |
| | | phoneNumber: form.phoneNumber, |
| | | code: form.verificationCode, |
| | | }, |
| | | { |
| | | showLoading: false, |
| | | } |
| | | ); |
| | | userStore.loginVirtualSuccess(res); |
| | | jump(); |
| | | } |
| | | } else { |
| | |
| | | <template> |
| | | <PageLayout title="话费充值" class="phoneBillRecharge-page-wrapper" hasBorder :need-auth="false"> |
| | | <PageLayout title="话费充值" class="phoneBillRecharge-page-wrapper" hasBorder> |
| | | <InnerPage /> |
| | | </PageLayout> |
| | | </template> |
| | |
| | | <template> |
| | | <PageLayout title="充值成功" class="rechargeResult-page-wrapper" hasBorder :need-auth="false"> |
| | | <PageLayout title="充值成功" class="rechargeResult-page-wrapper" hasBorder> |
| | | <ContentScrollView> |
| | | <RechargeResultView style="margin-top: 40px" @go-back-home="goHome()" /> |
| | | </ContentScrollView> |
| | |
| | | <template> |
| | | <PageLayout title="话费充值" class="selectPayType-page-wrapper" hasBorder :need-auth="false"> |
| | | <PageLayout title="话费充值" class="selectPayType-page-wrapper" hasBorder> |
| | | <InnerPage /> |
| | | </PageLayout> |
| | | </template> |
| | |
| | | import { BlLifeRecharge } from '@life-payment/components'; |
| | | import { request } from './request'; |
| | | import { getStorageVirtualUserId } from './storage'; |
| | | |
| | | export const blLifeRecharge = new BlLifeRecharge({ |
| | | request, |
| | | userId: getStorageVirtualUserId() ?? '', |
| | | }); |
| | |
| | | USER_DETAIL_KEY: 'USER_DETAIL_KEY', |
| | | MatchMakingIdentity_KEY: 'MatchMakingIdentity_KEY', |
| | | LocationCity_KEY: 'LocationCity_KEY', |
| | | VirtualUserId_KEY: 'VirtualUserId_KEY', |
| | | }; |
| | | |
| | | export function getToken() { |
| | |
| | | return storageLocal.removeItem(StorageKey.USER_DETAIL_KEY); |
| | | } |
| | | |
| | | export function getStorageVirtualUserId() { |
| | | return storageLocal.getItem<string>(StorageKey.VirtualUserId_KEY); |
| | | } |
| | | |
| | | export function setStorageVirtualUserId(virtualUserId: string) { |
| | | return storageLocal.setItem(StorageKey.VirtualUserId_KEY, virtualUserId); |
| | | } |
| | | |
| | | export function removeStorageVirtualUserId() { |
| | | return storageLocal.removeItem(StorageKey.VirtualUserId_KEY); |
| | | } |
| | | |
| | | type StorageLocation = { |
| | | city: string; |
| | |
| | | import { BlLifeRechargeServices, PhoneMesssageCodeLoginInput } from './lifeRechargeServices'; |
| | | import { |
| | | BlLifeRechargeServices, |
| | | PhoneMesssageCodeLoginInput, |
| | | RequestConfig, |
| | | } from './lifeRechargeServices'; |
| | | import { IRequest, BlLifeRechargeOptions } from './types'; |
| | | |
| | | export class BlLifeRecharge<T extends IRequest = IRequest> { |
| | | services: BlLifeRechargeServices<T>; |
| | | isLogin = false; |
| | | userId = ''; |
| | | |
| | | constructor(options: BlLifeRechargeOptions<T>) { |
| | | this.services = new BlLifeRechargeServices(options); |
| | | this.userId = options.userId || ''; |
| | | } |
| | | |
| | | login(body: PhoneMesssageCodeLoginInput) { |
| | | let res = this.services.lifePayPhoneMesssageCodeLogin(body); |
| | | this.isLogin = true; |
| | | async login(body: PhoneMesssageCodeLoginInput, options?: RequestConfig) { |
| | | let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options); |
| | | this.userId = res; |
| | | return res; |
| | | } |
| | | |
| | | loginout() { |
| | | this.userId = ''; |
| | | } |
| | | |
| | | isLogin() { |
| | | return !!this.userId; |
| | | } |
| | | |
| | | getRechargeParValue(amount: number, rate: number) { |
| | | return (amount * rate).toFixed(2); |
| | | } |
| | |
| | | export interface IRequestOptions extends AxiosRequestConfig {} |
| | | |
| | | export interface IRequest { |
| | | <T = any>(url: string, opts: IRequestOptions): Promise<AxiosResponse<T>>; |
| | | <T = any>(url: string, opts: IRequestOptions): Promise<T>; |
| | | } |
| | | |
| | | export type BlLifeRechargeServicesOptions<T extends IRequest> = { |
| | | request: T; |
| | | }; |
| | | |
| | | export type BlLifeRechargeOptions<T extends IRequest> = BlLifeRechargeServicesOptions<T> & {}; |
| | | export type BlLifeRechargeOptions<T extends IRequest> = BlLifeRechargeServicesOptions<T> & { |
| | | userId?: string; |
| | | }; |