|
@@ -0,0 +1,64 @@
|
|
|
+import axios from "axios";
|
|
|
+
|
|
|
+let config = {
|
|
|
+ baseURL: import.meta.env.VITE_APP_API_URL,
|
|
|
+ timeout: 10*60 * 1000, // Timeout
|
|
|
+};
|
|
|
+
|
|
|
+const _axios = axios.create(config);
|
|
|
+_axios.interceptors.request.use(
|
|
|
+ /* function (config) {
|
|
|
+
|
|
|
+ config.headers.Authorization=localStorage.getItem('token')||''
|
|
|
+ return config;
|
|
|
+ }, */
|
|
|
+ function (error) {
|
|
|
+ // Do something with request error
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+);
|
|
|
+_axios.interceptors.response.use(
|
|
|
+ function (response) {
|
|
|
+ // Do something with response data
|
|
|
+ let data
|
|
|
+ data=response.data
|
|
|
+
|
|
|
+ //错误提示
|
|
|
+ if(response.status!==200){
|
|
|
+ //网络异常
|
|
|
+ }
|
|
|
+ if(!data){
|
|
|
+ //服务器开了个小差
|
|
|
+ }
|
|
|
+ if(data.Ret===408){//token失效
|
|
|
+ }
|
|
|
+ if(data.Ret===403){
|
|
|
+ //data.Msg||'网络异常'
|
|
|
+ }
|
|
|
+
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+ function (error) {
|
|
|
+ console.log(error);
|
|
|
+ // Do something with response error
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+/**
|
|
|
+ * 导出get请求方法
|
|
|
+ * @url 请求地址
|
|
|
+ * @params get请求参数
|
|
|
+ */
|
|
|
+ export const get = (url, params) => {
|
|
|
+ return _axios.get(url, { params });
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出post请求方法
|
|
|
+ * @url 请求地址
|
|
|
+ * @params post请求参数
|
|
|
+ */
|
|
|
+ export const post = (url, params) => {
|
|
|
+ return _axios.post(url, params);
|
|
|
+ };
|