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,63 @@
import axios from 'axios';
import config from '@/config';
import { Toast } from 'vant';
export default class Api {
constructor(isBase = null ) {
this.instance = axios.create({
baseURL: isBase == null ? config.checkEnvironment() : "",
timeout: 10000
});
this.interceptors()
}
async get(params) {
return await this.instance.get(params.url, {
params: params.data
})
}
async post(params) {
return await this.instance.post(params.url, params.data, {
headers: Object.assign({
"Content-Type": "application/json",
}, params.headers)
})
}
interceptors() {
this.instance.interceptors.request.use(function (config) {
Toast.loading({
duration: 0,
forbidClick: true,
message: '加载中....',
});
return config;
}, function (error) {
return Promise.reject(error);
});
this.instance.interceptors.response.use(function (response) {
Toast.clear();
switch (response.data.status) {
case 200:
return response.data.result
break;
case 404:
Toast.fail({
message: response.data.message
});
throw new Error(response.data.message)
break;
default:
break;
}
}, function (error) {
return Promise.reject(error);
});
}
}