permission.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import router from '@/router'
  2. import { RouteLocationNormalized } from 'vue-router'
  3. import { useStore } from './store'
  4. import { UserActionTypes } from './store/modules/user/action-types'
  5. // import { getUrlaccessToken } from '@/utils/https'
  6. import { getToken, setCookieMac, setToken } from '@/utils/cookies'
  7. import { Toast } from 'vant'
  8. import Cookies from 'js-cookie'
  9. import { getUrlParams } from './utils/https'
  10. router.beforeEach(async (to: RouteLocationNormalized, _: RouteLocationNormalized, next: any) => {
  11. const store = useStore()
  12. let macAdr: string = getUrlParams('mac')
  13. if (macAdr && macAdr != "null" && macAdr != "NULL") {
  14. setCookieMac(macAdr)
  15. localStorage.setItem('mac', macAdr)
  16. }
  17. await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  18. next()
  19. // const store = useStore()
  20. // const accessToken: any = getUrlaccessToken()
  21. // if (accessToken) {
  22. // setToken(accessToken)
  23. // }
  24. // if (process.env.VUE_APP_BASE_API !== '/borui/') {
  25. // if (to.path === '/home') {
  26. // next()
  27. // } else {
  28. // if (getToken()) {
  29. // if (store.state.user.userId) {
  30. // next()
  31. // } else {
  32. // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  33. // next()
  34. // }
  35. // } else {
  36. // sessionStorage.clear()
  37. // const tokenOld: any = Cookies.get('accessToken')
  38. // if (to.path !== '/home') {
  39. // window.location.href = `/sgh5/home?accessToken=${tokenOld}`
  40. // }
  41. // Toast('登录失效,请退出app重新登录')
  42. // }
  43. // }
  44. // } else {
  45. // if (store.state.user.userId) {
  46. // next()
  47. // } else {
  48. // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  49. // next()
  50. // }
  51. // }
  52. })
  53. router.afterEach((to: RouteLocationNormalized) => {
  54. // console.log(to)
  55. // Finish progress bar
  56. // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
  57. // set page title
  58. // document.title = getPageTitle(to.meta.title)
  59. })