Kaynağa Gözat

fix: dict map

xingyu 2 yıl önce
ebeveyn
işleme
34f3e68558

+ 6 - 0
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()

+ 1 - 1
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) => {

+ 13 - 30
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')"
         />
         <!-- 操作:导出 -->
         <XButton
@@ -24,21 +24,18 @@
         <!-- 操作:修改 -->
         <XTextButton
           preIcon="ep:edit"
-          :title="t('action.edit')"
           v-hasPermi="['system:post:update']"
-          @click="handleUpdate(row.id)"
+          @click="openModel('update', row.id)"
         />
         <!-- 操作:详情 -->
         <XTextButton
           preIcon="ep:view"
-          :title="t('action.detail')"
           v-hasPermi="['system:post:query']"
-          @click="handleDetail(row.id)"
+          @click="openModel('detail', row.id)"
         />
         <!-- 操作:删除 -->
         <XTextButton
           preIcon="ep:delete"
-          :title="t('action.del')"
           v-hasPermi="['system:post:delete']"
           @click="deleteData(row.id)"
         />
@@ -103,34 +100,20 @@ const actionLoading = ref(false) // 按钮 Loading
 const formRef = ref<FormExpose>() // 表单 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()
       }
     }
   })