|
@@ -11,6 +11,28 @@ NProgress.configure({ showSpinner: false })
|
|
|
|
|
|
// const whiteList = ['/login', '/demo', '/auth-redirect', '/bind', '/register']
|
|
|
|
|
|
+const infoHandle = (to:any, next:any) => {
|
|
|
+ isRelogin.show = true
|
|
|
+ // 判断当前用户是否已拉取完user_info信息
|
|
|
+ store.dispatch('GetInfo').then(() => {
|
|
|
+ isRelogin.show = false
|
|
|
+ store.dispatch('GenerateRoutes').then(accessRoutes => {
|
|
|
+ // 根据roles权限生成可访问的路由表
|
|
|
+ for(const item of accessRoutes){
|
|
|
+ router.addRoute(item)
|
|
|
+ }
|
|
|
+ // router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
|
|
+ console.log(to)
|
|
|
+ next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ store.dispatch('LogOut').then(() => {
|
|
|
+ Message.error(err)
|
|
|
+ // next({ path: '/' })
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
router.beforeEach((to:any, from:any, next:any) => {
|
|
|
NProgress.start()
|
|
|
if (getToken()) {
|
|
@@ -21,24 +43,7 @@ router.beforeEach((to:any, from:any, next:any) => {
|
|
|
// NProgress.done()
|
|
|
// } else {
|
|
|
if (store.getters.roles.length === 0) {
|
|
|
- isRelogin.show = true
|
|
|
- // 判断当前用户是否已拉取完user_info信息
|
|
|
- store.dispatch('GetInfo').then(() => {
|
|
|
- isRelogin.show = false
|
|
|
- store.dispatch('GenerateRoutes').then(accessRoutes => {
|
|
|
- // 根据roles权限生成可访问的路由表
|
|
|
- for(const item of accessRoutes){
|
|
|
- router.addRoute(item)
|
|
|
- }
|
|
|
- // router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
|
|
- next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
- })
|
|
|
- }).catch(err => {
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
- Message.error(err)
|
|
|
- // next({ path: '/' })
|
|
|
- })
|
|
|
- })
|
|
|
+ infoHandle(to,next)
|
|
|
} else {
|
|
|
next()
|
|
|
}
|
|
@@ -48,7 +53,8 @@ router.beforeEach((to:any, from:any, next:any) => {
|
|
|
const ssoToken = getQueryString('ssoToken')
|
|
|
|
|
|
if(!ticket && !ssoToken){
|
|
|
- const redirect = location.href.replace(/\??ticket=[^&]*&?/g, '')
|
|
|
+ const redirect = location.origin
|
|
|
+ // const redirect = location.href.replace(/\??ticket=[^&]*&?/g, '')
|
|
|
location.href = `${process.env.VUE_APP_LOGIN_URL}?&redirect=${encodeURIComponent(redirect)}`
|
|
|
}else{
|
|
|
const url = ticket ? '/sso/doLoginByTicket' : '/sso/doLoginByToken'
|
|
@@ -62,29 +68,15 @@ router.beforeEach((to:any, from:any, next:any) => {
|
|
|
store.dispatch('GetToken',{
|
|
|
url,data
|
|
|
}).then(() => {
|
|
|
- isRelogin.show = true
|
|
|
- // 判断当前用户是否已拉取完user_info信息
|
|
|
- store.dispatch('GetInfo').then(() => {
|
|
|
- isRelogin.show = false
|
|
|
- store.dispatch('GenerateRoutes').then(accessRoutes => {
|
|
|
- // 根据roles权限生成可访问的路由表
|
|
|
- for(const item of accessRoutes){
|
|
|
- router.addRoute(item)
|
|
|
- }
|
|
|
- // router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
|
|
- next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
- })
|
|
|
- }).catch(err => {
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
- Message.error(err)
|
|
|
- // next({ path: '/' })
|
|
|
- })
|
|
|
- })
|
|
|
+ infoHandle(to,next)
|
|
|
// location.href = '/index';
|
|
|
}).catch((err:any) => {
|
|
|
if(err && err.msg) {
|
|
|
Message.error(err.msg);
|
|
|
}
|
|
|
+ // const redirect = location.href.replace(/\??ticket=[^&]*&?/g, '')
|
|
|
+ const redirect = location.origin
|
|
|
+ location.href = `${process.env.VUE_APP_LOGIN_URL}?&redirect=${encodeURIComponent(redirect)}`
|
|
|
})
|
|
|
// next()
|
|
|
}
|
|
@@ -105,3 +97,4 @@ router.beforeEach((to:any, from:any, next:any) => {
|
|
|
router.afterEach(() => {
|
|
|
NProgress.done()
|
|
|
})
|
|
|
+
|