From 61c935836c947aaf3421731045d024d064cc6688 Mon Sep 17 00:00:00 2001 From: wupengfei <834520024@qq.com> Date: 星期四, 07 八月 2025 13:33:16 +0800 Subject: [PATCH] feat: 企业 --- src/hooks/dic.ts | 146 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 106 insertions(+), 40 deletions(-) diff --git a/src/hooks/dic.ts b/src/hooks/dic.ts index d55c72f..8543fa8 100644 --- a/src/hooks/dic.ts +++ b/src/hooks/dic.ts @@ -1,55 +1,121 @@ -import * as searchSettingServices from '@/services/api/SearchSetting'; -import { useQuery } from '@tanstack/vue-query'; -import { useQueryClient } from '@tanstack/vue-query'; -import { SearchType } from '@/constants'; +import { useQuery, useQueryClient } from '@tanstack/vue-query'; +import * as dictionaryServices from '@/services/api/dictionary'; -type UseSearchSettingTypeOptions = { - searchType: number; - belongType?: number; - onSuccess?: (data: API.GetTypeSearchSettingList[]) => any; -}; - -export function useSearchSettingType({ - searchType, - belongType = null, - onSuccess, -}: UseSearchSettingTypeOptions) { - const { data, refetch } = useQuery({ - queryKey: ['searchSettingServices/getTypeSearchSettingList', { searchType, belongType }], +export function useGetDictionaryCategorySelect() { + const { data: dictionaryCategoryList, refetch } = useQuery({ + queryKey: ['dictionaryServices/getDictionaryCategorySelect'], queryFn: async () => { - return await searchSettingServices.getTypeSearchSettingList( - { - searchType: searchType, - belongType: belongType, - }, - { showLoading: false } - ); + let res = await dictionaryServices.getDictionaryCategorySelect({}, { showLoading: false }); + return res.map((x) => ({ + ...x, + fieldNamesMap: x.data.fieldNames ? JSON.parse(x.data.fieldNames) : {}, + })); }, - placeholderData: () => [] as API.GetTypeSearchSettingList[], - onSuccess(data) { - onSuccess?.(data); - }, + placeholderData: () => + [] as API.SelectQueryResultOptionGuidGetDictionaryCategorySelectQueryOption[], }); const queryClient = useQueryClient(); - async function ensureSearchSettingType() { - return await queryClient.ensureQueryData({ - queryKey: [ - 'searchSettingServices/getTypeSearchSettingList', - { searchType: searchType, belongType: belongType }, - ], + function ensureQueryData() { + return queryClient.ensureQueryData< + API.SelectQueryResultOptionGuidGetDictionaryCategorySelectQueryOption[] + >({ + queryKey: ['dictionaryServices/getDictionaryCategorySelect'], }); } - function getSearchSettingTypeNameById(id: string) { - return data.value.find((x) => x.id === id)?.name ?? ''; + function updateDictionaryCategorySelect() { + queryClient.invalidateQueries({ + queryKey: ['dictionaryServices/getDictionaryCategorySelect'], + }); + } + + function getDictionaryCategoryById(id: string) { + return dictionaryCategoryList.value.find((x) => x.value === id); + } + + function getDictionaryCategoryByCode(code: string) { + return dictionaryCategoryList.value.find((x) => x.code === code); + } + + function getDictionaryCategoryNameByCode(code: string) { + return getDictionaryCategoryByCode(code)?.label ?? ''; } return { - searchSettingTypeList: data, - ensureSearchSettingType, - refetchSearchSettingType: refetch, - getSearchSettingTypeNameById, + dictionaryCategoryList, + ensureQueryData, + getDictionaryCategoryById, + getDictionaryCategoryNameByCode, + getDictionaryCategoryByCode, + updateDictionaryCategorySelect, + }; +} + +type UseDictionaryDataSelectOptions = { + categoryId?: MaybeRef<string>; + categoryCode?: MaybeRef<CategoryCode>; +}; + +export function useDictionaryDataSelect({ + categoryId, + categoryCode, +}: UseDictionaryDataSelectOptions) { + const { data: dictionaryDataList, refetch } = useQuery({ + queryKey: ['dictionaryServices/getDictionaryDataSelect', categoryId, categoryCode], + queryFn: async () => { + let res = await dictionaryServices.getDictionaryDataSelect( + { + categoryId: unref(categoryId), + categoryCode: unref(categoryCode), + }, + { showLoading: false } + ); + return res.map((x) => ({ + ...x, + code: x.data?.code ?? '', + })); + }, + placeholderData: () => + [] as API.SelectQueryResultOptionGuidGetDictionaryDataSelectQueryResultOption[], + }); + + function getDictionaryDataNameById(id: string) { + return dictionaryDataList.value?.find((x) => x.value === id)?.label; + } + + function getDictionaryDataByCode(code: string) { + return dictionaryDataList.value?.find((x) => x.code === code); + } + + function getDictionaryDataNameByCode(code: string) { + return getDictionaryDataByCode(code)?.label ?? ''; + } + + const queryClient = useQueryClient(); + + function ensureQueryData() { + return queryClient.ensureQueryData< + API.SelectQueryResultOptionGuidGetDictionaryDataSelectQueryResultOption[] + >({ + queryKey: ['dictionaryServices/getDictionaryDataSelect'], + }); + } + + function updateDictionaryDataSelect() { + queryClient.invalidateQueries({ + queryKey: ['dictionaryServices/getDictionaryDataSelect'], + }); + } + + return { + dictionaryDataList, + ensureQueryData, + refetch, + getDictionaryDataNameById, + getDictionaryDataNameByCode, + getDictionaryDataByCode, + updateDictionaryDataSelect, }; } -- Gitblit v1.9.1