permission.ts 973 Bytes
import router from "./router/index";
import { getToken } from './utils/auth'
const whiteList = ["/login", "/", "/creditReport", "/product", "/receiptDetail", "/commerceDetail", "/industryDetail", "/scienceDetail"];

import isNewVersion from './utils/version.js'

router.beforeEach((_to: any, _from: any, _next: any) => {

    //判断当前代码版本是否与服务器中代码版本一致,如不一致则刷新页面获取最新
    isNewVersion()
    // next()
    if (getToken()) {
        if (['/login'].includes(_to.path)) {
            //已经登录,访问的是白名单,自动跳转到首页
            _next('/')
        } else {
            //已经登录,访问的是不是白名单
            _next()
        }
    } else {
        if (whiteList.includes(_to.path)) {
            //未登录,访问的白名单
            _next()
        } else {
            //未登录,访问的不是白名单
            _next('/login')
        }
    }
})