付延余
2022-04-11 f75e0187e2e32c1471d04c29c42517609910b7ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Vue from 'vue'
import Router from 'vue-router'
import { routers } from './router'
import { getStore, setStore, removeStore } from '../libs/store'
// 重复点击相同路由拦截报红错误
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
 
// import NProgress from 'nprogress' // 进度条
import 'nprogress/nprogress.css' //这个样式必须引入
// import { message, notification } from "ant-design-vue/es"; //单独引入message消息提示模块
// 简单配置
// NProgress.inc(0.2)
// NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false })
 
// 页面跳转开始时间
var startTime
// 通知跳过的路由
const passPath = [
    '/login',
    '/404',
    '/403',
    '/302'
]
 
Vue.use(Router);
 
const RouterConfig = {
    // mode: 'history',
    routes: routers
};
 
export const router = new Router(RouterConfig);
 
// 拦截器处理
/*router.beforeEach((to, from, next) => {
    // if (to.path == '/login') {
    //     removeStore('userinfo');
    // }
    // let userinfo = getStore({ key: 'userinfo' });
    // let toTime = new Date().getTime() / 1000
    // if (userinfo == null && to.path != '/login') {
    //     message.info('登录错误,请重新登录')
    //     setTimeout(() => {
    //         next({ path: '/login' })
    //     }, 1000)
    // }
    // console.log(userinfo)
    // if (userinfo && toTime >= userinfo.expire_time && to.path != '/login') {
    //     message.info('登录失效,请重新登录')
    //     setTimeout(() => {
    //         next({ path: '/login' })
    //     }, 1000)
    // }
 
    // userinfo.expire_time = toTime + 1000 * 60 * 60 * 2
    // localStorage.setItem("userinfo", JSON.stringify(userinfo))
 
    // 页面不存在
    // console.log(to)
    if (to.matched.length == 0) {
        next({ path: '/404' })
    }
 
    startTime = new Date().getTime()
 
    // NProgress.start();
    next()
})
 
router.afterEach((to) => {
    if (passPath.indexOf(to.path) === -1) {
        // var consumingTime = new Date().getTime() - startTime
        // notification.info({
        //     message: '此次加载页面消耗时间',
        //     duration:2,
        //     description: `耗时${consumingTime / 1000}秒`,
        // });
    }
    // NProgress.done();
});*/