|  |  |  | 
|---|
|  |  |  | import * as userServices from '@12333/services/api/User'; | 
|---|
|  |  |  | import * as electronSignServices from '@12333/services/apiV2/electronSign'; | 
|---|
|  |  |  | import { useQuery, useQueryClient } from '@tanstack/vue-query'; | 
|---|
|  |  |  | import { getUserCertificationFrontStatusAdapter } from '@12333/utils'; | 
|---|
|  |  |  | import { UserCertificationFrontStatus } from '@12333/constants'; | 
|---|
|  |  |  | import { useUser } from './user'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | type UseMyCertificationAuditInfoOptions = { | 
|---|
|  |  |  | onSuccess?: (data: API.MyCertificationAuditDto) => void; | 
|---|
|  |  |  | onSuccess?: (data: API.GetPersonalUserRealResultQueryResult) => void; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export function useMyCertificationAuditInfo(options: UseMyCertificationAuditInfoOptions = {}) { | 
|---|
|  |  |  | 
|---|
|  |  |  | const queryClient = useQueryClient(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { data, isLoading } = useQuery({ | 
|---|
|  |  |  | queryKey: ['userServices/getMyCertificationAuditInfo'], | 
|---|
|  |  |  | queryKey: ['electronSignServices/getPersonalUserRealResult'], | 
|---|
|  |  |  | queryFn: async () => { | 
|---|
|  |  |  | return await userServices.getMyCertificationAuditInfo({ showLoading: false }); | 
|---|
|  |  |  | return await electronSignServices.getPersonalUserRealResult({}, { showLoading: false }); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | placeholderData: () => null as API.MyCertificationAuditDto, | 
|---|
|  |  |  | placeholderData: () => null as API.GetPersonalUserRealResultQueryResult, | 
|---|
|  |  |  | select(data) { | 
|---|
|  |  |  | if (data) { | 
|---|
|  |  |  | data.frontStatus = getUserCertificationFrontStatusAdapter(data.status, data.auditStatus); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | onSuccess(data) { | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否有审核单 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | const hasAduit = computed(() => { | 
|---|
|  |  |  | return data && !!data.value?.currentUserCertificationAuditId; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const isCertified = computed( | 
|---|
|  |  |  | () => data?.value?.frontStatus === UserCertificationFrontStatus.Certified | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | const isExpired = computed( | 
|---|
|  |  |  | () => data?.value?.frontStatus === UserCertificationFrontStatus.Expired | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function invalidateCertificationAuditInfo() { | 
|---|
|  |  |  | updateUserInfo(); | 
|---|
|  |  |  | return queryClient.invalidateQueries({ | 
|---|
|  |  |  | queryKey: ['userServices/getMyCertificationAuditInfo'], | 
|---|
|  |  |  | queryKey: ['electronSignServices/getPersonalUserRealResult'], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function ensureCertificationAuditInfo() { | 
|---|
|  |  |  | return queryClient.ensureQueryData({ | 
|---|
|  |  |  | queryKey: ['userServices/getMyCertificationAuditInfo'], | 
|---|
|  |  |  | queryKey: ['electronSignServices/getPersonalUserRealResult'], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return { | 
|---|
|  |  |  | myCertificationAuditInfo: data, | 
|---|
|  |  |  | isLoading, | 
|---|
|  |  |  | hasAduit, | 
|---|
|  |  |  | invalidateCertificationAuditInfo, | 
|---|
|  |  |  | isCertified, | 
|---|
|  |  |  | isExpired, | 
|---|
|  |  |  | ensureCertificationAuditInfo, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | } | 
|---|