|
@@ -4,14 +4,11 @@ import { Message } from 'element-ui'
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
import getPageTitle from '@/utils/get-page-title'
|
|
|
|
|
|
-const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
|
|
|
+const whiteList = ['/login', '/auth-redirect']
|
|
|
const toSupplier = ['/supplier/list', '/supplier']
|
|
|
|
|
|
-// const onlyPath = ['/auth/list', '/product/list', '/product/add', '/product/edit']
|
|
|
-
|
|
|
router.beforeEach(async(to, from, next) => {
|
|
|
// 设置页面名称
|
|
|
- // eslint-disable-next-line indent
|
|
|
document.title = getPageTitle(to.meta.title)
|
|
|
// 获取token
|
|
|
const hasToken = getToken()
|
|
@@ -25,7 +22,6 @@ router.beforeEach(async(to, from, next) => {
|
|
|
if (toSupplier.includes(to.path) && store.getters.proxyInfo !== null) {
|
|
|
store.dispatch('tagsView/delAllProxyView')
|
|
|
store.commit('user/SET_PROXY_INFO', null)
|
|
|
- console.log('关闭其他的标签')
|
|
|
}
|
|
|
|
|
|
if (to.path === '/login') {
|
|
@@ -34,7 +30,8 @@ router.beforeEach(async(to, from, next) => {
|
|
|
} else {
|
|
|
// 加载国家列表
|
|
|
store.dispatch('app/setCountry')
|
|
|
- const hasInitRouter = store.getters.initRouter // 是否需要初始化路由
|
|
|
+ // 是否需要初始化路由
|
|
|
+ const hasInitRouter = store.getters.initRouter
|
|
|
if (hasInitRouter) {
|
|
|
next()
|
|
|
} else {
|
|
@@ -48,29 +45,26 @@ router.beforeEach(async(to, from, next) => {
|
|
|
// 设置路由
|
|
|
router.addRoutes(accessRoutes)
|
|
|
|
|
|
- // 开启会话
|
|
|
+ // 初始化会话信息 条件:当前用户为管理员 && socket对象已创建成功
|
|
|
if (!store.getters.socketState && store.getters.userIdentity === 1) {
|
|
|
store.dispatch('webSocket/initMessage')
|
|
|
}
|
|
|
|
|
|
- // hack method to ensure that addRoutes is complete
|
|
|
- // set the replace: true, so the navigation will not leave a history record
|
|
|
next({ ...to, replace: true })
|
|
|
} catch (error) {
|
|
|
- // remove token and go to login page to re-login
|
|
|
- await store.dispatch('user/resetToken')
|
|
|
+ store.dispatch('user/resetToken')
|
|
|
Message.error(error || '未知错误,请重新登录')
|
|
|
next(`/login?redirect=${to.path}`)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- /* has no token*/
|
|
|
+ // token不存在并且访问的路由非拦截路由
|
|
|
if (whiteList.indexOf(to.path) !== -1) {
|
|
|
- // in the free login whitelist, go directly
|
|
|
+ // 允许访问
|
|
|
next()
|
|
|
} else {
|
|
|
- // other pages that do not have permission to access are redirected to the login page.
|
|
|
+ // 跳转到登录页面
|
|
|
Message({ message: '登录失效,请重新登录!', duration: 1500 })
|
|
|
next(`/login`)
|
|
|
return
|