积分商城后台管理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
2.0 KiB

import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import {addressResolution} from '@/utils/tools'
// import { getToken, getNet, getUsername, getPassword, getChecked } from '@/utils/auth'
import getPageTitle from '@/utils/get-page-title'
// import vue from 'vue'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/financeLogin', '/webView', '/OfficialAccounts']
// const loginForm = {}
router.beforeEach(async (to, from, next) => {
let url = window.location.href.substring(0,window.location.href.indexOf('#/'))
NProgress.start()
document.title = getPageTitle(to.meta.title)
const hasToken = getToken();
let routerData = addressResolution(url)||null;
if(routerData!==null){
if(routerData.hasOwnProperty('code')&&routerData.hasOwnProperty('state')&&to.path!=='/OfficialAccounts' ){
console.log(routerData)
}
}
if (hasToken) {
// 有token时,登录页直接跳转到首页
if (to.path === '/login') {
// 如果是跳转到登录,就默认跳转到首页
next({ path: '/' })
NProgress.done()
} else {
const hasAuth = store.getters.auths && store.getters.auths.length > 0
if (hasAuth) {
next()
} else {
try {
await store.dispatch('user/getInfo')
const accessRoutes = await store.dispatch('permission/generateRoutes');
console.log(accessRoutes,"routerrouterrouter")
router.addRoutes(accessRoutes);
next({ ...to, replace: true })
} catch (error) {
await store.dispatch('user/resetToken')
Message.error(error || 'Has Error')
next(`/login`)
NProgress.done()
}
}
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
next(`/login`)
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})