From a69bf92c8907eb1fed227afb156ff0e1c5821c24 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期日, 19 十月 2025 16:16:12 +0800
Subject: [PATCH] fix: bug
---
packages/hooks/dic.ts | 207 +++++++++++++++++++++++++--------------------------
1 files changed, 102 insertions(+), 105 deletions(-)
diff --git a/packages/hooks/dic.ts b/packages/hooks/dic.ts
index c4fedbc..bb28a9f 100644
--- a/packages/hooks/dic.ts
+++ b/packages/hooks/dic.ts
@@ -1,134 +1,131 @@
-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, computed } 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.SelectOptionGuidGetDictionaryCategorySelectQueryOption[],
});
const queryClient = useQueryClient();
- async function ensureSearchSettingType() {
- return await queryClient.ensureQueryData({
- queryKey: [
- 'searchSettingServices/getTypeSearchSettingList',
- { searchType: searchType, belongType: belongType },
- ],
+ function ensureQueryData() {
+ return queryClient.ensureQueryData<
+ API.SelectOptionGuidGetDictionaryCategorySelectQueryOption[]
+ >({
+ 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.data?.id === id);
+ }
+
+ function getDictionaryCategoryByCode(code: string) {
+ return dictionaryCategoryList.value.find((x) => x.data?.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>;
+ parentId?: MaybeRef<string>;
+ staleTime?: number;
+ /** 鍏抽敭瀛� */
+ keywords?: MaybeRef<string>;
+ /** 鏌ヨ鎵�鏈� */
+ all?: MaybeRef<boolean>;
+ maxDeep?: number;
};
-export function useAllSearchSettingList(options: UseAllSearchSettingList) {
- const { enabled = true, ...params } = options;
-
- const { data: allSearchSettingList } = useQuery({
- queryKey: ['searchSettingServices/getAllSearchSettingList', params],
+export function useDictionaryDataSelect({
+ categoryId,
+ categoryCode,
+ parentId,
+ staleTime,
+ keywords,
+ all,
+ maxDeep,
+}: UseDictionaryDataSelectOptions) {
+ const params = computed(() => ({
+ categoryId: unref(categoryId),
+ categoryCode: unref(categoryCode),
+ parentId: unref(parentId),
+ keywords: unref(keywords),
+ all: unref(all),
+ maxDeep: maxDeep,
+ }));
+ const { data: dictionaryDataList, refetch } = useQuery({
+ queryKey: ['dictionaryServices/getDictionaryDataSelect', params],
queryFn: async () => {
- return await searchSettingServices.getAllSearchSettingList(params, { showLoading: false });
- },
- initialData: () => [] as API.GetSearchSettingList[],
- enabled,
- });
-
- 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),
- });
+ let res = await dictionaryServices.getDictionaryDataSelect(params.value, {
+ showLoading: false,
});
- return list;
- }
- return [];
+ return res.map((x) => ({
+ ...x,
+ code: x.data?.code ?? '',
+ }));
+ },
+ placeholderData: () => [] as API.SelectOptionStringGetDictionaryDataSelectQueryResultOption[],
+ staleTime,
});
- 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.data?.id === id)?.label;
}
- const MaxSelectWorkOfTypeLimit = 6;
+ function getDictionaryDataByCode(code: string) {
+ return dictionaryDataList.value?.find((x) => x.data?.code === code);
+ }
+
+ function getDictionaryDataNameByCode(code: string) {
+ return getDictionaryDataByCode(code)?.label ?? '';
+ }
+
+ const queryClient = useQueryClient();
+
+ function ensureQueryData() {
+ return queryClient.ensureQueryData<
+ API.SelectOptionStringGetDictionaryDataSelectQueryResultOption[]
+ >({
+ queryKey: ['dictionaryServices/getDictionaryDataSelect'],
+ });
+ }
+
+ function updateDictionaryDataSelect(categoryId?: string) {
+ queryClient.invalidateQueries({
+ queryKey: ['dictionaryServices/getDictionaryDataSelect'],
+ });
+ }
return {
- workOfTypeList: workOfTypeList,
- flattenWorkOfTypeList,
- workOfTypeRecommendList,
- getWorkOfTypeNameById,
- MaxSelectWorkOfTypeLimit,
+ dictionaryDataList,
+ ensureQueryData,
+ refetch,
+ getDictionaryDataNameById,
+ getDictionaryDataNameByCode,
+ getDictionaryDataByCode,
+ updateDictionaryDataSelect,
};
}
--
Gitblit v1.9.1