Commit 0d10fa495bc6ff39d49da9a4d9b9c2e6f8226283

Authored by yangzhi
1 parent 709bad86

超哥牛批

Showing 1 changed file with 179 additions and 179 deletions
src/utils/routerList.js
... ... @@ -2,13 +2,14 @@ import Layout from '@/layout'
2 2 import { getInfo } from '../store/modules/user.js'
3 3  
4 4  
5   -export function getRoutes() {
6   -
  5 +export function getRoutes(permissions) {
7 6 let userInfo = {}
8 7 if (localStorage.userinfo) {
9 8 userInfo = JSON.parse(localStorage.userinfo)
10 9 }
11   - console.log(userInfo)
  10 + var permissions = userInfo.permissions || [];
  11 +
  12 +
12 13 let constantRoutes1 = []
13 14 if (userInfo.UserId == 1) {
14 15 constantRoutes1 = [{
... ... @@ -298,7 +299,6 @@ export function getRoutes() {
298 299 import ('@/views/resume/femalestaff.vue'),
299 300 hidden: true
300 301 },
301   -
302 302 {
303 303 path: '/live',
304 304 name: '直播',
... ... @@ -329,167 +329,61 @@ export function getRoutes() {
329 329 }]
330 330 },
331 331  
332   - // {
333   - // path: '/example',
334   - // component: Layout,
335   - // redirect: '/example/table',
336   - // name: 'Example',
337   - // meta: {
338   - // title: '题库管理',
339   - // icon: 'el-icon-s-help'
340   - // },
341   - // children: [{
342   - // path: 'QuestionBank',
343   - // name: 'Table',
344   - // component: () => import('@/views/QuestionBank/index'),
345   - // meta: {
346   - // title: '题库',
347   - // icon: 'table'
348   - // }
349   - // }]
350   - // },
351 332 {
352   - path: '/moduleIndex',
353   - component: Layout,
354   - redirect: '/module/index',
355   - name: 'module',
356   - meta: {
357   - title: '练习',
358   - icon: 'el-icon-s-help'
359   - },
360   - children: [{
361   - path: 'recharge',
362   - name: 'recharge',
363   - component: () =>
364   - import ('@/views/module/index'),
365   - meta: {
366   - title: '练习',
367   - icon: 'el-icon-s-operation'
368   - }
369   - },
370   - {
371   - path: 'index',
372   - name: 'index',
373   - component: () =>
374   - import ('@/views/TestPaper/index'),
375   - hidden: true,
376   - meta: {
377   - title: '试卷维护',
378   - icon: 'table'
379   - }
380   - },
381   - ]
382   - },
383   - {
384   - path: '/realQuestion',
  333 + path: '/example',
385 334 component: Layout,
386   - redirect: '/module/realQuestion',
387   - name: 'realQuestion',
  335 + redirect: '/example/table',
  336 + name: 'Example',
388 337 meta: {
389   - title: '历年真题',
  338 + title: '题库管理',
390 339 icon: 'el-icon-s-help'
391 340 },
392 341 children: [{
393   - path: 'recharge',
394   - name: 'recharge',
  342 + path: 'QuestionBank',
  343 + name: 'Table',
395 344 component: () =>
396   - import ('@/views/module/realQuestion'),
  345 + import ('@/views/QuestionBank/index'),
397 346 meta: {
398   - title: '历年真题',
399   - icon: 'el-icon-s-management'
  347 + title: '题库',
  348 + icon: 'table'
400 349 }
401 350 }]
402 351 },
  352 +
403 353 {
404   - path: '/simulation',
  354 + path: '/views',
405 355 component: Layout,
406   - redirect: '/module/simulation',
407   - name: 'module',
  356 + redirect: '/views/TestPaper',
  357 + name: 'TestPaper',
408 358 meta: {
409   - title: '模拟试卷',
  359 + title: '试卷管理',
410 360 icon: 'el-icon-s-help'
411 361 },
412 362 children: [{
413   - path: 'recharge',
414   - name: 'recharge',
415   - component: () =>
416   - import ('@/views/module/simulation'),
417   - meta: {
418   - title: '模拟试卷',
419   - icon: 'el-icon-s-promotion'
420   - }
421   - }]
422   - },
423   -
424   - // {
425   - // path: '/views',
426   - // component: Layout,
427   - // redirect: '/views/TestPaper',
428   - // name: 'TestPaper',
429   - // meta: {
430   - // title: '试卷管理',
431   - // icon: 'el-icon-s-help'
432   - // },
433   - // children: [
434   - // {
435   - // path: 'TestPaperList',
436   - // name: 'Table',
437   - // component: () => import('@/views/TestPaper/TestPaperList'),
438   - // meta: {
439   - // title: '试卷列表',
440   - // icon: 'table'
441   - // }
442   - // },
443   - // {
444   - // path: 'index',
445   - // name: 'index',
446   - // component: () => import('@/views/TestPaper/index'),
447   - // hidden: true,
448   - // meta: {
449   - // title: '试卷维护',
450   - // icon: 'table'
451   - // }
452   - // },
453   - // // {
454   - // // path: 'ManualTestPaper',
455   - // // name: 'Table',
456   - // // component: () => import('@/views/TestPaper/ManualTestPaper'),
457   - // // meta: {
458   - // // title: '组卷',
459   - // // icon: 'table'
460   - // // }
461   - // // },
  363 + path: 'TestPaperList',
  364 + name: 'Table',
  365 + component: () =>
  366 + import ('@/views/TestPaper/TestPaperList'),
  367 + meta: {
  368 + title: '试卷列表',
  369 + icon: 'table'
  370 + }
  371 + },
  372 + {
  373 + path: 'ManualTestPaper',
  374 + name: 'Table',
  375 + component: () =>
  376 + import ('@/views/TestPaper/ManualTestPaper'),
  377 + meta: {
  378 + title: '组卷',
  379 + icon: 'table'
  380 + }
  381 + },
462 382  
463   - // ]
464   - // },
465   - {
466   - path: '/order',
467   - component: Layout,
468   - redirect: '/',
469   - name: 'order',
470   - meta: {
471   - title: '订单管理',
472   - icon: 'el-icon-s-marketing'
473   - },
474   - children: [{
475   - path: 'recharge',
476   - name: 'recharge',
477   - component: () =>
478   - import ('@/views/order/rechargeList'),
479   - meta: {
480   - title: '充值记录',
481   - }
482   - }, {
483   - path: 'shop',
484   - name: 'shop',
485   - component: () =>
486   - import ('@/views/order/shopList'),
487   - meta: {
488   - title: '购买记录',
489   - }
490   - }]
  383 + ]
491 384 },
492 385 {
  386 + code: '用户管理',
493 387 path: '/user',
494 388 component: Layout,
495 389 redirect: '/',
... ... @@ -499,15 +393,48 @@ export function getRoutes() {
499 393 icon: 'el-icon-s-help'
500 394 },
501 395 children: [{
  396 + code: '人才库',
502 397 path: 'user',
503 398 name: 'User',
504 399 component: () =>
505 400 import ('@/views/user/userlist'),
506 401 meta: {
507   - title: '普通用户列表',
  402 + title: '人才库',
508 403 }
509 404 },
  405 + {
  406 + code: '面试时间表',
  407 + path: 'interviewSchedule',
  408 + name: 'interviewSchedule',
  409 + component: () =>
  410 + import ('@/views/user/InterviewSchedule'),
  411 + meta: {
  412 + title: '面试时间表',
  413 + }
  414 + },
  415 +
  416 + {
  417 + code: 'importuser',
  418 + path: 'importuser',
  419 + name: 'importuser',
510 420  
  421 + component: () =>
  422 + import ('@/views/user/picuserimport'),
  423 + meta: {
  424 + title: '图片导入用户',
  425 + }
  426 + },
  427 + {
  428 + code: 'admin',
  429 + path: 'admin',
  430 + name: 'admin',
  431 + component: () =>
  432 + import ('@/views/user/adminList'),
  433 + meta: {
  434 + title: '管理员列表',
  435 + permissions: ['admin']
  436 + }
  437 + },
511 438  
512 439 ]
513 440 }, {
... ... @@ -519,49 +446,122 @@ export function getRoutes() {
519 446 title: '系统管理',
520 447 icon: 'el-icon-s-platform'
521 448 },
  449 +
522 450 children: [{
523   - path: 'index',
524   - name: 'index',
525   - component: () =>
526   - import ('@/views/password/index'),
527   - meta: {
528   - title: '忘记密码',
529   - }
530   - }, {
531   - path: 'TestPaperClass',
532   - name: 'Table',
533   - component: () =>
534   - import ('@/views/TestPaper/TestPaperClass'),
535   - meta: {
536   - title: '分类管理',
537   - }
538   - }, {
539   - path: 'carousel',
540   - name: 'carousel',
541   - component: () =>
542   - import ('@/views/carousel/index'),
543   - meta: {
544   - title: '轮播图',
545   - }
546   - }, {
547   - path: 'new',
548   - name: 'new',
549   - component: () =>
550   - import ('@/views/carousel/new'),
551   - meta: {
552   - title: '最新资讯',
553   - }
554   - }]
  451 + path: 'userdimset',
  452 + name: 'impouserdimsetrtuser',
  453 +
  454 + component: () =>
  455 + import ('@/views/user/userdimset'),
  456 + meta: {
  457 + title: '维度规则设置',
  458 + permissions: ['admin']
  459 + }
  460 + },
  461 + {
  462 + path: 'index',
  463 + name: 'index',
  464 + component: () =>
  465 + import ('@/views/password/index'),
  466 + meta: {
  467 + title: '忘记密码',
  468 + }
  469 + },
  470 +
  471 + {
  472 + code: 'settings',
  473 + path: 'settings',
  474 + name: 'settings',
  475 + component: () =>
  476 + import ('@/views/settings/index'),
  477 + meta: {
  478 + title: '系统设置',
  479 + }
  480 + },
  481 + {
  482 + path: 'TestPaperClass',
  483 + name: 'Table',
  484 + component: () =>
  485 + import ('@/views/TestPaper/TestPaperClass'),
  486 + meta: {
  487 + title: '分类管理',
  488 + permissions: ['admin']
  489 + }
  490 + }, {
  491 + path: 'carousel',
  492 + name: 'carousel',
  493 + component: () =>
  494 + import ('@/views/carousel/index'),
  495 + meta: {
  496 + title: '轮播图',
  497 + permissions: ['admin']
  498 + }
  499 + }, {
  500 + path: 'new',
  501 + name: 'new',
  502 + component: () =>
  503 + import ('@/views/carousel/new'),
  504 + meta: {
  505 + title: '最新资讯',
  506 + permissions: ['admin']
  507 + }
  508 + }, {
  509 + code: 'rolelist',
  510 + path: 'role',
  511 + name: 'rolelist',
  512 + component: () =>
  513 + import ('@/views/user/rolelist'),
  514 + meta: {
  515 + title: '角色权限',
  516 + permissions: ['admin']
  517 + }
  518 + },
  519 + {
  520 + code: 'logs',
  521 + path: 'logs',
  522 + name: 'logs',
  523 +
  524 + component: () =>
  525 + import ('@/views/user/loglist'),
  526 + meta: {
  527 + title: '系统日志',
  528 + }
  529 + },
  530 + ]
555 531 },
556 532 // 404 page must be placed at the end !!!
557 533 {
558 534 path: '*',
559 535 redirect: '/404',
560   - hidden: true
  536 + hidden: true
561 537 }
562 538 ]
563 539 }
564 540  
565 541  
  542 + function hasPermission(permissions, route) {
  543 + if (route.meta && route.meta.permissions) {
  544 + return permissions.some((role) => route.meta.permissions.includes(role));
  545 + } else {
  546 + return true;
  547 + }
  548 + }
  549 +
  550 +
  551 + function filterAsyncRoutes(routes, permissions) {
  552 + const finallyRoutes = [];
  553 + routes.forEach((route) => {
  554 + const item = {...route };
  555 + if (hasPermission(permissions, item)) {
  556 + if (item.children) {
  557 + item.children = filterAsyncRoutes(item.children, permissions);
  558 + }
  559 + finallyRoutes.push(item);
  560 + }
  561 + });
  562 + return finallyRoutes;
  563 + }
  564 + constantRoutes1 = filterAsyncRoutes(constantRoutes1, permissions);
  565 +
566 566 return constantRoutes1;
567 567 }
568 568 \ No newline at end of file
... ...