index.js
6.05 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import Vue from 'vue'
import Router from 'vue-router'
import * as Cookies from 'js-cookie'
// NavigationDuplicated error https://github.com/vuejs/vue-router/issues/2881
// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
// return originalPush.call(this, location).catch(err => err)
// }
Vue.use(Router)
/* module router */
import reportRouter from './modules/report'
import analysisRouter from './modules/analysis'
import faceAnalysisRouter from './modules/face-analysis'
import customerRouter from './modules/customer'
import managementRouter from './modules/back-stage-management'
const router = new Router({
// mode: 'history',
routes: [{
path: '/home',
name: 'home',
meta: {
permissionPath: 'home'
},
// component: home,
component: () => import('@/views/home'),
// redirect: '/account',
children: [
...reportRouter,
analysisRouter,
customerRouter,
faceAnalysisRouter,
{
path: '/dataasis',
meta: {
permissionPath: 'dataasis'
},
component: () => import('@/views/DataAsis/dataasis'),
children: [{
path: '/dataasis/trafficasis',
name: 'trafficasis',
meta: {
permissionPath: 'dataasis'
},
component: () => import('@/views/DataAsis/trafficAsis/trafficasis'),
children: [{
path: 'monthly',
name: 'ta_monthly',
meta: {
permissionPath: 'dataasis'
},
component: () => import('@/views/DataAsis/trafficAsis/monthly'),
}]
},]
},
managementRouter
]
},
{
path: '/',
name: 'login',
component: () => import('@/views/login/login'),
// component: Login,
children: []
},
{
path: '/asus',
name: 'asuslogin',
component: () => import('@/views/loginAsus/loginAsus'),
// component: Login,
children: []
},
{
path: '/historyCustomer',
name: 'historyCustomer',
meta: {
permissionPath: 'historyCustomer'
},
component: () => import('@/views/Behavior/historyCustomer')
},
{
path: '/repeatCustomerStore',
name: 'repeatCustomerStore',
meta: {
permissionPath: 'repeatCustomerStore'
},
component: () => import('@/views/others-page/repeatCustomerStore'),
children: []
},
{
path: '/mark-staff',
name: 'MarkStaff',
meta: {
permissionPath: 'mark-staff'
},
component: () => import('@/views/others-page/MarkStaff/index')
},
{
path: '/xincheng',
name: 'xinchenglogin',
component: () => import('@/views/loginXincheng/loginXincheng'),
// component: Login,
children: []
},
{
path: '/free',
name: 'freelogin',
component: () => import('@/views/Freelogin/freelogin'),
// component: Login,
children: []
},
{
path: '/404',
name: '404',
component: () => import('@/views/error-page/404')
},
{
path: '*',
redirect: '/404'
},
// {
// path: '/layout',
// name: 'Layout',
// //
// }
]
// , {
// path: '/',
// name: 'login',
// component: Login,
// children: []
// }
})
// window.getVersion = version => {
// setInterval(() => {
// if (
// (localStorage.feVersion
// && version !== localStorage.feVersion)
// || (window.feVersion
// && version !== window.feVersion)
// ) {
// // console.log('不相同-----', localStorage.feVersion, window.feVersion)
// location.reload()
// }
// localStorage.feVersion = window.feVersion = version
// }, 1000)
// }
const whiteList = [
'/',
// '/asus',
// '/xincheng',
// '/free'
]
const errPageList = [
'/404'
]
// 全局路由守卫
router.beforeEach((to, from, next) => {
// if (!window.feVersion || !localStorage.feVersion) {
// let versionScript = document.createElement("script")
// const { origin, pathname } = location
// versionScript.src = origin + (pathname === '/' ? '' : pathname) + '/version.js?t=' + new Date().getTime()
// let s = document.getElementsByTagName("script")[0]
// s.parentNode.insertBefore(versionScript, s)
// }
// const toPath = to.path.slice(to.path.lastIndexOf('/') + 1)
const firstPath = window.localStorage.getItem('firstPath')
if (whiteList.indexOf(to.path) !== -1) {
if (Cookies.get('atoken')) {
if (window.allMenu) {
router.push('/account');
} else {
const cacheMenuList = window.localStorage.getItem('menu')
if (cacheMenuList) {
router.push('/' + (firstPath || 'home'));
} else {
Cookies.remove('atoken')
next('/login');
}
}
} else {
next();
}
} else {
if (Cookies.get('atoken')) {
const isSuper = Cookies.get('user_type') === 'super'
const cacheHasPermissionMenu = JSON.parse(window.localStorage.getItem('menuName'))
if (cacheHasPermissionMenu.indexOf(to.meta.permissionPath) !== -1 ||
errPageList.indexOf(to.path) !== -1 ||
isSuper ||
window.allMenu
) {
next();
} else {
next('/404')
}
} else {
router.push('/');
}
}
// console.log('navigation-guards');
// to: Route: 即将要进入的目标 路由对象
// from: Route: 当前导航正要离开的路由
// next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
// const nextRoute = ['home', 'account', 'analysis', 'behavior', 'manage'];
// let isLogin = global.isLogin; // 是否登录
// 未登录状态;当路由到nextRoute指定页时,跳转至login
// console.log('beforeRoute:', to, to.path, nextRoute.indexOf(to.path), isLogin);
// if (nextRoute.indexOf(to.path) >= 0) {
// if (!isLogin) {
// console.log('what fuck');
// router.push({ name: 'login' })
// }
// }
// 已登录状态;当路由到login时,跳转至home
// if (to.name === 'login') {
// if (isLogin) {
// router.push({ name: 'home' });
// }
// }
});
export default router;