From c02e7a8fe42de2a5796e95e573f9e6b6735e4d0d Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 25 三月 2025 17:06:43 +0800
Subject: [PATCH] fix: 四期需求

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

diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts
index f76e73d..87a319c 100644
--- a/apps/taro/src/hooks/user.ts
+++ b/apps/taro/src/hooks/user.ts
@@ -26,6 +26,8 @@
     return userStore.getCurrentUserInfo();
   }
 
+  const isChannelAccount = computed(() => !!virtualUserId.value && true);
+
   return {
     user: userInfo,
     userDetail: userDetail,
@@ -35,6 +37,7 @@
     virtualPhoneNumber,
     wxCode,
     wxOpenId,
+    isChannelAccount,
   };
 }
 
@@ -83,6 +86,8 @@
 
   const { blLifeRecharge } = useLifeRechargeContext();
 
+  const { getLifePayWxIndentity } = useLifePayWxIndentity();
+
   Taro.useReady(async () => {
     try {
       //@ts-ignore
@@ -93,13 +98,17 @@
       }
       if (!!code && !wxCode.value) {
         userStore.setWxCode(router.params.code ?? '');
-        let res = await getLifePayWxIndentity();
-        userStore.setWxOpenId(res.openId);
+        // getLifePayWxIndentity(code);
       }
     } catch (error) {}
   });
+}
 
-  async function getLifePayWxIndentity() {
+export function useLifePayWxIndentity() {
+  const { blLifeRecharge } = useLifeRechargeContext();
+  const userStore = useUserStore();
+
+  async function getLifePayWxIndentity(code: string) {
     try {
       let params: APIgetLifePayWxIndentityParams = {
         code: code,
@@ -107,9 +116,30 @@
       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() {

--
Gitblit v1.9.1