| | |
| | | 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 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, |
| | | }; |
| | | } |
| | | |
| | | 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'], |
| | | }); |
| | | } |
| | | |
| | | return { |
| | | dictionaryDataList, |
| | | ensureQueryData, |
| | | refetch, |
| | | getDictionaryDataNameById, |
| | | getDictionaryDataNameByCode, |
| | | getDictionaryDataByCode, |
| | | }; |
| | | } |