diff --git a/src/router/index.js b/src/router/index.js index cfd5a5e..85e2cd7 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -59,50 +59,50 @@ const router = new Router({ routes: globalRoutes.concat(mainRoutes) }) -router.beforeEach((to, from, next) => { - const token = localStorage.getItem('token'); - const isLogin = to.name === 'login'; // 判断是否是登录页 +router.beforeEach((to, from, next) => {console.log(Vue.prototype.$store) - // 保存原始路径(仅在未登录状态下保存) - if (!token && !isLogin) { - console.log('保存重定向路径:', to.fullPath); - localStorage.setItem('redirectPath', to.fullPath); - } + // const token = localStorage.getItem('token'); + // const isLogin = to.name === 'login'; // 判断是否是登录页 + // + // // 保存原始路径(仅在未登录状态下保存) + // if (!token && !isLogin) { + // console.log('保存重定向路径:', to.fullPath); + // localStorage.setItem('redirectPath', to.fullPath); + // } - // 动态路由逻辑处理 + // 添加动态(菜单)路由 + // 1. 已经添加 or 全局路由, 直接访问 + // 2. 获取菜单列表, 添加并保存本地存储 if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') { - next(); + next() } else { + let menuType = localStorage.getItem('menuType') http({ url: http.adornUrl('/sys/menu/nav'), method: 'get', params: { - l: i18n.locale, // 当前语言 + 'l': i18n.locale, //i18n.locale menuType: 'pc' } + }).then(({data}) => { + if (data && data.code === 0) { + fnAddDynamicMenuRoutes(data.menuList) + router.options.isAddDynamicMenuRoutes = true + sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]')) + sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]')) + sessionStorage.setItem('userConfig', JSON.stringify(data.userConfig || '[]')) + next({ ...to, replace: true }) + } else { + sessionStorage.setItem('menuList', '[]') + sessionStorage.setItem('permissions', '[]') + next() + } + }).catch((e) => { + console.log(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue') + router.push({ name: 'login' }) }) - .then(({ data }) => { - if (data && data.code === 0) { - fnAddDynamicMenuRoutes(data.menuList); // 添加动态菜单路由 - router.options.isAddDynamicMenuRoutes = true; - sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]')); - sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]')); - sessionStorage.setItem('userConfig', JSON.stringify(data.userConfig || '[]')); - next({ ...to, replace: true }); - } else { - console.error('菜单数据获取失败:', data.msg); - sessionStorage.setItem('menuList', '[]'); - sessionStorage.setItem('permissions', '[]'); - next(); - } - }) - .catch((e) => { - console.error(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue'); - router.push({ name: 'login' }); // 跳转到登录页 - }); } -}); - +}) /** * 判断当前路由类型, global: 全局路由, main: 主入口路由 diff --git a/src/views/common/login.vue b/src/views/common/login.vue index cd8a8ef..137b6b2 100644 --- a/src/views/common/login.vue +++ b/src/views/common/login.vue @@ -105,13 +105,13 @@ import { getUUID } from '@/utils' }) }).then(({data}) => { if (data && data.code === 0) { - console.log('跳转前路径:', localStorage.getItem('redirectPath')); // 检查路径是否正确 + // console.log('跳转前路径:', localStorage.getItem('redirectPath')); // 检查路径是否正确 this.$cookie.set('token', data.token) // 动态跳转逻辑 - const redirectPath = localStorage.getItem('redirectPath') || '/home'; - console.log('Redirecting to:', redirectPath); // 调试输出 - this.$router.replace(redirectPath); // 根据保存的路径跳转 - // this.$router.replace({name: 'home'}) + // const redirectPath = localStorage.getItem('redirectPath') || '/home'; + // console.log('Redirecting to:', redirectPath); // 调试输出 + // this.$router.replace(redirectPath); // 根据保存的路径跳转 + this.$router.replace({name: 'home'}) this.$i18n.locale=data.language localStorage.setItem('locale', data.language) localStorage.setItem('refresh', "0") diff --git a/src/views/modules/auth/authInquiry.vue b/src/views/modules/auth/authInquiry.vue index e0d7f3d..a7cb183 100644 --- a/src/views/modules/auth/authInquiry.vue +++ b/src/views/modules/auth/authInquiry.vue @@ -312,13 +312,13 @@ import {updateAuthHist} from "../../../api/auth/auth"; import OssComponents from "../oss/ossComponents.vue"; export default { - beforeRouteEnter(to, from, next) { - next((vm) => { - // 跳转后清除 redirectPath - localStorage.removeItem('redirectPath'); - console.log('redirectPath 已清除'); - }); - }, + // beforeRouteEnter(to, from, next) { + // next((vm) => { + // // 跳转后清除 redirectPath + // localStorage.removeItem('redirectPath'); + // console.log('redirectPath 已清除'); + // }); + // }, computed: { statusDisplay() { return this.inquiryInfoData.status === 'C' ? '草稿' : (this.inquiryInfoData.status === 'B' ? '已下达' : '已报价') diff --git a/src/views/modules/auth/authQuote.vue b/src/views/modules/auth/authQuote.vue index c0baa7a..1f0910c 100644 --- a/src/views/modules/auth/authQuote.vue +++ b/src/views/modules/auth/authQuote.vue @@ -216,13 +216,13 @@ import TpCost from "../quote/detail/tpCost.vue"; import QuoteDetail from "../quote/detail/quoteDetail.vue"; export default { - beforeRouteEnter(to, from, next) { - next((vm) => { - // 跳转后清除 redirectPath - localStorage.removeItem('redirectPath'); - console.log('redirectPath 已清除'); - }); - }, + // beforeRouteEnter(to, from, next) { + // next((vm) => { + // // 跳转后清除 redirectPath + // localStorage.removeItem('redirectPath'); + // console.log('redirectPath 已清除'); + // }); + // }, computed: { // quotationInformationFlag () { // return (value) => {