2024-05-30 18:30:23 +08:00
|
|
|
const baseurl = "http://192.168.110.39:8080"; // 本地
|
|
|
|
// const baseurl = "http://lottery.unipay.test.86698.cn/api"; // 测试
|
2024-05-29 10:42:31 +08:00
|
|
|
// const baseurl = ""; // 正式
|
2024-05-31 10:45:11 +08:00
|
|
|
// 统一请求
|
|
|
|
// 返送之前
|
2024-05-29 10:42:31 +08:00
|
|
|
axios.interceptors.request.use((config) => {
|
2024-05-31 10:45:11 +08:00
|
|
|
config.headers = {
|
|
|
|
token: localStorage.getItem("yl_token")
|
|
|
|
? localStorage.getItem("yl_token")
|
|
|
|
: ""
|
|
|
|
};
|
2024-05-29 10:42:31 +08:00
|
|
|
return config;
|
|
|
|
});
|
|
|
|
|
2024-05-31 10:45:11 +08:00
|
|
|
// 发送之后
|
|
|
|
axios.interceptors.response.use(
|
|
|
|
(response) => {
|
|
|
|
// to do
|
|
|
|
return response.data;
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
// to do
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-05-29 10:42:31 +08:00
|
|
|
const req = {
|
|
|
|
//get请求
|
|
|
|
axiosGet(url, params) {
|
2024-05-31 10:45:11 +08:00
|
|
|
var result = axios({
|
|
|
|
method: "get",
|
2024-05-29 10:42:31 +08:00
|
|
|
url: baseurl + url,
|
2024-05-31 10:45:11 +08:00
|
|
|
params
|
2024-05-29 10:42:31 +08:00
|
|
|
})
|
|
|
|
.then((res) => {
|
2024-05-31 10:45:11 +08:00
|
|
|
return res;
|
2024-05-29 10:42:31 +08:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-05-31 10:45:11 +08:00
|
|
|
return new Error(error);
|
2024-05-29 10:42:31 +08:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
2024-05-31 10:45:11 +08:00
|
|
|
//post请求
|
|
|
|
axiosPost(url, data) {
|
2024-05-29 10:42:31 +08:00
|
|
|
let result = axios({
|
2024-05-31 10:45:11 +08:00
|
|
|
method: "post",
|
2024-05-29 10:42:31 +08:00
|
|
|
url: baseurl + url,
|
2024-05-31 10:45:11 +08:00
|
|
|
data: data
|
2024-05-29 10:42:31 +08:00
|
|
|
})
|
|
|
|
.then((res) => {
|
2024-05-31 10:45:11 +08:00
|
|
|
return res;
|
2024-05-29 10:42:31 +08:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-05-31 10:45:11 +08:00
|
|
|
return new Error(error);
|
2024-05-29 10:42:31 +08:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|