wupengfei
2025-03-10 6887129e91d32557c2b57178180329f46df09d12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { useUserStore } from '@/stores/modules/user';
import Taro from '@tarojs/taro';
import { object2query, LocationUtils } from '@12333/utils';
import { ParkOrHRStatus, UserCertificationFrontStatus } from '@12333/constants';
// import * as userServices from '@12333/services/api/User';
import { useQuery } from '@tanstack/vue-query';
import { MaybeRef } from 'vue';
import { useRefeshDidShow } from '@12333/hooks/infiniteLoading';
 
export function useUser() {
  const userStore = useUserStore();
 
  const { userDetail, userInfo, locationCity } = storeToRefs(userStore);
 
  // function updateUserInfo() {
  //   return userStore.getCurrentUserInfo();
  // }
 
  // const isCompanyAudited = computed(() => {
  //   return userDetail.value?.openHRSiteStatus === ParkOrHRStatus.Running;
  // });
 
  /**
   * 是否完善个人信息(企业名称,手机号)
   */
  // const isCompletePersonalInfo = computed(() => {
  //   return (
  //     !!userDetail.value?.customerName &&
  //     !!userDetail.value?.contacter &&
  //     !!userDetail.value?.cityName
  //   );
  // });
 
  const isCertified = computed(() => {
    return userDetail.value?.frontStatus === UserCertificationFrontStatus.Certified;
  });
 
  return {
    user: userInfo,
    userDetail: userDetail,
    // updateUserInfo,
    // isCompletePersonalInfo,
    // isCompanyAudited,
    isCertified,
    locationCity,
  };
}
 
export function useIsLogin() {
  const { user, userDetail } = useUser();
  return computed(() => !!user.value);
  // return user?.isPersonal ? !!user : !!user && !!enterpriseInfo;
}
 
type UseAuthOptions = {
  needAuth?: boolean;
};
 
export function useAuth(options: UseAuthOptions = {}) {
  const { needAuth = true } = options;
  const userStore = useUserStore();
 
  const isLogin = useIsLogin();
 
  const isAuth = computed(() => !needAuth || isLogin.value);
 
  const router = Taro.useRouter();
 
  Taro.useReady(async () => {
    if (isLogin.value && userStore.firstGetUserDetail) {
      // userStore.getCurrentUserInfo();
    }
    if (needAuth && !isLogin.value) {
      Taro.navigateTo({
        url: `${RouterPath.authorization}?redirect=${router.path}&${object2query(router.params)}`,
      });
    }
  });
 
  return { isAuth };
}
 
export function useGoLogin() {
  const router = Taro.useRouter();
 
  function goLoginFn() {
    Taro.navigateTo({
      url: `${RouterPath.authorization}?redirect=${router.path}&${object2query(router.params)}`,
    });
  }
 
  return {
    goLoginFn,
  };
}