import router from './router' import useStore from './store/piniaIndex' import { obtainUrlPathParameterTarget } from '@/utils/index.js' import { setToken, getToken, removeToken } from '@/utils/auth' import { Notify } from 'vant' let whiteList = ['/home'] router.beforeEach(async (to, from, next) => { //pinia挂载顺序问题异步处理路由拦截 setTimeout(() => { let store = useStore() //获取状态 let token = getToken() //获取cookie // removeToken() !whiteList.includes(to.path) && store.getPosition() // store.login({ username: '15098826302', networkId: '1522478429548756992' }) if (!token) { // let paramsTarget = obtainUrlPathParameterTarget(location.href) // sessionStorage.setItem('paramsTarget', JSON.stringify(paramsTarget)) // store.login(paramsTarget).then( // () => { // next() // }, // () => { // Notify('登陆失败,请退出重试') // } // ) let paramsTarget = obtainUrlPathParameterTarget(location.href) if (paramsTarget.token) { // sessionStorage.setItem('h5Token',) setToken(paramsTarget.token) store.getUser() next() } else Notify('登陆失败,请退出重试') return } if (!store.user) { store.getUser() } //检测到没有token直接登录 // if (!token) { // if (typeof data == 'object' && data?.accessToken) { // store.login(data) // } // } //拦截 如果不是去首页 还没有token直接去首页 // if (to.path !== '/home' && !token) { // Notify('请检查登陆状态') // next({ path: '/' }) // } else { // } next() }, 0) }) router.afterEach(() => {})