添加菜单页面.
This commit is contained in:
@@ -2,13 +2,15 @@ import { createPinia } from 'pinia';
|
||||
import useAppStore from './modules/app';
|
||||
import useUserStore from './modules/user';
|
||||
import useTabBarStore from './modules/tab-bar';
|
||||
import useMenuStore from './modules/system/menu';
|
||||
|
||||
const pinia = createPinia();
|
||||
|
||||
export {
|
||||
useAppStore,
|
||||
useUserStore,
|
||||
useTabBarStore
|
||||
useTabBarStore,
|
||||
useMenuStore
|
||||
};
|
||||
|
||||
export default pinia;
|
||||
|
||||
80
orion-ops-ui/src/store/modules/system/menu/index.ts
Normal file
80
orion-ops-ui/src/store/modules/system/menu/index.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { MenuState } from './types';
|
||||
import { MenuQueryResponse } from '@/api/system/menu';
|
||||
import { TreeNodeData } from '@arco-design/web-vue';
|
||||
|
||||
const useMenuStore = defineStore('menu', {
|
||||
state: (): MenuState => ({
|
||||
menus: []
|
||||
}),
|
||||
|
||||
getters: {
|
||||
menuState(state: MenuState): MenuState {
|
||||
return { ...state };
|
||||
},
|
||||
treeData(state: MenuState): TreeNodeData[] {
|
||||
let render = (arr: any[]): TreeNodeData[] => {
|
||||
return arr.map((s) => {
|
||||
// 非 function
|
||||
if (s.type === 3) {
|
||||
return null as unknown as TreeNodeData;
|
||||
}
|
||||
// 当前节点
|
||||
const node = {
|
||||
key: s.id,
|
||||
title: s.name,
|
||||
children: undefined as unknown
|
||||
} as TreeNodeData;
|
||||
// 子节点
|
||||
if (s.children && s.children.length) {
|
||||
node.children = render(s.children);
|
||||
}
|
||||
return node;
|
||||
}).filter(Boolean);
|
||||
};
|
||||
return render([{ name: '根目录', id: 0 }, ...state.menus]);
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
updateMenu(menus: MenuQueryResponse[]) {
|
||||
this.menus = menus;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取父菜单
|
||||
*/
|
||||
findParentMenu(arr: any, id: number): any {
|
||||
if (!arr || !arr.length) {
|
||||
return null;
|
||||
}
|
||||
// 当前级
|
||||
for (let e of arr) {
|
||||
if (e.id === id) {
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
// 子级
|
||||
for (let e of arr) {
|
||||
if (e.children && e.children.length) {
|
||||
// @ts-ignore
|
||||
if (this.findParent(e.children, id) !== null) {
|
||||
return e.children;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空菜单
|
||||
*/
|
||||
reset() {
|
||||
this.menus = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useMenuStore;
|
||||
7
orion-ops-ui/src/store/modules/system/menu/types.ts
Normal file
7
orion-ops-ui/src/store/modules/system/menu/types.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { MenuQueryResponse } from '@/api/system/menu';
|
||||
|
||||
export interface MenuState {
|
||||
menus: MenuQueryResponse[],
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
||||
Reference in New Issue
Block a user