Blame view

src/router/index.js 16.2 KB
80a28914e   吉鹏   init
1
2
3
4
5
6
7
  import Vue from 'vue'
  import Router from 'vue-router'
  
  Vue.use(Router)
  
  /* Layout */
  import Layout from '@/layout'
d7d9c38c2   Adam   auto commit the c...
8
9
10
11
  /* Router Modules */
  import componentsRouter from './modules/components'
  import chartsRouter from './modules/charts'
  import tableRouter from './modules/table'
3d3cdb68f   Adam   auto commit the c...
12
13
  // import nestedRouter from './modules/nested'
  import userRouter from './modules/user'
d7d9c38c2   Adam   auto commit the c...
14

80a28914e   吉鹏   init
15
16
17
18
19
20
21
22
23
24
25
  /**
   * 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 : {
3d3cdb68f   Adam   auto commit the c...
26
      roles: ['admin','assistant','runner', 'shoper']    control the page roles (you can set multiple roles)
80a28914e   吉鹏   init
27
28
      title: 'title'               the name show in sidebar and breadcrumb (recommend set)
      icon: 'svg-name'             the icon show in the sidebar
d7d9c38c2   Adam   auto commit the c...
29
30
      noCache: true                if set true, the page will no be cached(default is false)
      affix: true                  if set true, the tag will affix in the tags-view
80a28914e   吉鹏   init
31
32
33
34
35
36
37
38
39
40
      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
   */
d7d9c38c2   Adam   auto commit the c...
41
42
43
44
45
46
47
48
49
50
51
52
53
  export const constantRoutes = [
    {
      path: '/redirect',
      component: Layout,
      hidden: true,
      children: [
        {
          path: '/redirect/:path*',
          component: () => import('@/views/redirect/index')
        }
      ]
    },
    {
80a28914e   吉鹏   init
54
55
56
57
      path: '/login',
      component: () => import('@/views/login/index'),
      hidden: true
    },
80a28914e   吉鹏   init
58
    {
d7d9c38c2   Adam   auto commit the c...
59
60
61
62
63
      path: '/auth-redirect',
      component: () => import('@/views/login/auth-redirect'),
      hidden: true
    },
    {
80a28914e   吉鹏   init
64
      path: '/404',
d7d9c38c2   Adam   auto commit the c...
65
66
67
68
69
70
      component: () => import('@/views/error-page/404'),
      hidden: true
    },
    {
      path: '/401',
      component: () => import('@/views/error-page/401'),
80a28914e   吉鹏   init
71
72
      hidden: true
    },
80a28914e   吉鹏   init
73
74
75
76
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
d7d9c38c2   Adam   auto commit the c...
77
78
79
80
81
82
      children: [
        {
          path: 'dashboard',
          component: () => import('@/views/dashboard/index'),
          name: 'Dashboard',
          meta: { title: 'dashboard', icon: 'dashboard', affix: true }
1172ebb79   Adam   auto commit the c...
83
        }
d7d9c38c2   Adam   auto commit the c...
84
      ]
80a28914e   吉鹏   init
85
    },
d7d9c38c2   Adam   auto commit the c...
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
    // {
    //   path: '/documentation',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/documentation/index'),
    //       name: 'Documentation',
    //       meta: { title: 'documentation', icon: 'documentation', affix: true }
    //     }
    //   ]
    // },
    // {
    //   path: '/guide',
    //   component: Layout,
    //   redirect: '/guide/index',
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/guide/index'),
    //       name: 'Guide',
    //       meta: { title: 'guide', icon: 'guide', noCache: true }
    //     }
    //   ]
    // },
