|
@ -1,6 +1,5 @@ |
|
|
// src/utils/request.js
|
|
|
// src/utils/request.js
|
|
|
import axios from "axios"; |
|
|
import axios from "axios"; |
|
|
|
|
|
|
|
|
const baseURL = process.env.VUE_APP_BASE_API; |
|
|
const baseURL = process.env.VUE_APP_BASE_API; |
|
|
// 创建 axios 实例
|
|
|
// 创建 axios 实例
|
|
|
const service = axios.create({ |
|
|
const service = axios.create({ |
|
@ -8,7 +7,7 @@ const service = axios.create({ |
|
|
timeout: 60000, // 请求超时时间
|
|
|
timeout: 60000, // 请求超时时间
|
|
|
headers: { |
|
|
headers: { |
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
'AUTHADMIN' :'b10346e6-5003-4644-8e48-e14f49874338' |
|
|
'AUTHADMIN' :localStorage.getItem("authtoken") |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -75,20 +74,43 @@ const request = (method, url, data = {}, config = {}) => { |
|
|
const lowerCaseMethod = method.toLowerCase(); |
|
|
const lowerCaseMethod = method.toLowerCase(); |
|
|
if (lowerCaseMethod === "get") { |
|
|
if (lowerCaseMethod === "get") { |
|
|
// GET 请求将参数拼接到 URL 上
|
|
|
// GET 请求将参数拼接到 URL 上
|
|
|
return service({ |
|
|
var res = service({ |
|
|
method: "get", |
|
|
method: "get", |
|
|
url, |
|
|
url, |
|
|
params: data, |
|
|
params: data, |
|
|
...config, |
|
|
...config, |
|
|
}); |
|
|
}); |
|
|
|
|
|
res.then(response => { |
|
|
|
|
|
if(response.msg.indexOf('非法操作') > -1) { |
|
|
|
|
|
localStorage.removeItem('authtoken') |
|
|
|
|
|
location.href = '/ErrorAccess' |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
console.error('API Error:', error); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
} else { |
|
|
} else { |
|
|
// 其他请求(POST, PUT, DELETE 等)将参数放在请求体中
|
|
|
// 其他请求(POST, PUT, DELETE 等)将参数放在请求体中
|
|
|
return service({ |
|
|
var respost = service({ |
|
|
method: lowerCaseMethod, |
|
|
method: lowerCaseMethod, |
|
|
url, |
|
|
url, |
|
|
data, |
|
|
data, |
|
|
...config, |
|
|
...config, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
respost.then(response => { |
|
|
|
|
|
if(response.msg.indexOf('非法操作') > -1) { |
|
|
|
|
|
localStorage.removeItem('authtoken') |
|
|
|
|
|
location.href = '/ErrorAccess' |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
console.error('API Error:', error); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return respost; |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|