From a60cf88c3c9e18e83f3c216eaf444c44c3e94763 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 24 三月 2025 18:18:59 +0800
Subject: [PATCH] fix: 四期需求
---
apps/taro/src/hooks/user.ts | 94 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts
index 29a6ef4..757a837 100644
--- a/apps/taro/src/hooks/user.ts
+++ b/apps/taro/src/hooks/user.ts
@@ -1,28 +1,43 @@
import { useUserStore } from '@/stores/modules/user';
import Taro from '@tarojs/taro';
import { object2query } from '@life-payment/utils';
-import * as userServices from '@life-payment/services/api/User';
import { useQuery } from '@tanstack/vue-query';
import { MaybeRef } from 'vue';
import { useRefeshDidShow } from './infiniteLoading';
import { LoginFormTabs } from '@/subpackages/login/constants';
import { useLoginedJump } from './login';
+import { useLifeRechargeContext, APIgetLifePayWxIndentityParams } from '@life-payment/core-vue';
+import { isInWeChat } from '@/utils/env';
export function useUser() {
const userStore = useUserStore();
- const { userDetail, userInfo, locationCity, virtualUserId } = storeToRefs(userStore);
+ const {
+ userDetail,
+ userInfo,
+ locationCity,
+ virtualUserId,
+ virtualPhoneNumber,
+ wxCode,
+ wxOpenId,
+ } = storeToRefs(userStore);
function updateUserInfo() {
return userStore.getCurrentUserInfo();
}
+ const isChannelAccount = computed(() => true);
+
return {
user: userInfo,
userDetail: userDetail,
updateUserInfo,
locationCity,
virtualUserId,
+ virtualPhoneNumber,
+ wxCode,
+ wxOpenId,
+ isChannelAccount,
};
}
@@ -45,14 +60,15 @@
const isAuth = computed(() => !needAuth || isLogin.value);
const router = Taro.useRouter();
+ useInitWeixinJSBridge();
Taro.useReady(async () => {
if (isLogin.value && userStore.firstGetUserDetail) {
// userStore.getCurrentUserInfo();
}
if (needAuth && !isLogin.value) {
- Taro.navigateTo({
- url: `${RouterPath.authorization}?redirect=${router.path}&${object2query(router.params)}`,
+ RouteHelper.navigateTo({
+ url: `${RouterPath.loginByForm}?redirect=${router.path}&${object2query(router.params)}`,
});
}
});
@@ -60,15 +76,81 @@
return { isAuth };
}
+export function useInitWeixinJSBridge() {
+ const { wxCode } = useUser();
+
+ const userStore = useUserStore();
+ const router = Taro.useRouter();
+
+ const code = router.params.code ?? '';
+
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const { getLifePayWxIndentity } = useLifePayWxIndentity();
+
+ Taro.useReady(async () => {
+ try {
+ //@ts-ignore
+ if (!code && isInWeChat && !wxCode.value && location?.replace) {
+ location.replace(
+ `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf940ff1d35a98493&redirect_uri=${location.href}&response_type=code&scope=snsapi_base#wechat_redirect`
+ );
+ }
+ if (!!code && !wxCode.value) {
+ userStore.setWxCode(router.params.code ?? '');
+ // getLifePayWxIndentity(code);
+ }
+ } catch (error) {}
+ });
+}
+
+export function useLifePayWxIndentity() {
+ const { blLifeRecharge } = useLifeRechargeContext();
+ const userStore = useUserStore();
+
+ async function getLifePayWxIndentity(code: string) {
+ try {
+ let params: APIgetLifePayWxIndentityParams = {
+ code: code,
+ };
+ let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
+ showLoading: false,
+ });
+ if (res.openId) {
+ userStore.setWxOpenId(res.openId);
+ }
+ return res;
+ } catch (error) {}
+ }
+
+ return { getLifePayWxIndentity };
+}
+
+export function useEnsureOpenId() {
+ const { wxCode, wxOpenId } = useUser();
+ const { getLifePayWxIndentity } = useLifePayWxIndentity();
+
+ async function ensureOpenId() {
+ if (wxOpenId.value) {
+ return wxOpenId.value;
+ } else {
+ let rea = await getLifePayWxIndentity(wxCode.value);
+ return rea.openId ? rea.openId : wxOpenId.value;
+ }
+ }
+
+ return { ensureOpenId };
+}
+
export function useGoLogin() {
const router = Taro.useRouter();
const { redirectParams } = useLoginedJump();
function goLoginFn() {
- // Taro.navigateTo({
+ // RouteHelper.navigateTo({
// url: `${RouterPath.authorization}?redirect=${router.path}&${object2query(router.params)}`,
// });
- Taro.navigateTo({
+ RouteHelper.navigateTo({
url: `${RouterPath.loginByForm}?redirect=${redirectParams.value}&tab=${LoginFormTabs.VerificationCodeLogin}`,
});
}
--
Gitblit v1.10.0