zhengyiming
4 天以前 2935cf3629d1495d959381a1550cddaa500a0986
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { useUserStore } from '@/stores/modules/user';
import Taro from '@tarojs/taro';
import { object2query, LocationUtils } from '@12333/utils';
import { ParkOrHRStatus, UserCertificationFrontStatus } from '@12333/constants';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import { MaybeRef } from 'vue';
import { useRefeshDidShow } from '@12333/hooks/infiniteLoading';
import * as userResumeServices from '@12333/services/apiV2/userResume';
 
export function useUser() {
  const userStore = useUserStore();
 
  const { userDetail, userInfo, locationCity, userId } = 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,
    userId,
  };
}
 
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,
  };
}
 
export function useUserResume() {
  const { userId } = useUser();
 
  const { data, refetch } = useQuery({
    queryKey: ['userResumeServices/getUserResume', userId],
    queryFn: async () => {
      return await userResumeServices.getUserResume(
        { userId: userId.value },
        {
          showLoading: false,
        }
      );
    },
    placeholderData: () => ({} as API.GetUserResumeQueryResult),
    enabled: computed(() => !!userId.value),
  });
 
  return {
    userResumeInfo: data,
    refetch,
  };
}
 
export function useUpdateResume() {
  const queryClient = useQueryClient();
 
  const updateUserResumeCredentials = () => {
    return queryClient.invalidateQueries({
      queryKey: ['userResumeServices/getUserResumeCredentials'],
    });
  };
 
  const updateUserResume = () => {
    return queryClient.invalidateQueries({
      queryKey: ['userResumeServices/getUserResume'],
    });
  };
 
  return {
    updateUserResumeCredentials,
    updateUserResume,
  };
}