tongshangming преди 3 години
родител
ревизия
9b9836638e
променени са 3 файла, в които са добавени 39 реда и са изтрити 1 реда
  1. 27 0
      src/stores/dict.ts
  2. 12 0
      src/utils/dict.ts
  3. 0 1
      vite.config.ts

+ 27 - 0
src/stores/dict.ts

@@ -0,0 +1,27 @@
+import { getDictByType } from '@/api/dict'
+
+export const useDictStore = defineStore('dict', () => {
+  const dict = ref<any>({})
+
+  const setDict = (dictRes: any) => {
+    dict.value = { ...dict.value, ...dictRes }
+  }
+
+  const getDict = async (type: string) => {
+    if (dict.value[type] && dict.value[type].length) {
+      return dict.value[type]
+    } else {
+      const res: any = await getDictByType({ type })
+      setDict({
+        [type]: res.list
+      })
+      return dict.value[type]
+    }
+  }
+
+  return {
+    dict,
+    setDict,
+    getDict
+  }
+})

+ 12 - 0
src/utils/dict.ts

@@ -0,0 +1,12 @@
+import { useDictStore } from '@/stores/dict'
+
+export const getDict = async (type: string) => {
+  const dictStore = useDictStore()
+  const dict = await dictStore.getDict(type)
+  return dict
+}
+
+export const filterDict = (value: string, options: Array<any>) => {
+  const dict = options && options.filter(item => item.value === value)
+  return dict && dict[0]?.label
+}

+ 0 - 1
vite.config.ts

@@ -41,7 +41,6 @@ export default defineConfig(({ mode }) => {
     server: {
       proxy: {
         [env.VITE_BASE_API]: {
-          // target: 'https://yunji.sxidc.com',
           target: env.VITE_BASE_PATH,
           changeOrigin: true
         }