This commit is contained in:
张成
2025-10-08 18:53:38 +08:00
parent 43eb9715fa
commit 845658f193
39 changed files with 4820 additions and 93 deletions

167
src/config/menuConfig.js Normal file
View File

@@ -0,0 +1,167 @@
/**
* 默认菜单配置
* 当 authorityMenus 接口失败时使用
*/
export const defaultMenus = [
{
id: 1,
name: '首页',
path: '/home',
component: 'home/index',
parent_id: 0,
type: '页面',
is_show_menu: 1,
icon: 'md-home',
sort: 1
},
{
id: 5,
name: '系统管理',
path: '/system',
component: '',
parent_id: 0,
type: '菜单',
is_show_menu: 1,
icon: 'md-settings',
sort: 2,
children: [
{
id: 11,
name: '用户管理',
path: '/system/user',
component: 'system/sys_user',
parent_id: 5,
type: '页面',
is_show_menu: 1,
icon: 'md-person',
sort: 1
},
{
id: 12,
name: '角色管理',
path: '/system/role',
component: 'system/sys_role',
parent_id: 5,
type: '页面',
is_show_menu: 1,
icon: 'md-people',
sort: 2
},
{
id: 13,
name: '系统日志',
path: '/system/log',
component: 'system/sys_log',
parent_id: 5,
type: '页面',
is_show_menu: 1,
icon: 'md-list',
sort: 3
},
{
id: 15,
name: '参数设置',
path: '/system/param',
component: 'system/sys_param_setup',
parent_id: 5,
type: '页面',
is_show_menu: 1,
icon: 'md-options',
sort: 4
}
]
},
{
id: 120,
name: '高级管理',
path: '/system_high',
component: '',
parent_id: 0,
type: '菜单',
is_show_menu: 1,
icon: 'md-construct',
sort: 3,
children: [
{
id: 122,
name: '菜单管理',
path: '/system_high/menu',
component: 'system_high/sys_menu',
parent_id: 120,
type: '页面',
is_show_menu: 1,
icon: 'md-menu',
sort: 1
},
{
id: 123,
name: '控制管理',
path: '/system_high/control',
component: 'system_high/sys_control',
parent_id: 120,
type: '页面',
is_show_menu: 1,
icon: 'md-cube',
sort: 2
},
{
id: 124,
name: '系统标题',
path: '/system_high/title',
component: 'system_high/sys_title',
parent_id: 120,
type: '页面',
is_show_menu: 1,
icon: 'md-text',
sort: 3
}
]
}
]
/**
* 根据菜单 ID 数组过滤菜单
* @param {Array} menuIds - 菜单 ID 数组
* @param {Array} allMenus - 所有菜单配置
* @returns {Array} 过滤后的菜单
*/
export function filterMenusByIds(menuIds, allMenus = defaultMenus) {
if (!menuIds || menuIds.length === 0) {
return allMenus
}
const idSet = new Set(menuIds)
function filterMenu(menu) {
if (!idSet.has(menu.id)) {
return null
}
const filteredMenu = { ...menu }
if (menu.children && menu.children.length > 0) {
const filteredChildren = menu.children
.map(child => filterMenu(child))
.filter(child => child !== null)
if (filteredChildren.length > 0) {
filteredMenu.children = filteredChildren
} else {
delete filteredMenu.children
}
}
return filteredMenu
}
return allMenus
.map(menu => filterMenu(menu))
.filter(menu => menu !== null)
}
export default {
defaultMenus,
filterMenusByIds
}