feat: There is no way the idm and oa
This commit is contained in:
+46
-25
@@ -7,7 +7,11 @@ import axios from 'axios'
|
||||
import router from '@/router'
|
||||
import store from '@/store'
|
||||
import {Message} from 'element-ui'
|
||||
import { baseUrl } from '@/sysConfig'
|
||||
import { baseUrl,webLoginType,ssoLoginUrlDev } from '@/sysConfig'
|
||||
import domMessage from '../messageOnce/messageOnce'
|
||||
|
||||
const messageOnce = new domMessage()
|
||||
|
||||
export const CancelToken = axios.CancelToken
|
||||
// import 'element-ui/lib/theme-chalk/index.css'
|
||||
const _axios = axios.create({
|
||||
@@ -34,37 +38,54 @@ window._axiosPromiseArr = []
|
||||
* liuyan
|
||||
*/
|
||||
_axios.interceptors.request.use(
|
||||
config => {
|
||||
// 记录接口请求
|
||||
// config.cancelToken = new axios.CancelToken(cancel => {
|
||||
// // window._axiosPromiseArr.push({ cancel })
|
||||
// })
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error.response)
|
||||
})
|
||||
config => {
|
||||
// 记录接口请求
|
||||
let token = store.state.token;
|
||||
if (!config.headers.hasOwnProperty('token') && token != null && token) {
|
||||
config.headers.token = token;
|
||||
}
|
||||
// config.cancelToken = new axios.CancelToken(cancel => {
|
||||
// // window._axiosPromiseArr.push({ cancel })
|
||||
// })
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error.response)
|
||||
})
|
||||
/**
|
||||
* @description: axios响应拦截器
|
||||
* liuyan
|
||||
*/
|
||||
_axios.interceptors.response.use(
|
||||
res => {
|
||||
return res
|
||||
},
|
||||
error => {
|
||||
// 登录超时
|
||||
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
|
||||
for (let key in store.state) {
|
||||
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
|
||||
store.state[key] = ''
|
||||
res => {
|
||||
if(res.data && res.data.respCode && res.data.respCode === 'LE505'){
|
||||
window.sessionStorage.clear()
|
||||
messageOnce.warning({
|
||||
message: '登录超时,请重新登录',
|
||||
type: 'warning'
|
||||
})
|
||||
if(webLoginType != null && webLoginType === 'idm' ) {
|
||||
// idm 统一认证登录页面
|
||||
return window.location.href = ssoLoginUrlDev
|
||||
}else if(webLoginType != null && webLoginType === 'dev'){
|
||||
return router.push('/login')
|
||||
}
|
||||
}
|
||||
Message.warning('登录超时,请重新登录')
|
||||
router.push('/login')
|
||||
store.state.isTimeOut = true
|
||||
}
|
||||
})
|
||||
return res
|
||||
},
|
||||
error => {
|
||||
// 登录超时
|
||||
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
|
||||
for (let key in store.state) {
|
||||
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
|
||||
store.state[key] = ''
|
||||
}
|
||||
}
|
||||
Message.warning('登录超时,请重新登录')
|
||||
router.push('/login')
|
||||
store.state.isTimeOut = true
|
||||
}
|
||||
})
|
||||
function api () {
|
||||
return store.getters.getTypeFlag === 'CloudRepository' ? '/busApi/' : '/api/'
|
||||
}
|
||||
|
||||
+46
-25
@@ -2,9 +2,13 @@ import axios from 'axios'
|
||||
import router from '@/router'
|
||||
import store from '@/store'
|
||||
import {Message} from 'element-ui'
|
||||
import { baseUrl } from '@/sysConfig'
|
||||
import { baseUrl,webLoginType,ssoLoginUrlDev } from '@/sysConfig'
|
||||
import domMessage from '../messageOnce/messageOnce'
|
||||
|
||||
// import 'element-ui/lib/theme-chalk/index.css'
|
||||
|
||||
const messageOnce = new domMessage()
|
||||
|
||||
/**
|
||||
* @description: FormData
|
||||
* @author: xx
|
||||
@@ -29,35 +33,52 @@ service.defaults.headers['Content-type'] = 'application/json'
|
||||
* liuyan
|
||||
*/
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
if (config.params) {
|
||||
// 解决IE请求不刷新
|
||||
config.params._t = new Date().getTime()
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error.response)
|
||||
})
|
||||
config => {
|
||||
if (config.params) {
|
||||
// 解决IE请求不刷新
|
||||
config.params._t = new Date().getTime()
|
||||
}
|
||||
let token = store.state.token;
|
||||
if (!config.headers.hasOwnProperty('token') && token != null && token) {
|
||||
config.headers.token = token;
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error.response)
|
||||
})
|
||||
/**
|
||||
* @description: axios响应拦截器
|
||||
* liuyan
|
||||
*/
|
||||
service.interceptors.response.use(
|
||||
res => {
|
||||
return res.data
|
||||
},
|
||||
error => {
|
||||
// 登录超时
|
||||
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
|
||||
for (let key in store.state) {
|
||||
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
|
||||
store.state[key] = ''
|
||||
res => {
|
||||
if(res.data && res.data.respCode != undefined && res.data.respCode === 'LE505'){
|
||||
window.sessionStorage.clear()
|
||||
messageOnce.warning({
|
||||
message: '登录超时,请重新登录',
|
||||
type: 'warning'
|
||||
})
|
||||
if(webLoginType != null && webLoginType === 'idm' ) {
|
||||
// idm 统一认证登录页面
|
||||
return window.location.href = ssoLoginUrlDev
|
||||
}else if(webLoginType != null && webLoginType === 'dev'){
|
||||
return router.push('/login')
|
||||
}
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
error => {
|
||||
// 登录超时
|
||||
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
|
||||
for (let key in store.state) {
|
||||
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
|
||||
store.state[key] = ''
|
||||
}
|
||||
}
|
||||
Message.warning('登录超时,请重新登录')
|
||||
router.push('/login')
|
||||
store.state.isTimeOut = true
|
||||
}
|
||||
Message.warning('登录超时,请重新登录')
|
||||
router.push('/login')
|
||||
store.state.isTimeOut = true
|
||||
}
|
||||
})
|
||||
})
|
||||
export default service
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import {Message} from 'element-ui'
|
||||
// 私有属性,只在当前文件可用
|
||||
const showMessage = Symbol('showMessage')
|
||||
export default class domMessage {
|
||||
success (options, single = true) {
|
||||
this[showMessage]('success', options, single)
|
||||
}
|
||||
warning(options, single = true) {
|
||||
this[showMessage]('warning', options, single)
|
||||
}
|
||||
info(options, single = true) {
|
||||
this[showMessage]('info', options, single)
|
||||
}
|
||||
error(options, single = true) {
|
||||
this[showMessage]('error', options, single)
|
||||
}
|
||||
[showMessage] (type, options, single) {
|
||||
if (single) {
|
||||
// 关键代码,判断当前页是否有el-message标签,如果没有则执行弹窗操作
|
||||
if (document.getElementsByClassName('el-message').length === 0) {
|
||||
Message[type](options)
|
||||
}
|
||||
} else {
|
||||
Message[type](options)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user