From 34f3e685584b481d8bd58aaacde8a8b8ed43e434 Mon Sep 17 00:00:00 2001 From: xingyu Date: Tue, 17 Jan 2023 15:13:23 +0800 Subject: [PATCH] fix: dict map --- yudao-ui-admin-vue3/src/store/modules/dict.ts | 6 +++ yudao-ui-admin-vue3/src/utils/dict.ts | 2 +- .../src/views/system/post/index.vue | 43 ++++++------------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/yudao-ui-admin-vue3/src/store/modules/dict.ts b/yudao-ui-admin-vue3/src/store/modules/dict.ts index 11c79ccb3..4e9ab39c1 100644 --- a/yudao-ui-admin-vue3/src/store/modules/dict.ts +++ b/yudao-ui-admin-vue3/src/store/modules/dict.ts @@ -66,6 +66,12 @@ export const useDictStore = defineStore('dict', { wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 } }, + getDictByType(type: string) { + if (!this.isSetDict) { + this.setDictMap() + } + return this.dictMap[type] + }, async resetDict() { wsCache.delete(CACHE_KEY.DICT_CACHE) const res = await listSimpleDictDataApi() diff --git a/yudao-ui-admin-vue3/src/utils/dict.ts b/yudao-ui-admin-vue3/src/utils/dict.ts index ee08b1419..5e168e301 100644 --- a/yudao-ui-admin-vue3/src/utils/dict.ts +++ b/yudao-ui-admin-vue3/src/utils/dict.ts @@ -21,7 +21,7 @@ export interface DictDataType { } export const getDictOptions = (dictType: string) => { - return dictStore.getDictMap[dictType] + return dictStore.getDictByType(dictType) } export const getIntDictOptions = (dictType: string) => { diff --git a/yudao-ui-admin-vue3/src/views/system/post/index.vue b/yudao-ui-admin-vue3/src/views/system/post/index.vue index 81594343f..08a7ca0be 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/post/index.vue @@ -9,7 +9,7 @@ preIcon="ep:zoom-in" :title="t('action.add')" v-hasPermi="['system:post:create']" - @click="handleCreate()" + @click="openModel('create')" /> @@ -103,34 +100,20 @@ const actionLoading = ref(false) // 按钮 Loading const formRef = ref() // 表单 Ref const detailData = ref() // 详情 Ref -// 设置标题 -const setDialogTile = (type: string) => { +const openModel = async (type: string, rowId?: number) => { modelLoading.value = true modelTitle.value = t('action.' + type) actionType.value = type modelVisible.value = true -} - -// 新增操作 -const handleCreate = () => { - setDialogTile('create') - modelLoading.value = false -} - -// 修改操作 -const handleUpdate = async (rowId: number) => { - setDialogTile('update') // 设置数据 - const res = await PostApi.getPostApi(rowId) - unref(formRef)?.setValues(res) - modelLoading.value = false -} - -// 详情操作 -const handleDetail = async (rowId: number) => { - setDialogTile('detail') - const res = await PostApi.getPostApi(rowId) - detailData.value = res + if (rowId) { + const res = await PostApi.getPostApi(rowId) + if (type === 'update') { + unref(formRef)?.setValues(res) + } else if (type === 'detail') { + detailData.value = res + } + } modelLoading.value = false } @@ -155,7 +138,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - await reload() + reload() } } })