Browse Source

feat(config): 添加全局请求超时配置并优化代码格式

- 在 globalConfig 中添加 axiosRequestDef函数,设置请求超时时间为10 分钟
- 优化代码格式,调整缩进和空格
master
lizw-2015 5 months ago
parent
commit
85d5bb7226
  1. 21
      src/config.ts

21
src/config.ts

@ -6,6 +6,9 @@ import { createVNode } from "vue";
import ErrorDialog from "@/components/ErrorDialog.vue"; import ErrorDialog from "@/components/ErrorDialog.vue";
function globalConfig() { function globalConfig() {
window.globalConfig.axiosRequestDef = () => ({
timeout: 1000 * 60 * 10,
})
window.globalConfig.customAxios = axiosInstance => { window.globalConfig.customAxios = axiosInstance => {
// 全局请求拦截 // 全局请求拦截
axiosInstance.interceptors.request.clear(); axiosInstance.interceptors.request.clear();
@ -25,18 +28,18 @@ function globalConfig() {
axiosInstance.interceptors.response.clear(); axiosInstance.interceptors.response.clear();
axiosInstance.interceptors.response.use( axiosInstance.interceptors.response.use(
(response) => { (response) => {
const data = response.data; const data = response.data;
if (data && data.success === false) { if (data && data.success === false) {
// 显示错误对话框 // 显示错误对话框
system.showErrorDialog(data.failMessage || '系统异常'); system.showErrorDialog(data.failMessage || '系统异常');
// 返回一个被拒绝的 Promise,这样后续 .then() 不会执行,进入 .catch() // 返回一个被拒绝的 Promise,这样后续 .then() 不会执行,进入 .catch()
return Promise.reject(response); return Promise.reject(response);
} }
// 正常情况,继续传递数据 // 正常情况,继续传递数据
return response; return response;
}, },
(error: any) => { (error: any) => {
const { response } = error; const { response } = error;

Loading…
Cancel
Save