| | |
| | | import * as searchSettingServices from '@/services/api/SearchSetting'; |
| | | import { useQuery } from '@tanstack/vue-query'; |
| | | import { useQueryClient } from '@tanstack/vue-query'; |
| | | import { useQuery, useQueryClient } from '@tanstack/vue-query'; |
| | | import { SearchType } from '@/constants'; |
| | | |
| | | type UseSearchSettingTypeOptions = { |
| | | searchType: number; |
| | | belongType?: number; |
| | | onSuccess?: (data: API.GetTypeSearchSettingList[]) => any; |
| | | onSuccess?: (data: any[]) => any; |
| | | }; |
| | | |
| | | export function useSearchSettingType({ |
| | | searchType, |
| | | belongType = null, |
| | | onSuccess, |
| | | }: UseSearchSettingTypeOptions) { |
| | | const { data, refetch } = useQuery({ |
| | | queryKey: ['searchSettingServices/getTypeSearchSettingList', { searchType, belongType }], |
| | | queryFn: async () => { |
| | | return await searchSettingServices.getTypeSearchSettingList( |
| | | { |
| | | searchType: searchType, |
| | | belongType: belongType, |
| | | }, |
| | | { showLoading: false } |
| | | ); |
| | | }, |
| | | placeholderData: () => [] as API.GetTypeSearchSettingList[], |
| | | onSuccess(data) { |
| | | onSuccess?.(data); |
| | | }, |
| | | }); |
| | | |
| | | const queryClient = useQueryClient(); |
| | | |
| | | async function ensureSearchSettingType() { |
| | | return await queryClient.ensureQueryData({ |
| | | queryKey: [ |
| | | 'searchSettingServices/getTypeSearchSettingList', |
| | | { searchType: searchType, belongType: belongType }, |
| | | ], |
| | | }); |
| | | } |
| | | |
| | | function getSearchSettingTypeNameById(id: string) { |
| | | return data.value.find((x) => x.id === id)?.name ?? ''; |
| | | } |
| | | |
| | | return { |
| | | searchSettingTypeList: data, |
| | | ensureSearchSettingType, |
| | | refetchSearchSettingType: refetch, |
| | | getSearchSettingTypeNameById, |
| | | }; |
| | | } |