From 03ffdd67fc4c40f3e9443931a0aa55e508182873 Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期三, 06 八月 2025 17:00:06 +0800
Subject: [PATCH] feat: 字典

---
 src/hooks/dic.ts |  134 +++++++++++++++++++++++++++++++-------------
 1 files changed, 94 insertions(+), 40 deletions(-)

diff --git a/src/hooks/dic.ts b/src/hooks/dic.ts
index d55c72f..8935320 100644
--- a/src/hooks/dic.ts
+++ b/src/hooks/dic.ts
@@ -1,55 +1,109 @@
-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<string>;
+};
+
+export function useDictionaryDataSelect({
+  categoryId,
+  categoryCode,
+}: UseDictionaryDataSelectOptions) {
+  const { data: dictionaryDataList, refetch } = useQuery({
+    queryKey: ['dictionaryServices/getDictionaryDataSelect'],
+    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[],
+
+    enabled: !!unref(categoryId) || !!unref(categoryCode),
+  });
+
+  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,
   };
 }

--
Gitblit v1.9.1