kinit/kinit-uni/permission.js
ktianc ff56a184ca 版本升级:
1. 修复(kinit-admin):页面缓存问题修复
2. 更新(kinit-api,kinit-admin):菜单管理新增是否缓存字段
3. 更新(kinit-admin):将缓存默认存储在localStorage中
4. 更新(kinit-api):将python-jose库更换为pyjwt库
5. 优化(kinit-admin,kinit-uni):退出登录方法优化
6. 优化(kinit-admin,kinit-uni):response拦截优化
7. 新增(kinit-api,kinit-admin,kinit-uni):jwt到期时间缩短,加入刷新token功能
8. (kinit-uni)切换到 vscode 开发 uniapp 项目
2023-03-13 14:34:26 +08:00

61 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getToken } from '@/common/utils/auth'
import store from '@/store'
import { RouterMount, createRouter } from 'uni-simple-router'
// uni-simple-router 官方文档https://www.hhyang.cn/v2/start/cross/codeRoute.html
// 登录页面
const loginPage = '/pages/login/login'
// 首页
const indexPage = '/pages/index'
const router = createRouter({
platform: process.env.VUE_APP_PLATFORM,
detectBeforeLock: (router, to, navType) => {
if (navType === 'replaceAll' && (to.path === loginPage || to.path === indexPage)) {
router.$lockStatus = false // 取消跳转锁
}
},
routes: [...ROUTES] // ROUTES是通过webpack的defaultPlugin编译成全局变量
})
//全局路由前置守卫
router.beforeEach((to, from, next) => {
if (to.meta.loginAuth) {
// 如果跳转的路由需要登录权限则验证该权限
if (getToken()) {
if (!store.state.auth.isUser) {
store.dispatch('auth/GetInfo')
}
if (to.path === loginPage) {
next({
path: indexPage,
NAVTYPE: 'replaceAll'
})
}
next()
} else {
next({
path: loginPage,
NAVTYPE: 'replaceAll'
})
}
} else if (to.path === loginPage && getToken()) {
// 如果跳转路由为登录页面并且存在token则跳转到首页
next({
path: indexPage,
NAVTYPE: 'replaceAll'
})
} else {
// 不需要权限且不是登录页面则不进行验证
next()
}
})
// 全局路由后置守卫
router.afterEach((to, from) => {
// console.log('跳转结束')
})
export { router, RouterMount }