From 92ca6bd9fa4d1dd0cb04834c238aa0f5e9c28385 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期一, 07 七月 2025 16:46:45 +0800 Subject: [PATCH] fix: 江佑保系统健壮性修复 --- src/hooks/dic.ts | 74 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 0 deletions(-) diff --git a/src/hooks/dic.ts b/src/hooks/dic.ts index 3b84750..e206017 100644 --- a/src/hooks/dic.ts +++ b/src/hooks/dic.ts @@ -16,3 +16,77 @@ refetch, }; } + +export function useUserInsureProductSetting() { + const { data: allUserInsureProductSettingList, refetch } = useQuery({ + queryKey: ['dictionaryServices/getUserInsureProductSetting'], + queryFn: async () => { + let res = await dictionaryServices.getUserInsureProductSetting({ showLoading: false }); + return res; + }, + placeholderData: () => [] as API.InsureProductSettingDto[], + }); + + function getInsureProductByIdNumber(productIdNumber: string) { + return allUserInsureProductSettingList.value.find((x) => x.productIdNumber === productIdNumber); + } + + function getInsureProductIdByIdNumber(productIdNumber: string) { + const insureProduct = getInsureProductByIdNumber(productIdNumber); + return insureProduct?.id ?? ''; + } + + const queryClient = useQueryClient(); + + function ensureUserInsureProductSetting() { + return queryClient.ensureQueryData<API.InsureProductSettingDto[]>({ + queryKey: ['dictionaryServices/getUserInsureProductSetting'], + }); + } + + /**鏄惁鏄敓鐓庝繚璐﹀彿 */ + const isSjbAccount = computed(() => allUserInsureProductSettingList.value.length > 0); + + return { + allUserInsureProductSettingList, + getInsureProductByIdNumber, + getInsureProductIdByIdNumber, + refetch, + ensureUserInsureProductSetting, + isSjbAccount, + }; +} + +type UseInsureProductSchemeAllListOptions = { + insureProductId?: MaybeRef<string>; +}; + +export function useInsureProductSchemeAllList(options: UseInsureProductSchemeAllListOptions = {}) { + const { insureProductId } = options; + + const { data: allInsureProductSchemeList, refetch } = useQuery({ + queryKey: ['dictionaryServices/getInsureProductSchemeAllList', insureProductId], + queryFn: async () => { + let res = await dictionaryServices.getInsureProductSchemeAllList( + { + insureProductId: unref(insureProductId), + }, + { showLoading: false } + ); + return res; + }, + placeholderData: () => [] as API.InsureProductSchemeDto[], + enabled: computed(() => !!unref(insureProductId)), + staleTime: Infinity, + }); + + function getInsureProductSchemeByCode(code: string) { + return allInsureProductSchemeList.value.find((x) => x.code === code); + } + + return { + allInsureProductSchemeList, + refetch, + getInsureProductSchemeByCode, + }; +} -- Gitblit v1.9.1