123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import router from './router' // vue官方的路由
- import store from './store' // vue状态管理
- import { Message, MessageBox } from 'element-ui' // 引入Message、MessageBox
- import NProgress from 'nprogress' // 进度条
- import 'nprogress/nprogress.css' // 进度条样式
- import getPageTitle from '@/utils/get-page-title' // 获取页面标题
- import { Caegw_LogUrl } from '@/settings' // 引入settings.js
- NProgress.configure({ showSpinner: false }) // NProgress配置
- const whiteList = ['/fail404', '/home','/sso','/login/index','/register/index', '/forget/index', '/protocol/index','/indexLayout/index','/index','/HCFDLab/chart']// 免登录的'白名单
- // 前置路由守卫
- router.beforeEach(async (to, from, next) => {
- NProgress.start() // 开启进度条
- document.title = getPageTitle(to.meta.title) // 设置页面标题
- const token = store.getters.token // 确定用户是否已登录
- if (token) {
- if (to.path === '/login/index') {
- next({ path: '/index' }) // 重定向到主页
- NProgress.done() // 关闭进度条
- } else {
- next() // 直接进入
- NProgress.done() // 关闭进度
- }
- } else {
- if (whiteList.indexOf(to.path) !== -1) {
-
- next() // 在免登录白名单中,直接进入
- NProgress.done() // 关闭进度条
- } else {
- // next(`/login?redirect=${to.path}`) // 在没有访问权限的其他页面将重定向到登录页
- // NProgress.done() // 关闭进度条
- MessageBox.confirm('你还未登录,请登录后再操作, 是否登录?', '提示', {
- confirmButtonText: '登录',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- this.$router.replace(`/indexLayout/home?type=reLogin`)
- // next(`/indexLayout/index'?type=reLogin`)
- console.log(next(`/login?redirect=${to.path}`) );
- // next(`/login/index?redirect=${to.path}`) // 在没有访问权限的其他页面将重定向到登录页
- // const errUril = window.location.protocol+"//"+window.location.host+"/"+this.$store.getters.logUrl
- // window.location.href=errUril
- NProgress.done() // 关闭进度条
- })
- .catch(() => {
- NProgress.done() // 关闭进度条
- Message({
- type: 'info',
- message: '已取消'
- })
- })
- }
- }
- })
- // 后置路由守卫
- router.afterEach(() => {
- NProgress.done() // 关闭进度条
- })
|