|
@@ -1,59 +1,59 @@
|
1
|
|
-import router from "./router";
|
2
|
|
-import store from "./store";
|
3
|
|
-import NProgress from "nprogress"; // progress bar
|
4
|
|
-import "nprogress/nprogress.css"; // progress bar style
|
|
1
|
+import router from './router'
|
|
2
|
+import store from './store'
|
|
3
|
+import NProgress from 'nprogress' // progress bar
|
|
4
|
+import 'nprogress/nprogress.css' // progress bar style
|
5
|
5
|
|
6
|
6
|
NProgress.configure({
|
7
|
7
|
showSpinner: false
|
8
|
|
-}); // NProgress Configuration
|
|
8
|
+}) // NProgress Configuration
|
9
|
9
|
|
10
|
|
-const loginWhiteList = ["/token/verify", "/401", "/404"]; // 登录验证白名单
|
11
|
|
-const permissionWhiteList = loginWhiteList.concat(["/"]); // 权限验证白名单
|
|
10
|
+const loginWhiteList = ['/token/verify', '/401', '/404'] // 登录验证白名单
|
|
11
|
+const permissionWhiteList = loginWhiteList.concat(['/']) // 权限验证白名单
|
12
|
12
|
|
13
|
13
|
router.beforeEach((to, from, next) => {
|
14
|
14
|
// 线上注释
|
15
|
|
- // if (!store.getters.configlist || store.getters.configlist === undefined || store.getters.configlist.length <= 0) {
|
16
|
|
- // store.dispatch('VerifyConfigList', []).then(() => {
|
17
|
|
- // next()
|
18
|
|
- // })
|
19
|
|
- // }
|
20
|
|
- // if (store.getters.permission_routers === undefined) {
|
21
|
|
- // store.dispatch('xt_GenerateRoutes', []).then(() => {
|
22
|
|
- // next()
|
23
|
|
- // })
|
24
|
|
- // } else {
|
25
|
|
- // next()
|
26
|
|
- // }
|
27
|
|
- // return
|
|
15
|
+ if (!store.getters.configlist || store.getters.configlist === undefined || store.getters.configlist.length <= 0) {
|
|
16
|
+ store.dispatch('VerifyConfigList', []).then(() => {
|
|
17
|
+ next()
|
|
18
|
+ })
|
|
19
|
+ }
|
|
20
|
+ if (store.getters.permission_routers === undefined) {
|
|
21
|
+ store.dispatch('xt_GenerateRoutes', []).then(() => {
|
|
22
|
+ next()
|
|
23
|
+ })
|
|
24
|
+ } else {
|
|
25
|
+ next()
|
|
26
|
+ }
|
|
27
|
+ return
|
28
|
28
|
// 线上注释
|
29
|
29
|
|
30
|
|
- NProgress.start();
|
|
30
|
+ NProgress.start()
|
31
|
31
|
// console.log(store.getters.current_role_urls.indexOf(to.path))
|
32
|
32
|
// alert('path:' + to.path)
|
33
|
33
|
// 如果 url 带有 lt (login_token)参数,则跳转到验证 token 时等待的页面
|
34
|
34
|
if (to.query.lt != null && to.query.lt.length > 0) {
|
35
|
35
|
// alert('will go to verify token: ' + to.query.lt)
|
36
|
36
|
next({
|
37
|
|
- path: "/token/verify",
|
|
37
|
+ path: '/token/verify',
|
38
|
38
|
query: {
|
39
|
39
|
token: to.query.lt
|
40
|
40
|
}
|
41
|
|
- });
|
|
41
|
+ })
|
42
|
42
|
|
43
|
43
|
// 否则 如果没有 user 信息,则前往 sso 登录
|
44
|
44
|
} else if (store.getters.xt_user.user.id === 0) {
|
45
|
45
|
if (loginWhiteList.indexOf(to.path) !== -1) {
|
46
|
46
|
// alert('登录白名单内,跳过登录')
|
47
|
|
- next();
|
|
47
|
+ next()
|
48
|
48
|
} else {
|
49
|
49
|
// alert('前往登录')
|
50
|
|
- window.location.href = process.env.BASE_API + "/login"; // sso 地址
|
|
50
|
+ window.location.href = process.env.BASE_API + '/login' // sso 地址
|
51
|
51
|
}
|
52
|
52
|
|
53
|
53
|
// 否则 如果当前 url 不需要验证访问权限,则通过
|
54
|
54
|
} else if (permissionWhiteList.indexOf(to.path) !== -1) {
|
55
|
55
|
// alert('权限验证白名单内,直接进入')
|
56
|
|
- next();
|
|
56
|
+ next()
|
57
|
57
|
|
58
|
58
|
// 否则 如果拥有当前 url 的权限,则通过
|
59
|
59
|
// } else if (store.getters.current_role_urls.indexOf(to.path) !== -1) {
|
|
@@ -65,11 +65,11 @@ router.beforeEach((to, from, next) => {
|
65
|
65
|
// console.log(store.getters.current_role_urls)
|
66
|
66
|
// console.log(store.getters.current_role_urls.indexOf(to.path))
|
67
|
67
|
// alert('401')
|
68
|
|
- next();
|
|
68
|
+ next()
|
69
|
69
|
// next({ path: '/404' })
|
70
|
70
|
}
|
71
|
|
-});
|
|
71
|
+})
|
72
|
72
|
|
73
|
73
|
router.afterEach(() => {
|
74
|
|
- NProgress.done();
|
75
|
|
-});
|
|
74
|
+ NProgress.done()
|
|
75
|
+})
|