From 7ed1e4f30ba4d8204152cb157ceaee07374da080 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 17 三月 2025 14:29:14 +0800
Subject: [PATCH] fix: 修改支付方式选择

---
 apps/taro/src/hooks/user.ts |   49 +++++++++++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts
index 3dd00bb..67a64fe 100644
--- a/apps/taro/src/hooks/user.ts
+++ b/apps/taro/src/hooks/user.ts
@@ -8,6 +8,7 @@
 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();
@@ -57,13 +58,14 @@
   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({
+      RouteHelper.navigateTo({
         url: `${RouterPath.loginByForm}?redirect=${router.path}&${object2query(router.params)}`,
       });
     }
@@ -83,40 +85,43 @@
   const { blLifeRecharge } = useLifeRechargeContext();
 
   Taro.useReady(async () => {
-    if (!code && !!WeixinJSBridge && !wxCode) {
-      location.href = `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) {
-      try {
+    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 ?? '');
         let res = await getLifePayWxIndentity();
         userStore.setWxOpenId(res.openId);
-      } catch (error) {}
-    }
-
-    async function getLifePayWxIndentity() {
-      try {
-        let params: APIgetLifePayWxIndentityParams = {
-          code: code,
-        };
-        let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
-          showLoading: false,
-        });
-        return res;
-      } catch (error) {}
-    }
+      }
+    } catch (error) {}
   });
+
+  async function getLifePayWxIndentity() {
+    try {
+      let params: APIgetLifePayWxIndentityParams = {
+        code: code,
+      };
+      let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
+        showLoading: false,
+      });
+      return res;
+    } catch (error) {}
+  }
 }
 
 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.9.1