index.js
11.4 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
import Vue from 'vue'
import Router from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { Loading } from 'element-ui'
import db from '@/utils/localstorage'
import Cookies from 'js-cookie'
import store from '@/store/index'
// import { getRouter } from '@/api/login.js'
import { getRouter } from '@/api/login.js'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
/**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
*
* hidden: true if set true, item will not show in the sidebar(default is false)
* alwaysShow: true if set true, will always show the root menu
* if not set alwaysShow, when item has more than one children route,
* it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor'] control the page roles (you can set multiple roles)
title: 'title' the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name' the icon show in the sidebar
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
}
*/
/**
* constantRoutes
* a base page that does not have permission requirements
* all roles can be accessed
*/
export const constantRoutes = [
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/404',
component: () => import('@/views/404'),
hidden: true
},
{
path: '/',
component: Layout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/dashboard/index'),
meta: { title: '工作台', icon: 'dashboard', navShow: false }
}
]
},
{
path: '/business',
component: Layout,
redirect: '/business/list',
name: 'business',
meta: {
title: '订单管理',
icon: 'form'
},
children: [
{
path: 'order-manage',
component: () => import('@/views/order-manage/list'),
name: 'order-manage',
meta: { title: '订单管理', noCache: true }
},
{
path: 'edit-order',
component: () => import('@/views/order-manage/edit-order'),
name: 'edit-order',
hidden: true,
meta: { title: '订单详情', noCache: true, pageHeader: true }
}
]
},
{
path: '/business',
component: Layout,
redirect: '/business/list',
name: 'business',
meta: {
title: '运单管理',
icon: 'form'
},
children: [
{
path: 'waybill',
component: () => import('@/views/waybill/list'),
name: 'waybill',
meta: { title: '运单管理', noCache: true }
},
{
path: 'waybill-detail',
component: () => import('@/views/waybill/waybill-detail'),
hidden: true,
name: 'waybill-detail',
meta: { title: '运单详情', noCache: true, pageHeader: true }
}
]
},
{
path: '/branches',
component: Layout,
redirect: '/branches/operational',
name: 'branches',
meta: {
title: '网点管理',
icon: 'form'
},
children: [
{
path: 'organization-manage',
component: () => import('@/views/branches/organization-manage'),
name: 'organization-manage',
meta: { title: '机构管理', noCache: true }
},
{
path: 'operational',
component: () => import('@/views/branches/operational'),
name: 'operational',
meta: { title: '快递作业管理', noCache: true }
},
{
path: 'pickUptask',
component: () => import('@/views/branches/components/pickup-task'),
name: 'operational',
meta: { title: '取件作业管理', noCache: true }
},
{
path: 'dispatchTask',
component: () => import('@/views/branches/components/dispatch-task'),
name: 'operational',
meta: { title: '派件作业管理', noCache: true }
},
{
path: 'MapContent',
component: () => import('@/views/branches/components/MapContent'),
name: 'MapContent',
hidden: true,
meta: { title: '作业范围分配', noCache: true, pageHeader: true }
},
{
path: 'operational-range',
component: () => import('@/views/branches/operational-range'),
name: 'operational-range',
meta: { title: '快递员管理', noCache: true }
},
// {
// path: 'goods-type',
// component: () => import('@/views/branches/goods-type'),
// name: 'goods-type',
// meta: { title: '货品类型管理', noCache: true }
// },
{
path: 'institutions-jobs-area',
component: () => import('@/views/branches/institutions-jobs-area'),
name: 'institutions-jobs-area',
meta: { title: '机构作业范围', noCache: true }
}
]
},
{
path: '/transit',
component: Layout,
redirect: '/transit/car-models',
name: 'transit',
meta: {
title: '转运中心',
icon: 'form'
},
children: [
{
path: 'workArrange-manage',
component: () => import('@/views/transit/workArrange-manage'),
name: 'workArrange-manage',
meta: { title: '排班管理', noCache: true }
},
{
path: 'workArrange-setting',
component: () => import('@/views/transit/workArrange-setting'),
name: 'workArrange-setting',
hidden: true,
meta: { title: '排班设置', noCache: true, pageHeader: true }
},
{
path: 'freight-manage',
component: () => import('@/views/transit/freight-manage'),
name: 'freight-manage',
meta: { title: '运费管理', noCache: true }
},
{
path: 'car-models',
component: () => import('@/views/transit/car-models'),
name: 'car-models',
meta: { title: '车型管理', noCache: true }
},
{
path: 'driver',
component: () => import('@/views/transit/driver'),
name: 'driver',
meta: { title: '司机管理', noCache: true }
},
{
path: 'driver-detail',
component: () => import('@/views/transit/driver-detail'),
name: 'driver-detail',
hidden: true,
meta: { title: '司机详情', noCache: true, pageHeader: true }
},
{
path: 'vehicle',
component: () => import('@/views/transit/vehicle'),
name: 'vehicle',
meta: { title: '车辆管理', noCache: true }
},
{
path: 'vehicle-detail',
component: () => import('@/views/transit/vehicle-detail'),
name: 'vehicle-detail',
hidden: true,
meta: { title: '车辆详情', noCache: true, pageHeader: true }
},
{
path: 'car-register',
component: () => import('@/views/transit/car-register'),
name: 'car-register',
meta: { title: '回车登记', noCache: true }
},
{
path: 'car-register-info',
component: () => import('@/views/transit/car-register-info'),
name: 'car-register',
meta: { title: '回单查看', noCache: true, pageHeader: true }
}
]
},
{
path: '/transport',
component: Layout,
redirect: '/transport/transport-task',
name: 'transport',
meta: {
title: '运输管理',
icon: 'form'
},
children: [
{
path: 'transport-task',
component: () => import('@/views/transport/transport-task'),
name: 'transport-task',
meta: { title: '运输任务管理', noCache: true }
},
{
path: 'task-detail',
component: () => import('@/views/transport/task-detail'),
name: 'task-detail',
hidden: true,
meta: { title: '运输任务详情', noCache: true, pageHeader: true }
},
{
path: 'line-manage',
component: () => import('@/views/transit/line-manage'),
name: 'line-manage',
meta: { title: '线路管理', noCache: true }
}
]
},
{ path: '*', redirect: '/404', hidden: true }
]
const createRouter = () =>
new Router({
// mode: 'history', // require service support
scrollBehavior: (to, from, savedPosition) => {
return { y: 0, x: 0 }
},
routes: constantRoutes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
let asyncRouter
const whiteList = ['/login']
function go(to, next) {
next()
}
export const view = path => {
return resolve => require([`@/views/${path}.vue`], resolve)
}
function save(name, data) {
localStorage.setItem(name, JSON.stringify(data))
}
function get(name) {
return JSON.parse(localStorage.getItem(name))
}
// 导航守卫,渲染动态路由
router.beforeEach((to, from, next) => {
NProgress.start()
document.documentElement.scrollTop = 0
console.dir(document.documentElement, 'document.documentElement')
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
const token = Cookies.get('TOKEN')
const user = db.get('USER')
const userRouter = get('USER_ROUTER')
const iconList = [
require('@/assets/navIcons/gzt.png'),
require('@/assets/navIcons/jcsj.png'),
require('@/assets/navIcons/clgl.png'),
require('@/assets/navIcons/yggl.png'),
require('@/assets/navIcons/ywgl.png'),
require('@/assets/navIcons/ddgl.png')
]
if (token && user) {
if (!asyncRouter) {
if (!userRouter) {
getRouter({}).then(response => {
const res = response.data
asyncRouter = res.map((res, index) => {
return Object.assign({}, res, { icon: iconList[index] })
})
store.commit('account/setRoutes', asyncRouter)
save('USER_ROUTER', asyncRouter)
go(to, next)
})
// go(to, next)
} else {
asyncRouter = userRouter
go(to, next)
}
} else {
const options = {
lock: true,
// text: '页面加载中...',
// spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.8)'
}
const loadingInstance = Loading.service(options)
const origin = window.location.protocol + '//' + window.location.host
if (to.path === '/dashboard') {
// http://localhost:9528/
// http://pinda.itheima.net
// next('/myiframe/iframe?urlPath&src=http://localhost:9528/#/forpinda')
// next('/myiframe/iframe?urlPath&src=http://localhost:8080/#/forpinda')
next()
setTimeout(() => {
loadingInstance.close()
}, 600)
}
next()
setTimeout(() => {
loadingInstance.close()
}, 600)
}
} else {
if (to.path === '/login') {
next()
} else {
next('/login')
}
}
}
})
router.afterEach(() => {
NProgress.done()
// next()
})
export default router