Jelajahi Sumber

取值调整

zouzs 1 Minggu lalu
induk
melakukan
e6e8fef8e5
2 mengubah file dengan 56 tambahan dan 3 penghapusan
  1. 41 1
      src/utils/dict.ts
  2. 15 2
      src/views/ipInterfaceCall/index.vue

+ 41 - 1
src/utils/dict.ts

@@ -30,6 +30,10 @@ export function useDict(...args: string[]) {
 export function useDictValue<T>(dictType: T, searchValue: string) {
   if (!isString(searchValue)) searchValue = String(searchValue);
   const dictStore = useDictStore();
+  // 统一触发获取(内存/持久层/后端),不做重复的预检查
+  dictStore.fetchDictByType(dictType as string).catch(error => {
+    console.error(`获取字典${String(dictType)}失败:`, error);
+  });
   const dicts = dictStore.getDict(dictType as string) || [];
   const item = dicts.find((d: any) => d.value === searchValue);
   return item ? item.label : null;
@@ -38,7 +42,43 @@ export function useDictValue<T>(dictType: T, searchValue: string) {
 export function useDictClass<T>(dictType: T, searchValue: string) {
   if (!isString(searchValue)) searchValue = String(searchValue);
   const dictStore = useDictStore();
+  // 统一触发获取(内存/持久层/后端),不做重复的预检查
+  dictStore.fetchDictByType(dictType as string).catch(error => {
+    console.error(`获取字典${String(dictType)}失败:`, error);
+  });
   const dicts = dictStore.getDict(dictType as string) || [];
   const item = dicts.find((d: any) => d.value === searchValue);
   return item ? item.class : null;
-}
+}
+
+export async function useDictValueAsync<T>(
+  dictType: T,
+  searchValue: string
+): Promise<string | null> {
+  if (!isString(searchValue)) searchValue = String(searchValue);
+  const dictStore = useDictStore();
+  try {
+    await dictStore.fetchDictByType(dictType as string);
+  } catch (error) {
+    console.error(`获取字典${String(dictType)}失败:`, error);
+  }
+  const dicts = dictStore.getDict(dictType as string) || [];
+  const item = dicts.find((d: any) => d.value === searchValue);
+  return item ? item.label : null;
+}
+
+export async function useDictClassAsync<T>(
+  dictType: T,
+  searchValue: string
+): Promise<string | null> {
+  if (!isString(searchValue)) searchValue = String(searchValue);
+  const dictStore = useDictStore();
+  try {
+    await dictStore.fetchDictByType(dictType as string);
+  } catch (error) {
+    console.error(`获取字典${String(dictType)}失败:`, error);
+  }
+  const dicts = dictStore.getDict(dictType as string) || [];
+  const item = dicts.find((d: any) => d.value === searchValue);
+  return item ? item.cssClass : null;
+}

+ 15 - 2
src/views/ipInterfaceCall/index.vue

@@ -20,7 +20,7 @@
 </template>
 
 <script lang="ts" setup>
-import { ref } from "vue";
+import { computed, ref } from "vue";
 import {
   type FieldValues,
   type PlusColumn,
@@ -32,6 +32,7 @@ import { isString } from "@pureadmin/utils";
 import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
 import { useRouter } from "vue-router";
 import { getIpInterfaceCallList } from "@/api/system/ipInterfaceCall";
+import { useDict, useDictClass, useDictValue } from "@/utils/dict";
 
 defineOptions({
   name: "IpInterfaceCallIndex"
@@ -41,6 +42,8 @@ const router = useRouter();
 
 const plusPageInstance = ref<PlusPageInstance | null>(null);
 
+const { interface_status } = useDict("interface_status");
+
 const getList = async (query: Record<string, any>) => {
   let res = await getIpInterfaceCallList(query);
   return {
@@ -75,7 +78,17 @@ const tableConfig: PlusColumn[] = [
   {
     label: "调用状态",
     prop: "status",
-    hideInSearch: true
+    hideInSearch: true,
+    valueType: "tag",
+    // options: computed(() => interface_status.value),
+    fieldProps: (value: string) => {
+      return {
+        type: useDictClass("interface_status", value)
+      };
+    },
+    formatter: value => {
+      return useDictValue("interface_status", value);
+    }
   },
   {
     label: "回调状态",