|
|
@ -7,7 +7,7 @@ const service = axios.create({ |
|
|
|
baseURL: import.meta.env.VITE_BASE_API, |
|
|
|
baseURL: import.meta.env.VITE_BASE_API, |
|
|
|
timeout: 10000, |
|
|
|
timeout: 10000, |
|
|
|
}); |
|
|
|
}); |
|
|
|
let loaded = 0; |
|
|
|
let logouted = 0; |
|
|
|
service.interceptors.request.use( |
|
|
|
service.interceptors.request.use( |
|
|
|
(config) => { |
|
|
|
(config) => { |
|
|
|
config.headers = { ...config.headers, ...getAuthHeaders() }; |
|
|
|
config.headers = { ...config.headers, ...getAuthHeaders() }; |
|
|
@ -18,13 +18,27 @@ service.interceptors.request.use( |
|
|
|
|
|
|
|
|
|
|
|
service.interceptors.response.use( |
|
|
|
service.interceptors.response.use( |
|
|
|
(res) => { |
|
|
|
(res) => { |
|
|
|
const { message, status } = res.data; |
|
|
|
const { message, status, code, msg } = res.data; |
|
|
|
if (status) { |
|
|
|
if (status) { |
|
|
|
if (status === 200) { |
|
|
|
if (status === 200) { |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ElMessage.error(message); |
|
|
|
ElMessage.error(message); |
|
|
|
|
|
|
|
} else if (code === 401) { |
|
|
|
|
|
|
|
// 账号互踢
|
|
|
|
|
|
|
|
if (!logouted) { |
|
|
|
|
|
|
|
ElMessageBox.alert(msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!', { |
|
|
|
|
|
|
|
confirmButtonText: '重新登录', |
|
|
|
|
|
|
|
type: 'warning', |
|
|
|
|
|
|
|
closeOnClickModal: false, |
|
|
|
|
|
|
|
showClose: false, |
|
|
|
|
|
|
|
}).then(() => { |
|
|
|
|
|
|
|
// 未登录
|
|
|
|
|
|
|
|
logout(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
logouted = 1; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
@ -37,12 +51,12 @@ service.interceptors.response.use( |
|
|
|
}, |
|
|
|
}, |
|
|
|
} = e; |
|
|
|
} = e; |
|
|
|
if (status === 401) { |
|
|
|
if (status === 401) { |
|
|
|
loaded || |
|
|
|
logouted || |
|
|
|
ElMessageBox.alert('登录状态已过期,请重新登录', { confirmButtonText: '重新登录', type: 'warning', closeOnClickModal: false, showClose: false }).then(() => { |
|
|
|
ElMessageBox.alert('登录状态已过期,请重新登录', { confirmButtonText: '重新登录', type: 'warning', closeOnClickModal: false, showClose: false }).then(() => { |
|
|
|
// 未登录
|
|
|
|
// 未登录
|
|
|
|
logout(); |
|
|
|
logout(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
loaded = 1; |
|
|
|
logouted = 1; |
|
|
|
} else if (message) { |
|
|
|
} else if (message) { |
|
|
|
ElMessage.error(message); |
|
|
|
ElMessage.error(message); |
|
|
|
} |
|
|
|
} |
|
|
|