diff --git a/.env.dev b/.env.dev index 7c7b6af3..7c750412 100644 --- a/.env.dev +++ b/.env.dev @@ -12,9 +12,9 @@ VUE_APP_TITLE = 洛玻集团驾驶舱 # 杨姗姗 # VUE_APP_BASE_API = 'http://172.16.20.218:7070' # 小田 -# VUE_APP_BASE_API = 'http://172.16.19.232:7070' +VUE_APP_BASE_API = 'http://172.16.19.232:7070' # 测试 -VUE_APP_BASE_API = 'http://192.168.0.35:8080' +# VUE_APP_BASE_API = 'http://192.168.0.35:8080' # 路由懒加载 diff --git a/src/permission.js b/src/permission.js index 2411ca6a..ae41dce2 100644 --- a/src/permission.js +++ b/src/permission.js @@ -8,11 +8,8 @@ import { isRelogin } from '@/utils/request' NProgress.configure({ showSpinner: false }) -/** - * 从菜单树中查找 jumpFlag===1 的默认跳转路径 - * 若打标在父节点则取其下第一个可见叶子路径;若在叶子则直接返回该路径 - */ -function findDefaultPathFromMenus(menus) { +// 从菜单树中查找第一个可见叶子菜单路径(按接口返回顺序) +function findFirstLeafPathFromMenus(menus) { if (!Array.isArray(menus) || menus.length === 0) return null function dfs(list, parentPath = '') { @@ -23,16 +20,11 @@ function findDefaultPathFromMenus(menus) { ? rawPath : `${parentPath}/${rawPath}`.replace(/\/+/g, '/') - if (item.jumpFlag === 1) { - if (item.children && item.children.length > 0) { - const childPath = dfs(item.children, currentPath) - return childPath != null ? childPath : currentPath - } - return currentPath - } if (item.children && item.children.length > 0) { const found = dfs(item.children, currentPath) if (found != null) return found + } else { + return currentPath } } return null @@ -40,6 +32,24 @@ function findDefaultPathFromMenus(menus) { return dfs(menus) } +function findFirstLeafPathFromRoutes(routes) { + if (!Array.isArray(routes) || routes.length === 0) return null + const stack = [...routes] + while (stack.length) { + const route = stack.shift() + if (!route || route.hidden === true) continue + if (Array.isArray(route.children) && route.children.length > 0) { + stack.unshift(...route.children) + continue + } + const p = route.path || '' + if (typeof p === 'string' && p.startsWith('/') && p !== '/404') { + return p + } + } + return null +} + // 增加三方登陆 update by 芋艿 const whiteList = ['/login', '/social-login', '/auth-redirect', '/bind', '/register', '/oauthLogin/gitee'] @@ -65,11 +75,16 @@ router.beforeEach((to, from, next) => { store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => { // 根据 roles 权限生成可访问的路由表 router.addRoutes(accessRoutes) // 动态添加可访问路由表 - const defaultPath = findDefaultPathFromMenus(userInfo.menus) || '/' + const menuDefaultPath = findFirstLeafPathFromMenus(userInfo.menus) + const routeFallbackPath = findFirstLeafPathFromRoutes(accessRoutes) + const defaultPath = menuDefaultPath || routeFallbackPath || '/' store.dispatch('SetDefaultPath', defaultPath) // 仅当目标为根路径 '/' 时跳默认页;否则保持当前路径(含刷新场景),避免刷新被误判为“未匹配”而跳到默认页 if (to.path === '/') { - next({ path: defaultPath, replace: true }) + const matched = router.match(defaultPath) + const hasMatch = matched && Array.isArray(matched.matched) && matched.matched.length > 0 + const safePath = hasMatch ? defaultPath : (routeFallbackPath || '/') + next({ path: safePath, replace: true }) } else { next({ ...to, replace: true }) // hack方法 确保addRoutes已完成,当前页刷新时保留 to 的路径 } diff --git a/src/views/error/404.vue b/src/views/error/404.vue index 96f075c1..79849629 100644 --- a/src/views/error/404.vue +++ b/src/views/error/404.vue @@ -17,8 +17,8 @@
-
+ 环比{{ formatRate(factoryData?.thb) }}%
+
+
-
+ 同比{{ formatRate(factoryData?.thb) }}%
+
+