permission.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 {
  8. ACCESS_TOKEN,
  9. INDEX_MAIN_PAGE_PATH,
  10. UI_CACHE_DB_DICT_DATA,
  11. USER_INFO,
  12. USER_NAME
  13. } from '@/store/mutation-types'
  14. import {
  15. generateIndexRouter,
  16. welcome
  17. } from '@/utils/util'
  18. NProgress.configure({
  19. showSpinner: false
  20. }) // NProgress Configuration
  21. const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration', '/FocusWarningPage', '/drillingRisk'] // no redirect whitelist
  22. if (process.env.VUE_APP_IFRAME_CHECK === 'TRUE') {
  23. whiteList.push('/top')
  24. }
  25. function initRouter() {
  26. router.beforeEach((to, from, next) => {
  27. NProgress.start() // start progress bar
  28. if (Vue.ls.get(ACCESS_TOKEN)) {
  29. /* has token */
  30. if (to.path === '/user/login') {
  31. next({
  32. path: INDEX_MAIN_PAGE_PATH
  33. })
  34. NProgress.done()
  35. } else {
  36. if (false && store.getters.permissionList.length === 0) {} else {
  37. next()
  38. }
  39. }
  40. } else {
  41. if (whiteList.indexOf(to.path) !== -1) {
  42. // 在免登录白名单,直接进入
  43. next()
  44. } else {
  45. if (process.env.VUE_APP_IFRAME_CHECK === 'TRUE') {
  46. next({
  47. path: '/top',
  48. query: {
  49. redirect: to.fullPath
  50. }
  51. })
  52. } else {
  53. next({
  54. path: '/user/login',
  55. query: {
  56. redirect: to.fullPath
  57. }
  58. })
  59. }
  60. NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
  61. }
  62. }
  63. })
  64. router.afterEach(() => {
  65. NProgress.done() // finish progress bar
  66. })
  67. }
  68. export default initRouter