import * as settingServices from '@12333/services/api/Setting';
|
import { useQuery } from '@tanstack/vue-query';
|
import { MaybeRef, Ref, unref } from 'vue';
|
import { BusinessSettingType, TempFolderPath } from '@12333/constants';
|
|
type UseBusinessSettingByTypeOptions<T extends object = object, TData = T> = {
|
type?: MaybeRef<BusinessSettingType>;
|
select?: (data: T) => TData;
|
};
|
|
export function useBusinessSettingByType<T extends object = object, TData = T>(
|
options: UseBusinessSettingByTypeOptions = {}
|
) {
|
const { type, select } = options;
|
|
const { data: businessSetting } = useQuery({
|
queryKey: ['settingServices/getBusinessSettingByType', type],
|
queryFn: async () => {
|
return await settingServices.getBusinessSettingByType(
|
{
|
type: unref(type),
|
},
|
{ showLoading: false }
|
);
|
},
|
placeholderData: () => ({} as T),
|
staleTime: Infinity,
|
select,
|
});
|
|
return {
|
businessSetting: businessSetting as Ref<TData>,
|
};
|
}
|
|
type UserCertificationSetting = {
|
enterprisePowerAttorneyTempPath: string;
|
authenticationHelpUrl: string;
|
idPhoteTempPath: string;
|
payAmount: number;
|
receivingAccount: string;
|
receivingCompanyName: string;
|
receivingBankName: string;
|
offlinePayEndTime: string;
|
offlinePayEndDays: number;
|
};
|
|
export function useUserCertificationSetting() {
|
const { businessSetting } = useBusinessSettingByType<UserCertificationSetting>({
|
type: BusinessSettingType.UserCertification,
|
select(data: any) {
|
return {
|
...data,
|
enterprisePowerAttorneyTempPath: `${TempFolderPath}${data.enterprisePowerAttorneyTempPath}`,
|
idPhoteTempPath: `${TempFolderPath}${data.idPhoteTempPath}`,
|
payAmount: data.userCertificationAmount,
|
};
|
},
|
});
|
return {
|
userCertificationSetting: businessSetting,
|
};
|
}
|