zhengyiming
2025-03-20 192be5ad46233a4cd25880ba029997d47ad09bf6
apps/taro/src/hooks/user.ts
@@ -83,6 +83,8 @@
  const { blLifeRecharge } = useLifeRechargeContext();
  const { getLifePayWxIndentity } = useLifePayWxIndentity();
  Taro.useReady(async () => {
    try {
      //@ts-ignore
@@ -93,13 +95,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 +113,28 @@
      let res = await blLifeRecharge.services.getLifePayWxIndentity(params, {
        showLoading: false,
      });
      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) {
      return wxOpenId.value;
    } else {
      let rea = await getLifePayWxIndentity(wxCode.value);
      return rea.openId;
    }
  }
  return { ensureOpenId };
}
export function useGoLogin() {