Commit 34f3e685584b481d8bd58aaacde8a8b8ed43e434
1 parent
dbfc485b
fix: dict map
Showing
3 changed files
with
20 additions
and
31 deletions
yudao-ui-admin-vue3/src/store/modules/dict.ts
| @@ -66,6 +66,12 @@ export const useDictStore = defineStore('dict', { | @@ -66,6 +66,12 @@ export const useDictStore = defineStore('dict', { | ||
| 66 | wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 | 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 | async resetDict() { | 75 | async resetDict() { |
| 70 | wsCache.delete(CACHE_KEY.DICT_CACHE) | 76 | wsCache.delete(CACHE_KEY.DICT_CACHE) |
| 71 | const res = await listSimpleDictDataApi() | 77 | const res = await listSimpleDictDataApi() |
yudao-ui-admin-vue3/src/utils/dict.ts
| @@ -21,7 +21,7 @@ export interface DictDataType { | @@ -21,7 +21,7 @@ export interface DictDataType { | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | export const getDictOptions = (dictType: string) => { | 23 | export const getDictOptions = (dictType: string) => { |
| 24 | - return dictStore.getDictMap[dictType] | 24 | + return dictStore.getDictByType(dictType) |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | export const getIntDictOptions = (dictType: string) => { | 27 | export const getIntDictOptions = (dictType: string) => { |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | preIcon="ep:zoom-in" | 9 | preIcon="ep:zoom-in" |
| 10 | :title="t('action.add')" | 10 | :title="t('action.add')" |
| 11 | v-hasPermi="['system:post:create']" | 11 | v-hasPermi="['system:post:create']" |
| 12 | - @click="handleCreate()" | 12 | + @click="openModel('create')" |
| 13 | /> | 13 | /> |
| 14 | <!-- 操作:导出 --> | 14 | <!-- 操作:导出 --> |
| 15 | <XButton | 15 | <XButton |
| @@ -24,21 +24,18 @@ | @@ -24,21 +24,18 @@ | ||
| 24 | <!-- 操作:修改 --> | 24 | <!-- 操作:修改 --> |
| 25 | <XTextButton | 25 | <XTextButton |
| 26 | preIcon="ep:edit" | 26 | preIcon="ep:edit" |
| 27 | - :title="t('action.edit')" | ||
| 28 | v-hasPermi="['system:post:update']" | 27 | v-hasPermi="['system:post:update']" |
| 29 | - @click="handleUpdate(row.id)" | 28 | + @click="openModel('update', row.id)" |
| 30 | /> | 29 | /> |
| 31 | <!-- 操作:详情 --> | 30 | <!-- 操作:详情 --> |
| 32 | <XTextButton | 31 | <XTextButton |
| 33 | preIcon="ep:view" | 32 | preIcon="ep:view" |
| 34 | - :title="t('action.detail')" | ||
| 35 | v-hasPermi="['system:post:query']" | 33 | v-hasPermi="['system:post:query']" |
| 36 | - @click="handleDetail(row.id)" | 34 | + @click="openModel('detail', row.id)" |
| 37 | /> | 35 | /> |
| 38 | <!-- 操作:删除 --> | 36 | <!-- 操作:删除 --> |
| 39 | <XTextButton | 37 | <XTextButton |
| 40 | preIcon="ep:delete" | 38 | preIcon="ep:delete" |
| 41 | - :title="t('action.del')" | ||
| 42 | v-hasPermi="['system:post:delete']" | 39 | v-hasPermi="['system:post:delete']" |
| 43 | @click="deleteData(row.id)" | 40 | @click="deleteData(row.id)" |
| 44 | /> | 41 | /> |
| @@ -103,34 +100,20 @@ const actionLoading = ref(false) // 按钮 Loading | @@ -103,34 +100,20 @@ const actionLoading = ref(false) // 按钮 Loading | ||
| 103 | const formRef = ref<FormExpose>() // 表单 Ref | 100 | const formRef = ref<FormExpose>() // 表单 Ref |
| 104 | const detailData = ref() // 详情 Ref | 101 | const detailData = ref() // 详情 Ref |
| 105 | 102 | ||
| 106 | -// 设置标题 | ||
| 107 | -const setDialogTile = (type: string) => { | 103 | +const openModel = async (type: string, rowId?: number) => { |
| 108 | modelLoading.value = true | 104 | modelLoading.value = true |
| 109 | modelTitle.value = t('action.' + type) | 105 | modelTitle.value = t('action.' + type) |
| 110 | actionType.value = type | 106 | actionType.value = type |
| 111 | modelVisible.value = true | 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 | modelLoading.value = false | 117 | modelLoading.value = false |
| 135 | } | 118 | } |
| 136 | 119 | ||
| @@ -155,7 +138,7 @@ const submitForm = async () => { | @@ -155,7 +138,7 @@ const submitForm = async () => { | ||
| 155 | } finally { | 138 | } finally { |
| 156 | actionLoading.value = false | 139 | actionLoading.value = false |
| 157 | // 刷新列表 | 140 | // 刷新列表 |
| 158 | - await reload() | 141 | + reload() |
| 159 | } | 142 | } |
| 160 | } | 143 | } |
| 161 | }) | 144 | }) |