permission.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import Vue from 'vue'
  2. import router from './router'
  3. import store from './store'
  4. import NProgress from 'nprogress' // progress bar
  5. import 'nprogress/nprogress.css' // progress bar style
  6. import notification from 'ant-design-vue/es/notification'
  7. import { ACCESS_TOKEN } from '@/store/mutation-types'
  8. import { generateIndexRouter } from "@/utils/util"
  9. import warterMark from './warterMark'
  10. import { mapGetters, mapMutations, mapActions } from 'vuex'
  11. import { cmpPos } from 'codemirror'
  12. NProgress.configure({ showSpinner: false }) // NProgress Configuration
  13. const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration', '/user/transfer-local', '/errorPage', '/user/new-batch', '/user/lookPreview', 'http://192.168.0.111:8088/jeecg-boot/sys/feishu/url', '/user/FStransfer', '/creat-config', '/create-launch', '/boss-data-kanban'] // no redirect whitelist
  14. router.beforeEach((to, from, next) => {
  15. NProgress.start() // start progress bar
  16. //if (whiteList.indexOf(to.path) !== -1) {
  17. // 在免登录白名单,直接进入
  18. // next()
  19. //}
  20. console.log(to,from)
  21. if (Vue.ls.get(ACCESS_TOKEN)) {
  22. console.log(store.getters.userInfo.id);
  23. /* has token */
  24. if (to.path === '/user/login') {
  25. warterMark.out();
  26. next({ path: '/dashboard/workplace' })
  27. NProgress.done()
  28. } else {
  29. // warterMark.set(store.getters.userInfo.roleName)
  30. if (store.getters.permissionList.length === 0) {
  31. store.dispatch('GetPermissionList').then(res => {
  32. const menuData = res.result.menu;
  33. localStorage.setItem("roleCode", res.result.roleCode)
  34. if (menuData === null || menuData === "" || menuData === undefined) {
  35. return;
  36. }
  37. let constRoutes = [];
  38. constRoutes = generateIndexRouter(menuData);
  39. // 添加主界面路由
  40. store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
  41. // 根据roles权限生成可访问的路由表
  42. // 动态添加可访问路由表
  43. router.addRoutes(store.getters.addRouters)
  44. const redirect = decodeURIComponent(from.query.redirect || to.path)
  45. if (to.path === redirect) {
  46. // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
  47. next({ ...to, replace: true })
  48. } else {
  49. // 跳转到目的路由
  50. if( to.path === '/dashboard/analysis' && from.path == '/'){
  51. // if (store.getters.userInfo.id == '4aba62011120ac565c7f2b9f8f4aa96b' || store.getters.userInfo.id == 'e9ca23d68d884d4ebb19d07889727dae'|| store.getters.userInfo.id == 'db2d59e9b4a3b18629c838fd7f5b58d8') {
  52. // const a = document.createElement('a');
  53. // document.body.appendChild(a);
  54. // a.style.display = 'none';
  55. // a.href = 'http://adsp.c-top.com.cn/boss-data-kanban';
  56. // a.target = '_blank'
  57. // a.click();
  58. // document.body.removeChild(a);
  59. // // let tempPage = window.open('', '_blank');
  60. // // tempPage.location="/boss-data-kanban";
  61. // }
  62. }
  63. next({ path: redirect })
  64. }
  65. })
  66. })
  67. .catch(() => {
  68. /* notification.error({
  69. message: '系统提示',
  70. description: '请求用户信息失败,请重试!'
  71. })*/
  72. warterMark.out()
  73. store.dispatch('Logout').then(() => {
  74. next({ path: '/user/login', query: { redirect: to.fullPath } })
  75. })
  76. })
  77. } else {
  78. warterMark.set(store.getters.userInfo.realname)
  79. next()
  80. }
  81. if( to.path === '/dashboard/analysis' && from.path == '/'){
  82. // if (store.getters.userInfo.id == '4aba62011120ac565c7f2b9f8f4aa96b' || store.getters.userInfo.id == 'e9ca23d68d884d4ebb19d07889727dae' || store.getters.userInfo.id == 'db2d59e9b4a3b18629c838fd7f5b58d8') {
  83. // const a = document.createElement('a');
  84. // document.body.appendChild(a);
  85. // a.style.display = 'none';
  86. // a.href = 'http://adsp.c-top.com.cn/boss-data-kanban';
  87. // a.target = '_blank'
  88. // a.click();
  89. // document.body.removeChild(a);
  90. // // let tempPage = window.open('', '_blank');
  91. // // tempPage.location="/boss-data-kanban";
  92. // return
  93. // }
  94. }
  95. }
  96. } else {
  97. if (whiteList.indexOf(to.path) !== -1) {
  98. // 在免登录白名单,直接进入
  99. // warterMark.set(store.getters.userInfo.roleName)
  100. next()
  101. } else {
  102. warterMark.out()
  103. next({ path: '/user/login', query: { redirect: to.fullPath } })
  104. NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
  105. }
  106. }
  107. })
  108. router.afterEach(() => {
  109. NProgress.done() // finish progress bar
  110. })