first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
import axios from 'axios'
import config from '@/config/index'
import { Loading, Notification } from 'element-ui';
let loadingInstance = null;
class Http {
constructor() {
this.instance = axios.create({
baseURL: config.checkBaseUrl(),
timeout: 3000,
headers: {
"Content-Type": "application/json;charset=UTF-8"
}
});
this.interceptors()
}
async get(params) {
return await this.instance.get(params.url, {
params: params.data,
headers: Object.assign({
token: localStorage.getItem("token")
},params.headers)
})
}
async post(params) {
return await this.instance.post(params.url, params.data, {
headers: Object.assign({
token: localStorage.getItem("token")
},params.headers)
})
}
interceptors() {
// 添加请求拦截器
this.instance.interceptors.request.use(function (config) {
// Toast.loading({
// message: '加载中...',
// duration: 0,
// });
loadingInstance = Loading.service({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
// 在发送请求之前做些什么
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
this.instance.interceptors.response.use(function (response) {
loadingInstance.close();
switch (response.data.status) {
case 200:
return response.data.result;
break;
case 500:
Notification.error({
title: `错误: ${response.data.status}`,
message: response.data.msg
})
throw new Error(response.data.msg)
break;
default:
break;
}
}, function (error) {
// 对响应错误做点什么
return Promise.reject(error);
});
}
}
export default Http;