c44ba96f6   Adam   auto commit the c...
111
    {
d7d9c38c2   Adam   auto commit the c...
112
      path: '/profile',
c44ba96f6   Adam   auto commit the c...
113
      component: Layout,
d7d9c38c2   Adam   auto commit the c...
114
115
116
117
118
119
120
121
      redirect: '/profile/index',
      hidden: true,
      children: [
        {
          path: 'index',
          component: () => import('@/views/profile/index'),
          name: 'Profile',
          meta: { title: 'profile', icon: 'user', noCache: true }
c44ba96f6   Adam   auto commit the c...
122
123
        }
      ]
d7d9c38c2   Adam   auto commit the c...
124
125
126
127
128
129
130
131
    }
  ]
  
  /**
   * asyncRoutes
   * the routes that need to be dynamically loaded based on user roles
   */
  export const asyncRoutes = [
3d3cdb68f   Adam   auto commit the c...
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
    // {
    //   path: '/permission',
    //   component: Layout,
    //   redirect: '/permission/page',
    //   alwaysShow: true, // will always show the root menu
    //   name: 'Permission',
    //   meta: {
    //     title: 'permission',
    //     icon: 'lock',
    //     roles: ['admin', 'assistant'] // you can set roles in root nav
    //   },
    //   children: [
    //     {
    //       path: 'page',
    //       component: () => import('@/views/permission/page'),
    //       name: 'PagePermission',
    //       meta: {
    //         title: 'pagePermission',
    //         roles: ['admin','assistant'] // or you can only set roles in sub nav
    //       }
    //     },
    //     {
    //       path: 'directive',
    //       component: () => import('@/views/permission/directive'),
    //       name: 'DirectivePermission',
    //       meta: {
    //         title: 'directivePermission',
    //         roles: ['admin', 'shoper']
    //         // if do not set roles, means: this page does not require permission
    //       }
    //     },
    //     {
    //       path: 'role',
    //       component: () => import('@/views/permission/role'),
    //       name: 'RolePermission',
    //       meta: {
    //         title: 'rolePermission',
    //         roles: ['admin', 'runner']
    //       }
    //     }
    //   ]
    // },
80a28914e   吉鹏   init
174
    {
3d3cdb68f   Adam   auto commit the c...
175
      path: '/meta',
80a28914e   吉鹏   init
176
      component: Layout,
3d3cdb68f   Adam   auto commit the c...
177
      redirect: '/meta/page',
d7d9c38c2   Adam   auto commit the c...
178
      alwaysShow: true, // will always show the root menu
3d3cdb68f   Adam   auto commit the c...
179
      name: 'Meta',
1172ebb79   Adam   auto commit the c...
180
      meta: {
3d3cdb68f   Adam   auto commit the c...
181
        title: 'Meta',
d7d9c38c2   Adam   auto commit the c...
182
        icon: 'lock',
3d3cdb68f   Adam   auto commit the c...
183
        roles: ['admin', 'assistant'] // you can set roles in root nav
1172ebb79   Adam   auto commit the c...
184
      },
d7d9c38c2   Adam   auto commit the c...
185
186
187
188
      children: [
        {
          path: 'page',
          component: () => import('@/views/permission/page'),
3d3cdb68f   Adam   auto commit the c...
189
          name: 'MetaList',
1172ebb79   Adam   auto commit the c...
190
          meta: {
3d3cdb68f   Adam   auto commit the c...
191
192
            title: 'MetaList',
            roles: ['admin', 'assistant'] // or you can only set roles in sub nav
1172ebb79   Adam   auto commit the c...
193
          }
80a28914e   吉鹏   init
194
195
        },
        {
3d3cdb68f   Adam   auto commit the c...
196
          path: 'defined',
d7d9c38c2   Adam   auto commit the c...
197
          component: () => import('@/views/permission/directive'),
3d3cdb68f   Adam   auto commit the c...
198
          name: 'MetaDefiend',
1172ebb79   Adam   auto commit the c...
199
          meta: {
3d3cdb68f   Adam   auto commit the c...
200
201
            title: 'MetaDefiend',
            roles: ['admin', 'assistant']
d7d9c38c2   Adam   auto commit the c...
202
            // if do not set roles, means: this page does not require permission
1172ebb79   Adam   auto commit the c...
203
          }
3d3cdb68f   Adam   auto commit the c...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        }
      ]
    },
    {
      path: '/users',
      component: Layout,
      redirect: '/users/page',
      alwaysShow: true, // will always show the root menu
      name: 'Users',
      meta: {
        title: 'Users',
        icon: 'lock',
        roles: ['admin', 'assistant'] // you can set roles in root nav
      },
      children: [
        {
          path: 'page',
          component: () => import('@/views/permission/page'),
          name: 'UserList',
          meta: {
            title: 'UserList',
            roles: ['admin', 'assistant'] // or you can only set roles in sub nav
          }
1172ebb79   Adam   auto commit the c...
227
        },
80a28914e   吉鹏   init
228
        {
3d3cdb68f   Adam   auto commit the c...
229
230
231
          path: 'defined',
          component: () => import('@/views/permission/directive'),
          name: 'UserDefiend',
1172ebb79   Adam   auto commit the c...
232
          meta: {
3d3cdb68f   Adam   auto commit the c...
233
234
235
            title: 'UserDefiend',
            roles: ['admin', 'assistant']
            // if do not set roles, means: this page does not require permission
1172ebb79   Adam   auto commit the c...
236
          }
80a28914e   吉鹏   init
237
238
        }
      ]
1172ebb79   Adam   auto commit the c...
239
    },
80a28914e   吉鹏   init
240
    {
3d3cdb68f   Adam   auto commit the c...
241
      path: '/prod',
80a28914e   吉鹏   init
242
      component: Layout,
3d3cdb68f   Adam   auto commit the c...
243
244
245
246
247
248
249
250
      redirect: '/prod/page',
      alwaysShow: true, // will always show the root menu
      name: 'Prod',
      meta: {
        title: 'Prod',
        icon: 'lock',
        roles: ['admin', 'assistant', 'runner', 'shoper'] // you can set roles in root nav
      },
d7d9c38c2   Adam   auto commit the c...
251
      children: [
80a28914e   吉鹏   init
252
        {
3d3cdb68f   Adam   auto commit the c...
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
          path: 'page',
          component: () => import('@/views/permission/page'),
          name: 'ProdList',
          meta: {
            title: 'ProdList',
            roles: ['admin', 'assistant', 'runner', 'shoper'] // or you can only set roles in sub nav
          }
        },
        {
          path: 'defined',
          component: () => import('@/views/permission/directive'),
          name: 'ProdDefiend',
          meta: {
            title: 'ProdDefiend',
            roles: ['admin', 'assistant', 'shoper']
            // if do not set roles, means: this page does not require permission
          }
80a28914e   吉鹏   init
270
271
272
        }
      ]
    },
3d3cdb68f   Adam   auto commit the c...
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
    {
      path: '/order',
      component: Layout,
      redirect: '/order/page',
      alwaysShow: true, // will always show the root menu
      name: 'Order',
      meta: {
        title: 'Order',
        icon: 'lock',
        roles: ['admin', 'assistant', 'runner', 'shoper'] // you can set roles in root nav
      },
      children: [
        {
          path: 'page',
          component: () => import('@/views/permission/page'),
          name: 'OrderList',
          meta: {
            title: 'OrderList',
            roles: ['admin', 'assistant', 'runner', 'shoper'] // or you can only set roles in sub nav
          }
        },
        {
          path: 'defined',
          component: () => import('@/views/permission/directive'),
          name: 'OrderDefiend',
          meta: {
            title: 'OrderDefiend',
            roles: ['admin', 'assistant', 'runner', 'shoper']
            // if do not set roles, means: this page does not require permission
          }
        }
      ]
    },
    {
      path: '/site',
      component: Layout,
      redirect: '/site/page',
      alwaysShow: true, // will always show the root menu
      name: 'Site',
      meta: {
        title: 'Site',
        icon: 'lock',
        roles: ['admin', 'assistant', 'runner'] // you can set roles in root nav
      },
      children: [
        {
          path: 'page',
          component: () => import('@/views/permission/page'),
          name: 'SiteList',
          meta: {
            title: 'SiteList',
            roles: ['admin', 'assistant', 'runner'] // or you can only set roles in sub nav
          }
        },
        {
          path: 'defined',
          component: () => import('@/views/permission/directive'),
          name: 'SiteDefiend',
          meta: {
            title: 'SiteDefiend',
            roles: ['admin', 'assistant', 'runner']
            // if do not set roles, means: this page does not require permission
          }
        }
      ]
    },
    {
      path: '/system',
      component: Layout,
      redirect: '/system/page',
      alwaysShow: true, // will always show the root menu
      name: 'System',
      meta: {
        title: 'System',
        icon: 'lock',
        roles: ['admin', 'assistant', 'runner'] // you can set roles in root nav
      },
      children: [
        {
          path: 'page',
          component: () => import('@/views/permission/page'),
          name: 'SystemList',
          meta: {
            title: 'SystemList',
            roles: ['admin', 'assistant', 'runner'] // or you can only set roles in sub nav
          }
        },
        {
          path: 'defined',
          component: () => import('@/views/permission/directive'),
          name: 'SystemDefiend',
          meta: {
            title: 'SystemDefiend',
            roles: ['admin', 'assistant', 'runner']
            // if do not set roles, means: this page does not require permission
          }
        }
      ]
    },
    // {
    //   path: '/icon',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/icons/index'),
    //       name: 'Icons',
    //       meta: { title: 'icons', icon: 'icon', noCache: true }
    //     }
    //   ]
    // },
d7d9c38c2   Adam   auto commit the c...
384
385
386
387
  
    /** when your routing map is too long, you can split it into small modules **/
    componentsRouter,
    chartsRouter,
3d3cdb68f   Adam   auto commit the c...
388
    // nestedRouter,
d7d9c38c2   Adam   auto commit the c...
389
    tableRouter,
3d3cdb68f   Adam   auto commit the c...
390
    userRouter,
d7d9c38c2   Adam   auto commit the c...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  
    // {
    //   path: '/example',
    //   component: Layout,
    //   redirect: '/example/list',
    //   name: 'Example',
    //   meta: {
    //     title: 'example',
    //     icon: 'example'
    //   },
    //   children: [
    //     {
    //       path: 'create',
    //       component: () => import('@/views/example/create'),
    //       name: 'CreateArticle',
    //       meta: { title: 'createArticle', icon: 'edit' }
    //     },
    //     {
    //       path: 'edit/:id(\\d+)',
    //       component: () => import('@/views/example/edit'),
    //       name: 'EditArticle',
    //       meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
    //       hidden: true
    //     },
    //     {
    //       path: 'list',
    //       component: () => import('@/views/example/list'),
    //       name: 'ArticleList',
    //       meta: { title: 'articleList', icon: 'list' }
    //     }
    //   ]
    // },
3d3cdb68f   Adam   auto commit the c...
423
424
425
426
427
428
429
430
431
432
433
434
    // {
    //   path: '/tab',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/tab/index'),
    //       name: 'Tab',
    //       meta: { title: 'tab', icon: 'tab' }
    //     }
    //   ]
    // },
d7d9c38c2   Adam   auto commit the c...
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
  
    // {
    //   path: '/error',
    //   component: Layout,
    //   redirect: 'noRedirect',
    //   name: 'ErrorPages',
    //   meta: {
    //     title: 'errorPages',
    //     icon: '404'
    //   },
    //   children: [
    //     {
    //       path: '401',
    //       component: () => import('@/views/error-page/401'),
    //       name: 'Page401',
    //       meta: { title: 'page401', noCache: true }
    //     },
    //     {
    //       path: '404',
    //       component: () => import('@/views/error-page/404'),
    //       name: 'Page404',
    //       meta: { title: 'page404', noCache: true }
    //     }
    //   ]
    // },
  
    // {
    //   path: '/error-log',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'log',
    //       component: () => import('@/views/error-log/index'),
    //       name: 'ErrorLog',
    //       meta: { title: 'errorLog', icon: 'bug' }
    //     }
    //   ]
    // },
  
    // {
    //   path: '/excel',
    //   component: Layout,
    //   redirect: '/excel/export-excel',
    //   name: 'Excel',
    //   meta: {
    //     title: 'excel',
    //     icon: 'excel'
    //   },
    //   children: [
    //     {
    //       path: 'export-excel',
    //       component: () => import('@/views/excel/export-excel'),
    //       name: 'ExportExcel',
    //       meta: { title: 'exportExcel' }
    //     },
    //     {
    //       path: 'export-selected-excel',
    //       component: () => import('@/views/excel/select-excel'),
    //       name: 'SelectExcel',
    //       meta: { title: 'selectExcel' }
    //     },
    //     {
    //       path: 'export-merge-header',
    //       component: () => import('@/views/excel/merge-header'),
    //       name: 'MergeHeader',
    //       meta: { title: 'mergeHeader' }
    //     },
    //     {
    //       path: 'upload-excel',
    //       component: () => import('@/views/excel/upload-excel'),
    //       name: 'UploadExcel',
    //       meta: { title: 'uploadExcel' }
    //     }
    //   ]
    // },
  
    // {
    //   path: '/zip',
    //   component: Layout,
    //   redirect: '/zip/download',
    //   alwaysShow: true,
    //   name: 'Zip',
    //   meta: { title: 'zip', icon: 'zip' },
    //   children: [
    //     {
    //       path: 'download',
    //       component: () => import('@/views/zip/index'),
    //       name: 'ExportZip',
    //       meta: { title: 'exportZip' }
    //     }
    //   ]
    // },
  
    // {
    //   path: '/pdf',
    //   component: Layout,
    //   redirect: '/pdf/index',
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/pdf/index'),
    //       name: 'PDF',
    //       meta: { title: 'pdf', icon: 'pdf' }
    //     }
    //   ]
    // },
    // {
    //   path: '/pdf/download',
    //   component: () => import('@/views/pdf/download'),
    //   hidden: true
    // },
3d3cdb68f   Adam   auto commit the c...
546
547
548
549
550
551
552
553
554
555
556
557
    // {
    //   path: '/theme',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/theme/index'),
    //       name: 'Theme',
    //       meta: { title: 'theme', icon: 'theme' }
    //     }
    //   ]
    // },
1172ebb79   Adam   auto commit the c...
558

d7d9c38c2   Adam   auto commit the c...
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
    // {
    //   path: '/clipboard',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/clipboard/index'),
    //       name: 'ClipboardDemo',
    //       meta: { title: 'clipboardDemo', icon: 'clipboard' }
    //     }
    //   ]
    // },
  
    // {
    //   path: '/i18n',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/i18n-demo/index'),
    //       name: 'I18n',
    //       meta: { title: 'i18n', icon: 'international' }
    //     }
    //   ]
    // },
  
    // {
    //   path: 'external-link',
    //   component: Layout,
    //   children: [
    //     {
    //       path: 'https://github.com/PanJiaChen/vue-element-admin',
    //       meta: { title: 'externalLink', icon: 'link' }
    //     }
    //   ]
    // },
80a28914e   吉鹏   init
595
    // 404 page must be placed at the end !!!
d7d9c38c2   Adam   auto commit the c...
596
    { path: '*', redirect: '/404', hidden: true }
80a28914e   吉鹏   init
597
598
599
600
  ]
  
  const createRouter = () => new Router({
    // mode: 'history', // require service support
d7d9c38c2   Adam   auto commit the c...
601
    scrollBehavior: () => ({ y: 0 }),
80a28914e   吉鹏   init
602
603
604
605
606
607
608
609
610
611
612
613
    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
  }
  
  export default router