From 55c03f35a31979aefd46aead13a145c9b293e6d8 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期四, 27 三月 2025 17:38:55 +0800
Subject: [PATCH] fix: 四期需求

---
 apps/taro/src/hooks/user.ts |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts
index 6e25fee..711c45e 100644
--- a/apps/taro/src/hooks/user.ts
+++ b/apps/taro/src/hooks/user.ts
@@ -6,7 +6,11 @@
 import { useRefeshDidShow } from './infiniteLoading';
 import { LoginFormTabs } from '@/subpackages/login/constants';
 import { useLoginedJump } from './login';
-import { useLifeRechargeContext, APIgetLifePayWxIndentityParams } from '@life-payment/core-vue';
+import {
+  useLifeRechargeContext,
+  APIgetLifePayWxIndentityParams,
+  WxMiniAppIndentityInfo,
+} from '@life-payment/core-vue';
 import { isInWeChat } from '@/utils/env';
 
 export function useUser() {
@@ -26,6 +30,8 @@
     return userStore.getCurrentUserInfo();
   }
 
+  const isChannelAccount = computed(() => !!virtualUserId.value && true);
+
   return {
     user: userInfo,
     userDetail: userDetail,
@@ -35,6 +41,7 @@
     virtualPhoneNumber,
     wxCode,
     wxOpenId,
+    isChannelAccount,
   };
 }
 
@@ -101,6 +108,8 @@
   });
 }
 
+let wxIndentityPromise: Promise<WxMiniAppIndentityInfo>;
+
 export function useLifePayWxIndentity() {
   const { blLifeRecharge } = useLifeRechargeContext();
   const userStore = useUserStore();
@@ -110,10 +119,20 @@
       let params: APIgetLifePayWxIndentityParams = {
         code: code,
       };
-      let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
-        showLoading: false,
-      });
-      userStore.setWxOpenId(res.openId);
+      if (!wxIndentityPromise) {
+        wxIndentityPromise = blLifeRecharge.services
+          .getLifePayWxIndentity(params, {
+            showLoading: false,
+          })
+          .finally(() => {
+            wxIndentityPromise = undefined;
+          });
+      }
+
+      let res = await wxIndentityPromise;
+      if (res.openId) {
+        userStore.setWxOpenId(res.openId);
+      }
       return res;
     } catch (error) {}
   }
@@ -126,11 +145,11 @@
   const { getLifePayWxIndentity } = useLifePayWxIndentity();
 
   async function ensureOpenId() {
-    if (wxOpenId) {
+    if (wxOpenId.value) {
       return wxOpenId.value;
     } else {
       let rea = await getLifePayWxIndentity(wxCode.value);
-      return rea.openId;
+      return rea.openId ? rea.openId : wxOpenId.value;
     }
   }
 

--
Gitblit v1.9.1