|
@ -6,7 +6,6 @@ import 'nprogress/nprogress.css' // progress bar style |
|
|
import { getToken } from '@/utils/auth' // get token from cookie
|
|
|
import { getToken } from '@/utils/auth' // get token from cookie
|
|
|
import getPageTitle from '@/utils/get-page-title' |
|
|
import getPageTitle from '@/utils/get-page-title' |
|
|
import { asyncRoutes } from '@/router' |
|
|
import { asyncRoutes } from '@/router' |
|
|
import { getInterfaceBoard } from "@/api/wms-interface" |
|
|
|
|
|
import { login,getUsersByUserName } from "@/api/wms-auth" |
|
|
import { login,getUsersByUserName } from "@/api/wms-auth" |
|
|
|
|
|
|
|
|
NProgress.configure({ |
|
|
NProgress.configure({ |
|
@ -19,6 +18,16 @@ router.beforeEach(async (to, from, next) => { |
|
|
// set page title
|
|
|
// set page title
|
|
|
document.title = getPageTitle() |
|
|
document.title = getPageTitle() |
|
|
|
|
|
|
|
|
|
|
|
// 获取枚举数据
|
|
|
|
|
|
if(!store.getters.enumList || store.getters.enumList.length <= 0){ |
|
|
|
|
|
await store.dispatch('definition/getEnumList') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// // 获取表头转义
|
|
|
|
|
|
// if(!store.getters.columZHList || store.getters.columZHList.length <= 0){
|
|
|
|
|
|
// await store.dispatch('definition/getColumZHList')
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
// 判断是否自动登录
|
|
|
// 判断是否自动登录
|
|
|
let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) |
|
|
let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) |
|
|
const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") |
|
|
const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") |
|
@ -27,41 +36,49 @@ router.beforeEach(async (to, from, next) => { |
|
|
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ |
|
|
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ |
|
|
isAutoLogin = JSON.parse(_url_isAutoLogin) |
|
|
isAutoLogin = JSON.parse(_url_isAutoLogin) |
|
|
} |
|
|
} |
|
|
let userInfo = localStorage.getItem('currentUserInfo') |
|
|
|
|
|
// 是否有用户信息:
|
|
|
// 是否有用户信息:
|
|
|
|
|
|
const userInfo = store.getters.currentUserInfo |
|
|
// 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页)
|
|
|
// 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页)
|
|
|
// 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取
|
|
|
// 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取
|
|
|
if(userInfo){ |
|
|
if(userInfo){ |
|
|
|
|
|
console.log('有store.getters.currentUserInfo',store.getters.currentUserInfo) |
|
|
if(store.getters.permission_routes && store.getters.permission_routes.length > 0){ |
|
|
if(store.getters.permission_routes && store.getters.permission_routes.length > 0){ |
|
|
|
|
|
console.log('有store.getters.permission_routes',store.getters.permission_routes) |
|
|
next() |
|
|
next() |
|
|
}else{ |
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
console.log('没有store.getters.permission_routes',store.getters.permission_routes) |
|
|
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') |
|
|
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') |
|
|
router.addRoutes(accessRoutes) |
|
|
router.addRoutes(accessRoutes) |
|
|
console.log(52) |
|
|
|
|
|
next({ |
|
|
next({ |
|
|
...to, |
|
|
...to, |
|
|
query:{ |
|
|
query:{ |
|
|
loginName:from.query.loginName, |
|
|
loginName:to.query.loginName, |
|
|
isAutoLogin:from.query.isAutoLogin, |
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
|
|
|
isSinglePage:to.query.isSinglePage |
|
|
}, |
|
|
}, |
|
|
replace: true |
|
|
replace: true |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
|
|
|
// console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo)
|
|
|
if(!interfaceBoardColumnsNames){ |
|
|
if(!interfaceBoardColumnsNames){ |
|
|
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') |
|
|
console.log('没有interfaceBoardColumnsNames',interfaceBoardColumnsNames) |
|
|
router.addRoutes(accessRoutes) |
|
|
await store.dispatch('definition/getColumZHList') |
|
|
console.log(123,to) |
|
|
// const accessRoutes = await store.dispatch('permission/getApiColumnsNames')
|
|
|
|
|
|
// router.addRoutes(accessRoutes)
|
|
|
next({ |
|
|
next({ |
|
|
...to, |
|
|
...to, |
|
|
query:{ |
|
|
query:{ |
|
|
loginName:to.query.loginName, |
|
|
loginName:to.query.loginName, |
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
|
|
|
isSinglePage:to.query.isSinglePage |
|
|
}, |
|
|
}, |
|
|
replace: true |
|
|
replace: true |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
if(isAutoLogin || to.query.loginName){ |
|
|
if(isAutoLogin || to.query.loginName){ |
|
|
|
|
|
console.log('有自动登录',isAutoLogin,to.query.loginName) |
|
|
// let loginForm= {
|
|
|
// let loginForm= {
|
|
|
// userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"),
|
|
|
// userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"),
|
|
|
// password:localStorage.getItem("client_secret"),
|
|
|
// password:localStorage.getItem("client_secret"),
|
|
@ -71,32 +88,43 @@ router.beforeEach(async (to, from, next) => { |
|
|
// }
|
|
|
// }
|
|
|
// // store.dispatch('user/login', loginForm).then(() => {
|
|
|
// // store.dispatch('user/login', loginForm).then(() => {
|
|
|
// login(loginForm).then(()=>{
|
|
|
// login(loginForm).then(()=>{
|
|
|
let _username = to.query.loginName ? to.query.loginName : localStorage.getItem("userNameOrEmailAddress") |
|
|
let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") |
|
|
if(to.path != '/login'){ |
|
|
if(to.path != '/login'){ |
|
|
getUsersByUserName(_username).then(res=>{ |
|
|
await store.dispatch('user/getUserInfo',_username).then(()=>{ |
|
|
// todo:currentUserInfo全程需要优化
|
|
|
next({ |
|
|
if(res && JSON.stringify(res).length > 0){ |
|
|
...to, |
|
|
localStorage.setItem("currentUserInfo", JSON.stringify(res)); |
|
|
query:{ |
|
|
// next('/')
|
|
|
loginName:to.query.loginName, |
|
|
next({ |
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
...to, |
|
|
isSinglePage:to.query.isSinglePage |
|
|
query:{ |
|
|
}, |
|
|
loginName:to.query.loginName, |
|
|
replace: true |
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
}) |
|
|
}, |
|
|
}).catch(()=>{ |
|
|
replace: true |
|
|
next() |
|
|
}) |
|
|
// next({
|
|
|
}else{ |
|
|
// path:'/login',
|
|
|
next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) |
|
|
// query:{
|
|
|
// next(`/login`)
|
|
|
// isAutoLogin:to.query.isAutoLogin,
|
|
|
Message.error('获取用户信息失败,请重试') |
|
|
// isSinglePage:to.query.isSinglePage
|
|
|
} |
|
|
// },
|
|
|
}) |
|
|
// replace: true
|
|
|
.catch(err => { |
|
|
// })
|
|
|
console.log('获取用户信息失败,请重试') |
|
|
// next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`)
|
|
|
|
|
|
// next(`/login`)
|
|
|
|
|
|
Message.error('获取用户信息失败,请重试!') |
|
|
}) |
|
|
}) |
|
|
}else{ |
|
|
}else{ |
|
|
next() |
|
|
next() |
|
|
|
|
|
// next({
|
|
|
|
|
|
// ...to,
|
|
|
|
|
|
// query:{
|
|
|
|
|
|
// loginName:to.query.loginName,
|
|
|
|
|
|
// isAutoLogin:to.query.isAutoLogin,
|
|
|
|
|
|
// isSinglePage:to.query.isSinglePage
|
|
|
|
|
|
// },
|
|
|
|
|
|
// replace: true
|
|
|
|
|
|
// })
|
|
|
} |
|
|
} |
|
|
// })
|
|
|
// })
|
|
|
// .catch((error) => {
|
|
|
// .catch((error) => {
|
|
@ -104,11 +132,29 @@ router.beforeEach(async (to, from, next) => { |
|
|
// })
|
|
|
// })
|
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
|
|
|
console.log('不自动登录',isAutoLogin,to.query.loginName) |
|
|
if (to.path != '/login') { |
|
|
if (to.path != '/login') { |
|
|
Message.error('获取用户信息失败,请重新登录') |
|
|
Message.error('获取用户信息失败,请重新登录') |
|
|
next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) |
|
|
next({ |
|
|
next(`/login`) |
|
|
path:'/login', |
|
|
|
|
|
query:{ |
|
|
|
|
|
isAutoLogin:to.query.isAutoLogin, |
|
|
|
|
|
loginName:to.query.loginName, |
|
|
|
|
|
isSinglePage:to.query.isSinglePage |
|
|
|
|
|
}, |
|
|
|
|
|
replace: true |
|
|
|
|
|
}) |
|
|
|
|
|
// next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`)
|
|
|
|
|
|
// next(`/login`)
|
|
|
}else{ |
|
|
}else{ |
|
|
|
|
|
// next({
|
|
|
|
|
|
// ...to,
|
|
|
|
|
|
// query:{
|
|
|
|
|
|
// isAutoLogin:to.query.isAutoLogin,
|
|
|
|
|
|
// loginName:to.query.loginName,
|
|
|
|
|
|
// },
|
|
|
|
|
|
// replace: true
|
|
|
|
|
|
// })
|
|
|
next() |
|
|
next() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |