[测试]-测试单点登录
This commit is contained in:
+3
-3
@@ -63,9 +63,9 @@ export function logout(logoutToken) {
|
||||
* @param thirdType
|
||||
* @returns {*}
|
||||
*/
|
||||
export function thirdLogin(token,thirdType) {
|
||||
export function thirdLogin(token) {
|
||||
return axios({
|
||||
url: `/sys/thirdLogin/getLoginUser/${token}/${thirdType}`,
|
||||
url: `/sys/thirdLogin/getLoginUser/${token}`,
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
@@ -86,4 +86,4 @@ export function getRSAPublicKey() {
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+24
-8
@@ -11,9 +11,24 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
|
||||
const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration'] // no redirect whitelist
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start() // start progress bar
|
||||
const ThirdLoginFunc = (token) => {
|
||||
return new Promise(resolve => {
|
||||
store.dispatch('ThirdLogin', {token: token, thirdType: 1}).then(res => {
|
||||
console.log(res)
|
||||
}).finally(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start() // start progress bar
|
||||
if (to.query.token) {
|
||||
Vue.ls.set(ACCESS_TOKEN, to.query.token, 7 * 24 * 60 * 60 * 1000)
|
||||
// store.commit('SET_TOKEN', to.query.token)
|
||||
// 进行三方登录的功能
|
||||
await ThirdLoginFunc(to.query.token)
|
||||
}
|
||||
if (Vue.ls.get(ACCESS_TOKEN)) {
|
||||
/* has token */
|
||||
if (to.path === '/user/login') {
|
||||
@@ -36,21 +51,22 @@ router.beforeEach((to, from, next) => {
|
||||
const redirect = decodeURIComponent(from.query.redirect || to.path)
|
||||
if (to.path === redirect) {
|
||||
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
||||
next({ ...to, replace: true })
|
||||
// next({ ...to, replace: true })
|
||||
} else {
|
||||
// 跳转到目的路由
|
||||
next({ path: redirect })
|
||||
// next({ path: redirect })
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((e) => {
|
||||
console.log(e, '%%%%%%%%%%')
|
||||
/* notification.error({
|
||||
message: '系统提示',
|
||||
description: '请求用户信息失败,请重试!'
|
||||
})*/
|
||||
store.dispatch('Logout').then(() => {
|
||||
next({ path: '/user/login', query: { redirect: to.fullPath } })
|
||||
})
|
||||
// store.dispatch('Logout').then(() => {
|
||||
// next({ path: '/user/login', query: { redirect: to.fullPath } })
|
||||
// })
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user