From 74688ca53567cd9a2d2c2ecc4daa4377dcd03b48 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Fri, 27 Oct 2023 01:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AD=97=E5=85=B8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9B=BF=E6=8D=A2=E6=9E=9A=E4=B8=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orion-ops-ui/src/api/system/dict-value.ts | 2 + orion-ops-ui/src/store/index.ts | 4 +- orion-ops-ui/src/store/modules/dict/index.ts | 66 +++++++++++++++++++ orion-ops-ui/src/store/modules/dict/types.ts | 5 ++ .../asset/host/components/host-card-list.vue | 6 +- .../asset/host/components/host-table.vue | 4 +- .../dict-key/components/dict-key-table.vue | 4 +- .../components/dict-key-view-modal.vue | 1 + .../src/views/system/dict-key/types/const.ts | 3 + .../components/dict-value-form-modal.vue | 11 +++- .../components/dict-value-table.vue | 4 +- .../menu/components/menu-form-modal.vue | 63 ++++++++++-------- .../system/menu/components/menu-table.vue | 40 +++++------ .../menu/components/menu-tree-selector.vue | 5 +- orion-ops-ui/src/views/system/menu/index.vue | 6 +- .../src/views/system/menu/types/const.ts | 38 +++++++++++ .../src/views/system/menu/types/enum.types.ts | 63 ------------------ 17 files changed, 198 insertions(+), 127 deletions(-) delete mode 100644 orion-ops-ui/src/views/system/menu/types/enum.types.ts diff --git a/orion-ops-ui/src/api/system/dict-value.ts b/orion-ops-ui/src/api/system/dict-value.ts index c4de113a..f7534f94 100644 --- a/orion-ops-ui/src/api/system/dict-value.ts +++ b/orion-ops-ui/src/api/system/dict-value.ts @@ -66,6 +66,8 @@ export interface DictValueQueryResponse extends TableData { * 字典配置值选项查询响应 */ export interface DictValueOptionsQueryResponse extends Options { + label: string; + value: string | number | boolean; [key: string]: unknown; } diff --git a/orion-ops-ui/src/store/index.ts b/orion-ops-ui/src/store/index.ts index f20f0842..97ed6920 100644 --- a/orion-ops-ui/src/store/index.ts +++ b/orion-ops-ui/src/store/index.ts @@ -5,7 +5,7 @@ import useUserStore from './modules/user'; import useTabBarStore from './modules/tab-bar'; import useCacheStore from './modules/cache'; import useTipsStore from './modules/tips'; -// import useDictStore from './modules/dict'; +import useDictStore from './modules/dict'; const pinia = createPinia(); @@ -16,7 +16,7 @@ export { useTabBarStore, useCacheStore, useTipsStore, - // useDictStore, + useDictStore, }; export default pinia; diff --git a/orion-ops-ui/src/store/modules/dict/index.ts b/orion-ops-ui/src/store/modules/dict/index.ts index e69de29b..f58eaca1 100644 --- a/orion-ops-ui/src/store/modules/dict/index.ts +++ b/orion-ops-ui/src/store/modules/dict/index.ts @@ -0,0 +1,66 @@ +import type { DictState } from './types'; +import { defineStore } from 'pinia'; +import { getDictValueList } from '@/api/system/dict-value'; + +export default defineStore('dict', { + state: (): DictState => ({}), + + actions: { + // 加载字典值 + async loadKeys(keys: string[]) { + // 检查是否存在 + const unloadKeys = keys.filter(key => !this.$state.hasOwnProperty(key)); + if (!unloadKeys.length) { + return; + } + // 加载未加载的数据 + try { + const { data } = await getDictValueList(unloadKeys); + this.$patch(data as object); + } catch (e) { + } + }, + + // 获取字典选项 + toOptions(key: string) { + return this.$state[key]; + }, + + // 获取选择值 + getDictValue(dict: string, + value: any, + key = 'label', + defaultValue = value) { + for (let dictValue of this.$state[dict] || []) { + if (dictValue.value === value) { + return dictValue[key]; + } + } + return defaultValue; + }, + + // 切换字典值对象 + toggleDictValue(dict: string, + value: any, + key = 'value', + defaultValue = value) { + for (let dictValue of this.$state[dict] || []) { + if (dictValue.value !== value) { + return dictValue[key]; + } + } + return defaultValue; + }, + + // 切换字典值对象 + toggleDict(dict: string, value: any) { + for (let dictValue of this.$state[dict] || []) { + if (dictValue.value !== value) { + return dictValue; + } + } + return {}; + } + + }, +}); diff --git a/orion-ops-ui/src/store/modules/dict/types.ts b/orion-ops-ui/src/store/modules/dict/types.ts index e69de29b..4ce4c8e1 100644 --- a/orion-ops-ui/src/store/modules/dict/types.ts +++ b/orion-ops-ui/src/store/modules/dict/types.ts @@ -0,0 +1,5 @@ +import { DictValueOptionsQueryResponse } from '@/api/system/dict-value'; + +export interface DictState { + [key: string]: Array; +} diff --git a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue index f039ab05..71e525f2 100644 --- a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue +++ b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue @@ -24,7 +24,7 @@ diff --git a/orion-ops-ui/src/views/system/dict-key/components/dict-key-table.vue b/orion-ops-ui/src/views/system/dict-key/components/dict-key-table.vue index 139baa9a..f06e00ac 100644 --- a/orion-ops-ui/src/views/system/dict-key/components/dict-key-table.vue +++ b/orion-ops-ui/src/views/system/dict-key/components/dict-key-table.vue @@ -55,7 +55,9 @@ :bordered="false"> diff --git a/orion-ops-ui/src/views/system/dict-key/components/dict-key-view-modal.vue b/orion-ops-ui/src/views/system/dict-key/components/dict-key-view-modal.vue index ef9948d9..57a99700 100644 --- a/orion-ops-ui/src/views/system/dict-key/components/dict-key-view-modal.vue +++ b/orion-ops-ui/src/views/system/dict-key/components/dict-key-view-modal.vue @@ -50,6 +50,7 @@ // 查看 const { data } = await getDictValueList([keyName]); value.value = JSON.stringify(data[keyName], undefined, 4); + } catch (e) { } finally { setLoading(false); } diff --git a/orion-ops-ui/src/views/system/dict-key/types/const.ts b/orion-ops-ui/src/views/system/dict-key/types/const.ts index 28821e06..a8090953 100644 --- a/orion-ops-ui/src/views/system/dict-key/types/const.ts +++ b/orion-ops-ui/src/views/system/dict-key/types/const.ts @@ -4,6 +4,9 @@ import { ValueTypeEnum } from './enum.types'; * 快捷定义字段 */ export const definedExtraKeys = [{ + name: 'disabled', + type: ValueTypeEnum.BOOLEAN.value +}, { name: 'status', type: ValueTypeEnum.STRING.value }, { diff --git a/orion-ops-ui/src/views/system/dict-value/components/dict-value-form-modal.vue b/orion-ops-ui/src/views/system/dict-value/components/dict-value-form-modal.vue index bda53eb6..0666333c 100644 --- a/orion-ops-ui/src/views/system/dict-value/components/dict-value-form-modal.vue +++ b/orion-ops-ui/src/views/system/dict-value/components/dict-value-form-modal.vue @@ -111,7 +111,7 @@ value: undefined, label: undefined, extra: undefined, - sort: 10, + sort: undefined, }; }; @@ -126,7 +126,7 @@ const openAdd = () => { title.value = '添加字典配置值'; isAddHandle.value = true; - renderForm({ ...defaultForm(), keyId: formModel.value.keyId }); + renderForm({ ...defaultForm(), keyId: formModel.value.keyId, sort: (formModel.value.sort || 0) + 10 }); setVisible(true); }; @@ -207,6 +207,13 @@ // 关闭 const handleClose = () => { handlerClear(); + if (isAddHandle.value) { + // 关闭后设置排序 -10 下次进入的排序字段会保持不变 + formModel.value.sort = (formModel.value.sort || 0) - 10; + } else { + // 关闭后设置排序为 0 下次进入的排序字段为 10 + formModel.value.sort = 0; + } }; // 清空 diff --git a/orion-ops-ui/src/views/system/dict-value/components/dict-value-table.vue b/orion-ops-ui/src/views/system/dict-value/components/dict-value-table.vue index 8b4dd342..f84cecce 100644 --- a/orion-ops-ui/src/views/system/dict-value/components/dict-value-table.vue +++ b/orion-ops-ui/src/views/system/dict-value/components/dict-value-table.vue @@ -78,7 +78,9 @@ :bordered="false"> @@ -145,7 +145,7 @@ 新增 @@ -185,13 +185,13 @@ import { reactive, ref } from 'vue'; import useLoading from '@/hooks/loading'; import { getMenuList, deleteMenu, updateMenuStatus, initCache } from '@/api/system/menu'; - import { toOptions, getEnumValue, toggleEnumValue } from '@/utils/enum'; - import { MenuStatusEnum, MenuVisibleEnum, MenuTypeEnum } from '../types/enum.types'; + import { menuStatusKey, menuVisibleKey, menuTypeKey, MenuType } from '../types/const'; import columns from '../types/table.columns'; import { Message } from '@arco-design/web-vue'; - import { useCacheStore } from '@/store'; + import { useCacheStore, useDictStore } from '@/store'; import usePermission from '@/hooks/permission'; + const { toOptions, getDictValue, toggleDictValue } = useDictStore(); const cacheStore = useCacheStore(); const { hasPermission } = usePermission(); diff --git a/orion-ops-ui/src/views/system/menu/components/menu-tree-selector.vue b/orion-ops-ui/src/views/system/menu/components/menu-tree-selector.vue index 7fb9db66..1dedeeda 100644 --- a/orion-ops-ui/src/views/system/menu/components/menu-tree-selector.vue +++ b/orion-ops-ui/src/views/system/menu/components/menu-tree-selector.vue @@ -17,6 +17,7 @@ import type { TreeNodeData } from '@arco-design/web-vue'; import { useCacheStore } from '@/store'; import { computed } from 'vue'; + import { MenuType } from '../types/const'; const props = defineProps({ modelValue: Number, @@ -39,8 +40,8 @@ const treeData = (): TreeNodeData[] => { let render = (arr: any[]): TreeNodeData[] => { return arr.map((s) => { - // 非 function - if (s.type === 3) { + // 为 function 返回空 + if (s.type === MenuType.FUNCTION) { return null as unknown as TreeNodeData; } // 当前节点 diff --git a/orion-ops-ui/src/views/system/menu/index.vue b/orion-ops-ui/src/views/system/menu/index.vue index 2ee3e7b6..42e781f2 100644 --- a/orion-ops-ui/src/views/system/menu/index.vue +++ b/orion-ops-ui/src/views/system/menu/index.vue @@ -22,11 +22,15 @@ import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue'; import { onUnmounted, ref } from 'vue'; - import { useCacheStore } from '@/store'; + import { useCacheStore, useDictStore } from '@/store'; + import { dictKeys } from './types/const'; const table = ref(); const modal = ref(); + // 加载字典项 + useDictStore().loadKeys(dictKeys); + // 卸载时清除 menu cache onUnmounted(() => { const cacheStore = useCacheStore(); diff --git a/orion-ops-ui/src/views/system/menu/types/const.ts b/orion-ops-ui/src/views/system/menu/types/const.ts index cf7d2e42..f5fbf252 100644 --- a/orion-ops-ui/src/views/system/menu/types/const.ts +++ b/orion-ops-ui/src/views/system/menu/types/const.ts @@ -1 +1,39 @@ +// 排序步长 export const sortStep = 10; + +// 菜单类型 值 +export const MenuType = { + // 父菜单 + PARENT_MENU: 1, + // 子菜单 + SUB_MENU: 2, + // 功能 + FUNCTION: 3 +}; + +// 菜单是否可见 值 +export const MenuVisible = { + // 隐藏 + HIDE: 0, + // 显示 + SHOW: 1 +}; + +// 菜单缓存状态 值 +export const MenuCache = { + // 禁用 + DISABLED: 0, + // 启用 + ENABLED: 1 +}; + +// 菜单类型 字典项 +export const menuTypeKey = 'systemMenuType'; +// 菜单状态 字典项 +export const menuStatusKey = 'systemMenuStatus'; +// 是否可见 字典项 +export const menuVisibleKey = 'systemMenuVisible'; +// 是否缓存 字典项 +export const menuCacheKey = 'systemMenuCache'; + +export const dictKeys = [menuTypeKey, menuStatusKey, menuVisibleKey, menuCacheKey]; diff --git a/orion-ops-ui/src/views/system/menu/types/enum.types.ts b/orion-ops-ui/src/views/system/menu/types/enum.types.ts deleted file mode 100644 index 6666ccb5..00000000 --- a/orion-ops-ui/src/views/system/menu/types/enum.types.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 菜单类型 - */ -export const MenuTypeEnum = { - PARENT_MENU: { - value: 1, - label: '父菜单' - }, - SUB_MENU: { - value: 2, - label: '子菜单' - }, - FUNCTION: { - value: 3, - label: '功能' - } -}; - -/** - * 菜单状态 - */ -export const MenuStatusEnum = { - DISABLED: { - value: 0, - label: '停用', - color: 'orange' - }, - ENABLED: { - value: 1, - label: '启用', - color: 'blue' - } -}; - -/** - * 菜单是否可见 - */ -export const MenuVisibleEnum = { - HIDE: { - value: 0, - label: '隐藏', - color: 'orange' - }, - SHOW: { - value: 1, - label: '显示', - color: 'blue' - } -}; - -/** - * 菜单缓存状态 - */ -export const MenuCacheEnum = { - DISABLED: { - value: 0, - label: '不缓存', - }, - ENABLED: { - value: 1, - label: '缓存', - } -};