permission.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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) {
  14. setCookieMac(macAdr)
  15. }
  16. await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  17. next()
  18. // const store = useStore()
  19. // const accessToken: any = getUrlaccessToken()
  20. // if (accessToken) {
  21. // setToken(accessToken)
  22. // }
  23. // if (process.env.VUE_APP_BASE_API !== '/borui/') {
  24. // if (to.path === '/home') {
  25. // next()
  26. // } else {
  27. // if (getToken()) {
  28. // if (store.state.user.userId) {
  29. // next()
  30. // } else {
  31. // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  32. // next()
  33. // }
  34. // } else {
  35. // sessionStorage.clear()
  36. // const tokenOld: any = Cookies.get('accessToken')
  37. // if (to.path !== '/home') {
  38. // window.location.href = `/sgh5/home?accessToken=${tokenOld}`
  39. // }
  40. // Toast('登录失效,请退出app重新登录')
  41. // }
  42. // }
  43. // } else {
  44. // if (store.state.user.userId) {
  45. // next()
  46. // } else {
  47. // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
  48. // next()
  49. // }
  50. // }
  51. })
  52. router.afterEach((to: RouteLocationNormalized) => {
  53. // console.log(to)
  54. // Finish progress bar
  55. // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
  56. // set page title
  57. // document.title = getPageTitle(to.meta.title)
  58. })