|
@@ -17,9 +17,9 @@ export let isRelogin = { show: false };
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
// 创建axios实例
|
|
|
const service = axios.create({
|
|
|
- // axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
|
- baseURL: process.env.VUE_APP_BASE_URL,
|
|
|
- // 超时
|
|
|
+ // axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
|
+ baseURL: process.env.VUE_APP_BASE_URL,
|
|
|
+ // 超时
|
|
|
timeout: 3000,
|
|
|
headers: {
|
|
|
// 设置后端需要的传参类型
|
|
@@ -40,7 +40,8 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(
|
|
|
- res => {
|
|
|
+ res => {
|
|
|
+ debugger
|
|
|
// 未设置状态码则默认成功状态
|
|
|
const code = res.data.code || 200;
|
|
|
// 获取错误信息
|
|
@@ -49,21 +50,29 @@ service.interceptors.response.use(
|
|
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
return res.data
|
|
|
}
|
|
|
- if (code === 401) {
|
|
|
- if (!isRelogin.show) {
|
|
|
- isRelogin.show = true;
|
|
|
+ if (code === 401) {
|
|
|
+ debugger
|
|
|
ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录','系统提示', {
|
|
|
- confirmButtonText: '重新登录',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
+ confirmButtonText: '重新登录',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
}).then(() => {
|
|
|
- isRelogin.show = false;
|
|
|
- this.$route.push({path: '/login'})
|
|
|
- }).catch(() => {
|
|
|
- isRelogin.show = false
|
|
|
+ this.$route.replace({path: '/login'})
|
|
|
})
|
|
|
- }
|
|
|
- return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
+ // if (!isRelogin.show) {
|
|
|
+ // isRelogin.show = true;
|
|
|
+ // ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录','系统提示', {
|
|
|
+ // confirmButtonText: '重新登录',
|
|
|
+ // cancelButtonText: '取消',
|
|
|
+ // type: 'warning'
|
|
|
+ // }).then(() => {
|
|
|
+ // isRelogin.show = false;
|
|
|
+ // this.$route.push({path: '/login'})
|
|
|
+ // }).catch(() => {
|
|
|
+ // isRelogin.show = false
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
} else if (code === 500) {
|
|
|
ElMessage({ message: msg, type: 'error' })
|
|
|
return Promise.reject(new Error(msg))
|