diff --git a/src/layout/index.vue b/src/layout/index.vue index 5d9cb20..0139e77 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -22,7 +22,7 @@ import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components' import MobileBottomNav from '@/components/MobileBottomNav' import ResizeMixin from './mixin/ResizeHandler' -import { mapState } from 'vuex' +import { mapState, mapGetters } from 'vuex' import variables from '@/assets/styles/variables.scss' export default { @@ -45,10 +45,87 @@ export default { needTagsView: state => state.settings.tagsView, fixedHeader: state => state.settings.fixedHeader }), + ...mapGetters(['sidebarRouters']), mobileNavItems() { - // 可以从配置或store中获取,也可以自定义 - // 如果返回空数组,组件会使用默认逻辑 - return [] + // 根据业务需求配置底部导航项 + // 匹配关键词来自动查找路由,如果找不到则使用指定路径 + 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) }, classObj() { return { diff --git a/src/views/system/jd-instruction/index.vue b/src/views/system/jd-instruction/index.vue index fe9b449..f2416aa 100644 --- a/src/views/system/jd-instruction/index.vue +++ b/src/views/system/jd-instruction/index.vue @@ -9,20 +9,19 @@ - + 执行 清空 慢单 - + 腾峰 鸿 拼多多 拼多多-纹 - @@ -505,26 +504,91 @@ export default {