Commit 34f3e685584b481d8bd58aaacde8a8b8ed43e434

Authored by xingyu
1 parent dbfc485b

fix: dict map

yudao-ui-admin-vue3/src/store/modules/dict.ts
... ... @@ -66,6 +66,12 @@ export const useDictStore = defineStore('dict', {
66 66 wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
67 67 }
68 68 },
  69 + getDictByType(type: string) {
  70 + if (!this.isSetDict) {
  71 + this.setDictMap()
  72 + }
  73 + return this.dictMap[type]
  74 + },
69 75 async resetDict() {
70 76 wsCache.delete(CACHE_KEY.DICT_CACHE)
71 77 const res = await listSimpleDictDataApi()
... ...
yudao-ui-admin-vue3/src/utils/dict.ts
... ... @@ -21,7 +21,7 @@ export interface DictDataType {
21 21 }
22 22  
23 23 export const getDictOptions = (dictType: string) => {
24   - return dictStore.getDictMap[dictType]
  24 + return dictStore.getDictByType(dictType)
25 25 }
26 26  
27 27 export const getIntDictOptions = (dictType: string) => {
... ...
yudao-ui-admin-vue3/src/views/system/post/index.vue
... ... @@ -9,7 +9,7 @@
9 9 preIcon="ep:zoom-in"
10 10 :title="t('action.add')"
11 11 v-hasPermi="['system:post:create']"
12   - @click="handleCreate()"
  12 + @click="openModel('create')"
13 13 />
14 14 <!-- 操作:导出 -->
15 15 <XButton
... ... @@ -24,21 +24,18 @@
24 24 <!-- 操作:修改 -->
25 25 <XTextButton
26 26 preIcon="ep:edit"
27   - :title="t('action.edit')"
28 27 v-hasPermi="['system:post:update']"
29   - @click="handleUpdate(row.id)"
  28 + @click="openModel('update', row.id)"
30 29 />
31 30 <!-- 操作:详情 -->
32 31 <XTextButton
33 32 preIcon="ep:view"
34   - :title="t('action.detail')"
35 33 v-hasPermi="['system:post:query']"
36   - @click="handleDetail(row.id)"
  34 + @click="openModel('detail', row.id)"
37 35 />
38 36 <!-- 操作:删除 -->
39 37 <XTextButton
40 38 preIcon="ep:delete"
41   - :title="t('action.del')"
42 39 v-hasPermi="['system:post:delete']"
43 40 @click="deleteData(row.id)"
44 41 />
... ... @@ -103,34 +100,20 @@ const actionLoading = ref(false) // 按钮 Loading
103 100 const formRef = ref<FormExpose>() // 表单 Ref
104 101 const detailData = ref() // 详情 Ref
105 102  
106   -// 设置标题
107   -const setDialogTile = (type: string) => {
  103 +const openModel = async (type: string, rowId?: number) => {
108 104 modelLoading.value = true
109 105 modelTitle.value = t('action.' + type)
110 106 actionType.value = type
111 107 modelVisible.value = true
112   -}
113   -
114   -// 新增操作
115   -const handleCreate = () => {
116   - setDialogTile('create')
117   - modelLoading.value = false
118   -}
119   -
120   -// 修改操作
121   -const handleUpdate = async (rowId: number) => {
122   - setDialogTile('update')
123 108 // 设置数据
124   - const res = await PostApi.getPostApi(rowId)
125   - unref(formRef)?.setValues(res)
126   - modelLoading.value = false
127   -}
128   -
129   -// 详情操作
130   -const handleDetail = async (rowId: number) => {
131   - setDialogTile('detail')
132   - const res = await PostApi.getPostApi(rowId)
133   - detailData.value = res
  109 + if (rowId) {
  110 + const res = await PostApi.getPostApi(rowId)
  111 + if (type === 'update') {
  112 + unref(formRef)?.setValues(res)
  113 + } else if (type === 'detail') {
  114 + detailData.value = res
  115 + }
  116 + }
134 117 modelLoading.value = false
135 118 }
136 119  
... ... @@ -155,7 +138,7 @@ const submitForm = async () =&gt; {
155 138 } finally {
156 139 actionLoading.value = false
157 140 // 刷新列表
158   - await reload()
  141 + reload()
159 142 }
160 143 }
161 144 })
... ...