import { useUserStore } from '@/store/modules/user'; 
 | 
import { UserUtils } from '@bole-core/core'; 
 | 
import * as userRoleServices from '@/services/api/UserRole'; 
 | 
import * as userServices from '@/services/api/User'; 
 | 
import { useQuery, useQueryClient } from '@tanstack/vue-query'; 
 | 
import { usePermissionStore } from '@/store/modules/permission'; 
 | 
import { 
 | 
  UserCertificationFrontStatus, 
 | 
  ParkOrHRStatus, 
 | 
  WalletAccountOpenStatusEnum, 
 | 
  SignatureImageStatusEnum, 
 | 
  WalletMainStatusEnum, 
 | 
  WalletAccountTypeEnum, 
 | 
} from '@/constants'; 
 | 
import { isWalletAccountOpen as isWalletAccountOpenUtil } from '@/utils'; 
 | 
  
 | 
export function useIsSystemAdmin() { 
 | 
  const userStore = useUserStore(); 
 | 
  const { accountInfo } = storeToRefs(userStore); 
 | 
  const isSystemAdmin = computed(() => UserUtils.isSystemRole(accountInfo.value)); 
 | 
  return isSystemAdmin; 
 | 
} 
 | 
  
 | 
export function useAllRoleList() { 
 | 
  const { data: allRoleList } = useQuery({ 
 | 
    queryKey: ['userRoleServices/getRoles'], 
 | 
    queryFn: async () => { 
 | 
      let res = await userRoleServices.getRoles({}, { showLoading: false }); 
 | 
      return res.data; 
 | 
    }, 
 | 
  }); 
 | 
  
 | 
  return { 
 | 
    allRoleList, 
 | 
  }; 
 | 
} 
 | 
  
 | 
export function useUser() { 
 | 
  const userStore = useUserStore(); 
 | 
  const permissionStore = usePermissionStore(); 
 | 
  
 | 
  const { userDetail, userInfo } = storeToRefs(userStore); 
 | 
  
 | 
  function updateUserInfo() { 
 | 
    return userStore.getCurrentUserInfo(); 
 | 
  } 
 | 
  
 | 
  function resetAccessRoutes() { 
 | 
    return permissionStore.resetAccessRoutes(); 
 | 
  } 
 | 
  
 | 
  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( 
 | 
    () => userDetail?.value?.frontStatus === UserCertificationFrontStatus.Certified 
 | 
  ); 
 | 
  
 | 
  const isExpired = computed( 
 | 
    () => userDetail?.value?.frontStatus === UserCertificationFrontStatus.Expired 
 | 
  ); 
 | 
  
 | 
  const isWalletAccountOpen = computed(() => { 
 | 
    return isWalletAccountOpenUtil(userDetail?.value?.walletAccountOpenStatus); 
 | 
  }); 
 | 
  
 | 
  const isAlipayWalletAccountOpen = computed(() => { 
 | 
    return ( 
 | 
      userDetail?.value?.walletAccountOpenStatus?.some?.( 
 | 
        (x) => 
 | 
          x.walletAccountOpenStatus === WalletAccountOpenStatusEnum.Enabled && 
 | 
          x.walletAccountType === WalletAccountTypeEnum.AliPay 
 | 
      ) ?? false 
 | 
    ); 
 | 
  }); 
 | 
  
 | 
  const isPangAnWalletAccountOpen = computed(() => { 
 | 
    return ( 
 | 
      userDetail?.value?.walletAccountOpenStatus?.some?.( 
 | 
        (x) => 
 | 
          x.walletAccountOpenStatus === WalletAccountOpenStatusEnum.Enabled && 
 | 
          x.walletAccountType === WalletAccountTypeEnum.PingAn 
 | 
      ) ?? false 
 | 
    ); 
 | 
  }); 
 | 
  
 | 
  const isSignatureOpen = computed( 
 | 
    () => userDetail.value?.signatureImageStatus === SignatureImageStatusEnum.Generated 
 | 
  ); 
 | 
  
 | 
  const isWalletMainNormal = computed(() => { 
 | 
    if (userDetail.value?.walletMainStatus?.length > 0) { 
 | 
      return userDetail.value?.walletMainStatus.some( 
 | 
        (x) => x.walletMainStatus === WalletMainStatusEnum.Normal 
 | 
      ); 
 | 
    } 
 | 
    return false; 
 | 
  }); 
 | 
  
 | 
  return { 
 | 
    user: userInfo, 
 | 
    userDetail: userDetail, 
 | 
    updateUserInfo, 
 | 
    resetAccessRoutes, 
 | 
    isCompanyAudited, 
 | 
    isCompletePersonalInfo, 
 | 
    isCertified, 
 | 
    isExpired, 
 | 
    isWalletAccountOpen, 
 | 
    isSignatureOpen, 
 | 
    isWalletMainNormal, 
 | 
    isAlipayWalletAccountOpen, 
 | 
    isPangAnWalletAccountOpen, 
 | 
  }; 
 | 
} 
 | 
  
 | 
export function useGetAllPlatUserAttestationList() { 
 | 
  const queryClient = useQueryClient(); 
 | 
  
 | 
  const { data: platUserAttestationAllList } = useQuery({ 
 | 
    queryKey: ['userServices/getAllPlatUserAttestationList'], 
 | 
    queryFn: async () => { 
 | 
      let res = await userServices.getAllPlatUserAttestationList({}, { showLoading: false }); 
 | 
      return res; 
 | 
    }, 
 | 
    placeholderData: () => [] as API.AttestationV2Info[], 
 | 
  }); 
 | 
  
 | 
  function ensureAllPlatUserAttestationList() { 
 | 
    return queryClient.ensureQueryData<API.AttestationV2Info[]>({ 
 | 
      queryKey: ['userServices/getAllPlatUserAttestationList'], 
 | 
    }); 
 | 
  } 
 | 
  
 | 
  return { 
 | 
    platUserAttestationAllList, 
 | 
    ensureAllPlatUserAttestationList, 
 | 
  }; 
 | 
} 
 | 
  
 | 
export function useUserGetCertificationList({ params, enabled = true }) { 
 | 
  const { data: userCertificationList, isLoading } = useQuery({ 
 | 
    queryKey: ['userServices/getUserCertificationDropdownDataList', params], 
 | 
    queryFn: async () => { 
 | 
      return await userServices.getUserCertificationDropdownDataList(unref(params), { 
 | 
        showLoading: false, 
 | 
      }); 
 | 
    }, 
 | 
    initialData: () => [] as API.UserCertificationDropdownDataDto[], 
 | 
    enabled, 
 | 
  }); 
 | 
  
 | 
  return { 
 | 
    userCertificationList, 
 | 
    isLoading, 
 | 
  }; 
 | 
} 
 |