12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import router from '@/router'
- import { RouteLocationNormalized } from 'vue-router'
- import { useStore } from './store'
- import { UserActionTypes } from './store/modules/user/action-types'
- // import { getUrlaccessToken } from '@/utils/https'
- import { getToken, setCookieMac, setToken } from '@/utils/cookies'
- import { Toast } from 'vant'
- import Cookies from 'js-cookie'
- import { getUrlParams } from './utils/https'
- router.beforeEach(async (to: RouteLocationNormalized, _: RouteLocationNormalized, next: any) => {
- const store = useStore()
- let macAdr: string = getUrlParams('mac')
- if (macAdr) {
- setCookieMac(macAdr)
- }
- await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
- next()
- // const store = useStore()
- // const accessToken: any = getUrlaccessToken()
- // if (accessToken) {
- // setToken(accessToken)
- // }
- // if (process.env.VUE_APP_BASE_API !== '/borui/') {
- // if (to.path === '/home') {
- // next()
- // } else {
- // if (getToken()) {
- // if (store.state.user.userId) {
- // next()
- // } else {
- // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
- // next()
- // }
- // } else {
- // sessionStorage.clear()
- // const tokenOld: any = Cookies.get('accessToken')
- // if (to.path !== '/home') {
- // window.location.href = `/sgh5/home?accessToken=${tokenOld}`
- // }
- // Toast('登录失效,请退出app重新登录')
- // }
- // }
- // } else {
- // if (store.state.user.userId) {
- // next()
- // } else {
- // await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined)
- // next()
- // }
- // }
- })
- router.afterEach((to: RouteLocationNormalized) => {
- // console.log(to)
- // Finish progress bar
- // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
- // set page title
- // document.title = getPageTitle(to.meta.title)
- })
|