|
|
@@ -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
|
|
|
+ }
|
|
|
+})
|