|
|
@@ -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 };
|