Quellcode durchsuchen

配置字典调用方法

@dongkboy vor 1 Jahr
Ursprung
Commit
54603ceaf4
2 geänderte Dateien mit 38 neuen und 3 gelöschten Zeilen
  1. 3 3
      .env.development
  2. 35 0
      src/utils/composables/dictService.ts

+ 3 - 3
.env.development

@@ -1,11 +1,11 @@
 # 应用配置面板
-VITE_APP_SETTING = false
+VITE_APP_SETTING = true
 # 页面标题
 VITE_APP_TITLE = 掌柜运营平台
 # 接口请求地址,会设置到 axios 的 baseURL 参数上
 # VITE_APP_API_BASEURL = http://192.168.0.55:8001  #董鑫
-# VITE_APP_API_BASEURL = http://192.168.0.253:8001  #田智
-VITE_APP_API_BASEURL = http://192.168.0.59:8001  #徐强
+VITE_APP_API_BASEURL = http://192.168.0.253:8001  #田智
+# VITE_APP_API_BASEURL = http://192.168.0.59:8001  #徐强
 
 # 调试工具,可设置 eruda 或 vconsole,如果不需要开启则留空
 VITE_APP_DEBUG_TOOL =

+ 35 - 0
src/utils/composables/dictService.ts

@@ -0,0 +1,35 @@
+// dictService.ts
+import { ref } from 'vue';
+import api from '@/api';
+
+const dictLists = ref<{ [key: string]: any[] }>({});//多个字典集合
+
+// 加载多个字典
+const loadDicts = async (types: string[]): Promise<void> => {
+  const promises = types.map(async (type) => {
+    if (!dictLists.value[type + 'List']) {
+      try {
+        const res: any = await api.toolApi.dictType({ dictCode: type });
+        if (res.code == '200') {
+          dictLists.value[type + 'List'] = res.data.map((item: any) => {
+            return {
+              value: item.value,
+              label: item.label
+            };
+          });
+        }
+      } catch (error) {
+        console.error(`字典类型 ${type} 加载失败:`, error);
+      }
+    }
+  });
+
+  await Promise.all(promises);
+};
+
+// 获取字典数据
+const getDict = (type: string): any[] => {
+  return dictLists.value[type + 'List'] || [];
+};
+
+export { dictLists, loadDicts, getDict };