zhengyiming
2025-03-27 55c03f35a31979aefd46aead13a145c9b293e6d8
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,
  };
}
@@ -95,11 +102,13 @@
      }
      if (!!code && !wxCode.value) {
        userStore.setWxCode(router.params.code ?? '');
        // getLifePayWxIndentity(code);
        getLifePayWxIndentity(code);
      }
    } catch (error) {}
  });
}
let wxIndentityPromise: Promise<WxMiniAppIndentityInfo>;
export function useLifePayWxIndentity() {
  const { blLifeRecharge } = useLifeRechargeContext();
@@ -110,9 +119,17 @@
      let params: APIgetLifePayWxIndentityParams = {
        code: code,
      };
      let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
        showLoading: false,
      });
      if (!wxIndentityPromise) {
        wxIndentityPromise = blLifeRecharge.services
          .getLifePayWxIndentity(params, {
            showLoading: false,
          })
          .finally(() => {
            wxIndentityPromise = undefined;
          });
      }
      let res = await wxIndentityPromise;
      if (res.openId) {
        userStore.setWxOpenId(res.openId);
      }