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