使用字典配置替换枚举.
This commit is contained in:
@@ -8,6 +8,7 @@ export default defineStore('dict', {
|
||||
actions: {
|
||||
// 加载字典值
|
||||
async loadKeys(keys: string[]) {
|
||||
console.log('loadKeys', keys);
|
||||
// 检查是否存在
|
||||
const unloadKeys = keys.filter(key => !this.$state.hasOwnProperty(key));
|
||||
if (!unloadKeys.length) {
|
||||
@@ -18,6 +19,8 @@ export default defineStore('dict', {
|
||||
const { data } = await getDictValueList(unloadKeys);
|
||||
this.$patch(data as object);
|
||||
} catch (e) {
|
||||
} finally {
|
||||
console.log('final');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -33,9 +36,11 @@ export default defineStore('dict', {
|
||||
defaultValue = value) {
|
||||
for (let dictValue of this.$state[dict] || []) {
|
||||
if (dictValue.value === value) {
|
||||
console.log(dictValue[key]);
|
||||
return dictValue[key];
|
||||
}
|
||||
}
|
||||
console.log('default', dict);
|
||||
return defaultValue;
|
||||
},
|
||||
|
||||
|
||||
@@ -25,11 +25,15 @@
|
||||
import DictKeyTable from './components/dict-key-table.vue';
|
||||
import DictKeyFormModal from './components/dict-key-form-modal.vue';
|
||||
import DictKeyViewModal from './components/dict-key-view-modal.vue';
|
||||
import { useDictStore } from '@/store';
|
||||
import { dictKeys } from './types/const';
|
||||
|
||||
const table = ref();
|
||||
const modal = ref();
|
||||
const view = ref();
|
||||
|
||||
useDictStore().loadKeys(dictKeys);
|
||||
|
||||
// 添加回调
|
||||
const modalAddCallback = () => {
|
||||
table.value.addedCallback();
|
||||
|
||||
@@ -1,27 +1,38 @@
|
||||
import { ValueTypeEnum } from './enum.types';
|
||||
// 配置值类型定义
|
||||
export const ValueType = {
|
||||
STRING: 'STRING',
|
||||
INTEGER: 'INTEGER',
|
||||
DECIMAL: 'DECIMAL',
|
||||
BOOLEAN: 'BOOLEAN',
|
||||
COLOR: 'COLOR',
|
||||
};
|
||||
|
||||
/**
|
||||
* 快捷定义字段
|
||||
*/
|
||||
export const definedExtraKeys = [{
|
||||
name: 'disabled',
|
||||
type: ValueTypeEnum.BOOLEAN.value
|
||||
}, {
|
||||
name: 'status',
|
||||
type: ValueTypeEnum.STRING.value
|
||||
}, {
|
||||
name: 'type',
|
||||
type: ValueTypeEnum.STRING.value
|
||||
}, {
|
||||
name: 'color',
|
||||
type: ValueTypeEnum.COLOR.value
|
||||
}];
|
||||
// 快捷定义字段
|
||||
export const definedExtraKeys = [
|
||||
{
|
||||
name: 'disabled',
|
||||
type: ValueType.BOOLEAN
|
||||
}, {
|
||||
name: 'status',
|
||||
type: ValueType.STRING
|
||||
}, {
|
||||
name: 'type',
|
||||
type: ValueType.STRING
|
||||
}, {
|
||||
name: 'color',
|
||||
type: ValueType.COLOR
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* 内置字段
|
||||
*/
|
||||
// 内置字段
|
||||
export const innerKeys = ['value', 'label'];
|
||||
|
||||
// 菜单配置值类型 字典项
|
||||
export const dictValueTypeKey = 'dictValueType';
|
||||
|
||||
// 加载的字典值
|
||||
export const dictKeys = [dictValueTypeKey];
|
||||
|
||||
/**
|
||||
* 额外参数类型
|
||||
*/
|
||||
|
||||
@@ -204,16 +204,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 关闭
|
||||
// 关闭回调
|
||||
const handleClose = () => {
|
||||
handlerClear();
|
||||
if (isAddHandle.value) {
|
||||
// 关闭后设置排序 -10 下次进入的排序字段会保持不变
|
||||
formModel.value.sort = (formModel.value.sort || 0) - 10;
|
||||
} else {
|
||||
// 关闭后设置排序为 0 下次进入的排序字段为 10
|
||||
if (!isAddHandle.value) {
|
||||
// 修改关闭后设置排序为 0 下次进入的排序字段为 10
|
||||
formModel.value.sort = 0;
|
||||
}
|
||||
handlerClear();
|
||||
};
|
||||
|
||||
// 清空
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { MenuQueryRequest, MenuQueryResponse } from '@/api/system/menu';
|
||||
import { reactive, ref } from 'vue';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import { getMenuList, deleteMenu, updateMenuStatus, initCache } from '@/api/system/menu';
|
||||
import { menuStatusKey, menuVisibleKey, menuTypeKey, MenuType } from '../types/const';
|
||||
@@ -281,7 +281,10 @@
|
||||
setFetchLoading(false);
|
||||
}
|
||||
};
|
||||
loadMenuData();
|
||||
|
||||
onMounted(() => {
|
||||
loadMenuData();
|
||||
});
|
||||
|
||||
// 重置菜单
|
||||
const resetForm = () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="layout-container">
|
||||
<div class="layout-container" v-if="render">
|
||||
<!-- 表格 -->
|
||||
<menu-table ref="table"
|
||||
@openAdd="(e) => modal.openAdd(e)"
|
||||
@@ -20,16 +20,22 @@
|
||||
<script lang="ts" setup>
|
||||
import MenuTable from '@/views/system/menu/components/menu-table.vue';
|
||||
import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue';
|
||||
|
||||
import { onUnmounted, ref } from 'vue';
|
||||
import { onBeforeMount, onUnmounted, ref } from 'vue';
|
||||
import { useCacheStore, useDictStore } from '@/store';
|
||||
import { dictKeys } from './types/const';
|
||||
|
||||
const table = ref();
|
||||
const modal = ref();
|
||||
// FIXME
|
||||
const render = ref(false);
|
||||
|
||||
// FIXME
|
||||
// 加载字典项
|
||||
useDictStore().loadKeys(dictKeys);
|
||||
onBeforeMount(async () => {
|
||||
const dictStore = useDictStore();
|
||||
await dictStore.loadKeys(dictKeys);
|
||||
render.value = true;
|
||||
});
|
||||
|
||||
// 卸载时清除 menu cache
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -36,4 +36,5 @@ export const menuVisibleKey = 'systemMenuVisible';
|
||||
// 是否缓存 字典项
|
||||
export const menuCacheKey = 'systemMenuCache';
|
||||
|
||||
// 加载的字典值
|
||||
export const dictKeys = [menuTypeKey, menuStatusKey, menuVisibleKey, menuCacheKey];
|
||||
|
||||
Reference in New Issue
Block a user