Compare commits
2 Commits
c7f2e1f70a
...
c156b52d84
Author | SHA1 | Date |
---|---|---|
yuhan_jiang | c156b52d84 | |
yuhan_jiang | 15eb5dbd13 |
|
@ -23,11 +23,15 @@ export async function socialLogin(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserInfo() {
|
export function getUserInfo(redict) {
|
||||||
//此处为了兼容mock.js使用data传递accessToken,如果使用mock可以走headers
|
//此处为了兼容mock.js使用data传递accessToken,如果使用mock可以走headers
|
||||||
|
// debugger
|
||||||
return request({
|
return request({
|
||||||
url: '/sys/user/info',
|
url: '/sys/user/info',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
headers: {
|
||||||
|
REQUESTURI:redict
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
export function getDeptAll() {
|
export function getDeptAll() {
|
||||||
|
|
|
@ -23,24 +23,10 @@ let loadingInstance
|
||||||
* @param {*} msg
|
* @param {*} msg
|
||||||
*/
|
*/
|
||||||
const handleCode = (code, msg, res) => {
|
const handleCode = (code, msg, res) => {
|
||||||
debugger
|
// debugger
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 401:
|
case 401:
|
||||||
// message.error(msg || '登录失效')
|
|
||||||
|
|
||||||
store.dispatch('user/resetAll').catch(() => {})
|
store.dispatch('user/resetAll').catch(() => {})
|
||||||
debugger
|
|
||||||
// if (res.token) {
|
|
||||||
// console.log('存在token信息', res.token)
|
|
||||||
// setAccessToken(res.token)
|
|
||||||
// const token = getAccessToken()
|
|
||||||
// console.log('验证token信息', token)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // location.reload()
|
|
||||||
// if (redirect) {
|
|
||||||
// window.location.href = res.redirect
|
|
||||||
// }
|
|
||||||
break
|
break
|
||||||
case 403:
|
case 403:
|
||||||
router.push({ path: '/401' }).catch(() => {})
|
router.push({ path: '/401' }).catch(() => {})
|
||||||
|
@ -72,7 +58,7 @@ const instance = axios.create({
|
||||||
*/
|
*/
|
||||||
instance.interceptors.request.use(
|
instance.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
debugger
|
// debugger
|
||||||
const token = getAccessToken()
|
const token = getAccessToken()
|
||||||
if (token) config.headers[tokenName] = token
|
if (token) config.headers[tokenName] = token
|
||||||
if (
|
if (
|
||||||
|
@ -84,7 +70,10 @@ instance.interceptors.request.use(
|
||||||
if (debounce.some((item) => config.url.includes(item))) {
|
if (debounce.some((item) => config.url.includes(item))) {
|
||||||
//这里写加载动画
|
//这里写加载动画
|
||||||
}
|
}
|
||||||
|
if (!config.headers.REQUESTURI){
|
||||||
config.headers.REQUESTURI = window.location.href
|
config.headers.REQUESTURI = window.location.href
|
||||||
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
@ -103,17 +92,13 @@ instance.interceptors.response.use(
|
||||||
console.log('接口返回REDIRECT', response.headers.redirect)
|
console.log('接口返回REDIRECT', response.headers.redirect)
|
||||||
response['Access-Control-Expose-Headers'] = 'redirect'
|
response['Access-Control-Expose-Headers'] = 'redirect'
|
||||||
const { code, message } = response.data
|
const { code, message } = response.data
|
||||||
debugger
|
|
||||||
if (code == '0' && response.headers.token) {
|
if (response.headers.token) {
|
||||||
setAccessToken(response.headers.token)
|
setAccessToken(response.headers.token)
|
||||||
} else {
|
}
|
||||||
const token = getAccessToken()
|
if (response.headers.redirect) {
|
||||||
if (response.headers.redirect && !token) {
|
|
||||||
// window.location.href = response.headers.redirect
|
|
||||||
window.location.replace(response.headers.redirect)
|
window.location.replace(response.headers.redirect)
|
||||||
return
|
return
|
||||||
// location.reload()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (response.headers.redirect === '/#/login') {
|
if (response.headers.redirect === '/#/login') {
|
||||||
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
||||||
|
@ -158,7 +143,7 @@ instance.interceptors.response.use(
|
||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
debugger
|
// debugger
|
||||||
console.log('接口error', error)
|
console.log('接口error', error)
|
||||||
if (loadingInstance) loadingInstance.close()
|
if (loadingInstance) loadingInstance.close()
|
||||||
|
|
||||||
|
@ -167,12 +152,12 @@ instance.interceptors.response.use(
|
||||||
console.log('接口返回', response)
|
console.log('接口返回', response)
|
||||||
console.log('接口返回headers', response.headers)
|
console.log('接口返回headers', response.headers)
|
||||||
console.log('接口返回REDIRECT', response.headers.redirect)
|
console.log('接口返回REDIRECT', response.headers.redirect)
|
||||||
// if (response.headers.token) {
|
if (response.headers.token) {
|
||||||
// setAccessToken(response.headers.token)
|
setAccessToken(response.headers.token)
|
||||||
// }
|
}
|
||||||
if (response.headers.redirect) {
|
if (response.headers.redirect) {
|
||||||
window.location.replace(response.headers.redirect)
|
window.location.replace(response.headers.redirect)
|
||||||
// return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
const { status, data } = response
|
const { status, data } = response
|
||||||
|
|
||||||
|
|
|
@ -9,33 +9,34 @@
|
||||||
* @author chuzhixin 1204505056@qq.com
|
* @author chuzhixin 1204505056@qq.com
|
||||||
* @description 路由守卫,目前两种模式:all模式与intelligence模式
|
* @description 路由守卫,目前两种模式:all模式与intelligence模式
|
||||||
*/
|
*/
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import getPageTitle from '@/utils/pageTitle'
|
import getPageTitle from '@/utils/pageTitle'
|
||||||
import { getUserInfo } from '@/api/user'
|
import { getUserInfo } from '@/api/user'
|
||||||
import {
|
import {
|
||||||
// authentication,
|
// authentication,
|
||||||
loginInterception,
|
loginInterception,
|
||||||
// recordRoute,
|
// recordRoute,
|
||||||
routesWhiteList,
|
routesWhiteList,
|
||||||
} from '@/config'
|
} from '@/config'
|
||||||
import { setAccessToken, getAccessToken } from '@/utils/accessToken'
|
import { setAccessToken, getAccessToken } from '@/utils/accessToken'
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
// debugger
|
// debugger
|
||||||
// const SSOTOKEN = to.query.SSOToken
|
// const SSOTOKEN = to.query.SSOToken
|
||||||
// if (SSOTOKEN) {
|
// if (SSOTOKEN) {
|
||||||
// setAccessToken(SSOTOKEN)
|
// setAccessToken(SSOTOKEN)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const token = getAccessToken()
|
const token = getAccessToken()
|
||||||
console.log('token', token)
|
console.log('token', token)
|
||||||
let hasToken = token || store.getters['user/accessToken']
|
let hasToken = token
|
||||||
// debugger
|
// debugger
|
||||||
if (!loginInterception) hasToken = true
|
if (!loginInterception) hasToken = true
|
||||||
console.log('hasToken存在巨大问题', hasToken)
|
console.log('hasToken存在巨大问题', hasToken)
|
||||||
if (hasToken) {
|
if (hasToken) {
|
||||||
// setAccessToken(hasToken)
|
// setAccessToken(hasToken)
|
||||||
await store.dispatch('user/getUserInfo')
|
await store.dispatch('user/getUserInfo')
|
||||||
debugger
|
// debugger
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
let accessRoutes = []
|
let accessRoutes = []
|
||||||
|
@ -47,20 +48,14 @@ router.beforeEach(async (to, from, next) => {
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
// 这里是一个单点登录的入口
|
// 这里是一个单点登录的入口
|
||||||
getUserInfo().then((res) => {
|
if (to.query.redict)
|
||||||
console.log(res)
|
getUserInfo(to.query.redict)
|
||||||
router.replace('/home')
|
else {
|
||||||
|
getUserInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// await store.dispatch('user/getUserInfo')
|
router.afterEach((to) => {
|
||||||
// next()
|
|
||||||
// if (recordRoute)
|
|
||||||
// next({ path: '/login', query: { redirect: to.path }, replace: true })
|
|
||||||
// else next({ path: '/login', replace: true })
|
|
||||||
// next()
|
|
||||||
// window.open('http://www.baidu.com', '_self')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
router.afterEach((to) => {
|
|
||||||
document.title = getPageTitle(to.meta.title)
|
document.title = getPageTitle(to.meta.title)
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const goHome = () => {
|
const goHome = () => {
|
||||||
router.push('/home')
|
router.push({path: '/home', query:{redict: window.location.origin + '/#/home'}})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
|
Loading…
Reference in New Issue