| | |
| | | import * as searchSettingServices from '@12333/services/api/SearchSetting'; |
| | | import { useQuery, useQueryClient } from '@tanstack/vue-query'; |
| | | import { SearchType } from '@12333/constants'; |
| | | import { MaybeRef, computed } from 'vue'; |
| | | import * as dictionaryServices from '@12333/services/apiV2/dictionary'; |
| | | import { MaybeRef, unref } from 'vue'; |
| | | import { CategoryCode } from '@12333/constants'; |
| | | |
| | | type UseSearchSettingTypeOptions = { |
| | | searchType: number; |
| | | belongType?: number; |
| | | onSuccess?: (data: API.GetTypeSearchSettingList[]) => any; |
| | | enabled?: MaybeRef<boolean>; |
| | | }; |
| | | |
| | | export function useSearchSettingType({ |
| | | searchType, |
| | | belongType = null, |
| | | onSuccess, |
| | | enabled = true, |
| | | }: 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); |
| | | }, |
| | | enabled, |
| | | 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 UseAllSearchSettingList = API.GetSearchSettingListInput & { |
| | | enabled?: MaybeRef<boolean>; |
| | | type UseDictionaryDataSelectOptions = { |
| | | categoryId?: MaybeRef<string>; |
| | | categoryCode?: MaybeRef<CategoryCode>; |
| | | }; |
| | | |
| | | export function useAllSearchSettingList(options: UseAllSearchSettingList) { |
| | | const { enabled = true, ...params } = options; |
| | | |
| | | const { data: allSearchSettingList } = useQuery({ |
| | | queryKey: ['searchSettingServices/getAllSearchSettingList', params], |
| | | export function useDictionaryDataSelect({ |
| | | categoryId, |
| | | categoryCode, |
| | | }: UseDictionaryDataSelectOptions) { |
| | | const { data: dictionaryDataList, refetch } = useQuery({ |
| | | queryKey: ['dictionaryServices/getDictionaryDataSelect', categoryId, categoryCode], |
| | | queryFn: async () => { |
| | | return await searchSettingServices.getAllSearchSettingList(params, { showLoading: false }); |
| | | let res = await dictionaryServices.getDictionaryDataSelect( |
| | | { |
| | | categoryId: unref(categoryId), |
| | | categoryCode: unref(categoryCode), |
| | | }, |
| | | { showLoading: false } |
| | | ); |
| | | return res.map((x) => ({ |
| | | ...x, |
| | | code: x.data?.code ?? '', |
| | | })); |
| | | }, |
| | | initialData: () => [] as API.GetSearchSettingList[], |
| | | enabled, |
| | | placeholderData: () => |
| | | [] as API.SelectQueryResultOptionGuidGetDictionaryDataSelectQueryResultOption[], |
| | | }); |
| | | |
| | | return { |
| | | allSearchSettingList, |
| | | }; |
| | | } |
| | | |
| | | type UseWorkOfTypeOptions = { |
| | | enabled?: MaybeRef<boolean>; |
| | | }; |
| | | |
| | | export function useWorkOfType(options: UseWorkOfTypeOptions = {}) { |
| | | const { enabled = true } = options; |
| | | |
| | | const { allSearchSettingList: industryCategoryList } = useAllSearchSettingList({ |
| | | searchType: SearchType.IndustryCategory, |
| | | enabled, |
| | | status: true, |
| | | }); |
| | | |
| | | const { allSearchSettingList: flattenWorkOfTypeList } = useAllSearchSettingList({ |
| | | searchType: SearchType.Work, |
| | | enabled, |
| | | status: true, |
| | | }); |
| | | |
| | | const workOfTypeList = computed<API.GetSearchSettingList[]>(() => { |
| | | if (industryCategoryList.value?.length > 0) { |
| | | let list = []; |
| | | industryCategoryList.value.forEach((x) => { |
| | | list.push({ |
| | | ...x, |
| | | children: flattenWorkOfTypeList.value.filter((w) => w.parentId === x.id), |
| | | }); |
| | | }); |
| | | return list; |
| | | } |
| | | return []; |
| | | }); |
| | | |
| | | const workOfTypeRecommendList = computed<API.GetSearchSettingList[]>(() => { |
| | | if (flattenWorkOfTypeList.value?.length > 0) { |
| | | return flattenWorkOfTypeList.value.filter((w) => w.isRecommend); |
| | | } |
| | | return []; |
| | | }); |
| | | |
| | | function getWorkOfTypeNameById(id: string) { |
| | | return flattenWorkOfTypeList.value.find((x) => x.id === id)?.name ?? ''; |
| | | function getDictionaryDataNameById(id: string) { |
| | | return dictionaryDataList.value?.find((x) => x.value === id)?.label; |
| | | } |
| | | |
| | | const MaxSelectWorkOfTypeLimit = 6; |
| | | 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 { |
| | | workOfTypeList: workOfTypeList, |
| | | flattenWorkOfTypeList, |
| | | workOfTypeRecommendList, |
| | | getWorkOfTypeNameById, |
| | | MaxSelectWorkOfTypeLimit, |
| | | dictionaryDataList, |
| | | ensureQueryData, |
| | | refetch, |
| | | getDictionaryDataNameById, |
| | | getDictionaryDataNameByCode, |
| | | getDictionaryDataByCode, |
| | | }; |
| | | } |