This commit is contained in:
Leo
2026-01-05 22:02:21 +08:00
parent 5367eb7834
commit af0000107f
5 changed files with 138 additions and 96 deletions

View File

@@ -47,85 +47,8 @@ export default {
}),
...mapGetters(['sidebarRouters']),
mobileNavItems() {
// 根据业务需求配置底部导航项
// 匹配关键词来自动查找路由,如果找不到则使用指定路径
const navConfig = [
{ keywords: ['慢单', 'sloworder'], label: '下好的慢单', icon: 'el-icon-list', defaultPath: '/sloworder/index' },
{ keywords: ['指令', 'instruction', 'jd-instruction'], label: '指令执行', icon: 'el-icon-edit-outline', defaultPath: '/jd-instruction/index' },
{ keywords: ['型号', 'productJdConfig', 'product'], label: '型号配置', icon: 'el-icon-setting', defaultPath: '/jarvis/productJdConfig' },
{ keywords: ['商品', 'favorite', 'erpProduct'], label: '商品列表', icon: 'el-icon-goods', defaultPath: '/favorite/index' }
]
const routes = this.sidebarRouters || []
// 扁平化路由
const flattenRoutes = (routes, parentPath = '') => {
let result = []
if (!routes || !Array.isArray(routes)) return result
routes.forEach(route => {
if (route.hidden) return
let fullPath = route.path || ''
if (parentPath) {
if (fullPath.startsWith('/')) {
fullPath = fullPath
} else {
const basePath = parentPath.endsWith('/') ? parentPath.slice(0, -1) : parentPath
fullPath = `${basePath}/${fullPath}`.replace(/\/+/g, '/')
}
}
if (!fullPath.startsWith('/')) {
fullPath = '/' + fullPath
}
if (route.children && route.children.length > 0) {
result = result.concat(flattenRoutes(route.children, fullPath))
} else {
if (route.meta && route.meta.title && fullPath) {
result.push({
path: fullPath,
label: route.meta.title,
route: route
})
}
}
})
return result
}
const flatRoutes = flattenRoutes(routes)
// 为每个配置项查找匹配的路由
const navItems = navConfig.map(config => {
// 先尝试从路由中匹配
const matchedRoute = flatRoutes.find(route => {
const path = (route.path || '').toLowerCase()
const title = (route.label || '').toLowerCase()
return config.keywords.some(keyword =>
path.includes(keyword.toLowerCase()) || title.includes(keyword.toLowerCase())
)
})
if (matchedRoute) {
return {
path: matchedRoute.path,
label: config.label,
icon: config.icon
}
}
// 如果没找到,使用默认路径
return {
path: config.defaultPath,
label: config.label,
icon: config.icon
}
})
// 过滤掉无效的路由
return navItems.filter(item => item.path)
// 如果返回空数组,组件会使用默认逻辑从路由中自动获取所有可用路由
return []
},
classObj() {
return {