From 653b1bf5132df83d24f827e56c781e724b3d165c Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Mon, 9 Jun 2025 16:24:07 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afix=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=AE=89=E5=8D=93=E7=AB=AF=20=E8=BA=AB=E4=BB=BDtoken?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E4=BC=9A=E5=BC=B9=E7=AA=97=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=20=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0=E6=89=93=E5=BC=80app=20?= =?UTF-8?q?=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E8=B7=B3=E8=BD=AC=E5=88=B0=E7=99=BB=E9=99=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- src/permission.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/permission.js b/src/permission.js index 4161ba1..6fcb666 100644 --- a/src/permission.js +++ b/src/permission.js @@ -6,37 +6,37 @@ import 'nprogress/nprogress.css' // 进度条 style NProgress.configure({ showSpinner: false }) // 进度条 Configuration /** - * @description: 路由守卫 + * @description: 路由前置守卫 */ router.beforeEach((to, from, next) => { - // start 进度条 NProgress.start() - // 设置title document.title = getPageTitle(to.meta.title) - store.commit('user/initUser') // 用户信息初始化 + // 初始化用户信息 + store.commit('user/initUser') const power = store.state.user.power const token = store.state.user.token + // 判断 token 是否存在 if (!token) { if (to.path === '/login') { next() } else { - next('/login') // 直接调用 next('/login') + // 安卓端兼容性更强的方式,强制跳转登录页 + router.replace('/login') } } else { if (to.path === '/login') { - next('/') + next('/') // 已登录访问登录页,重定向首页 } else { - if (to.meta.roles && to.meta.roles.indexOf(power) >= 0) { // 确保 roles 存在 + // 校验权限 + if (!to.meta.roles || to.meta.roles.indexOf(power) >= 0) { next() } else { - next('/') + next('/') // 权限不足时跳转首页 } } } - - NProgress.done() }) /**