src/api/index.js
@@ -3,8 +3,11 @@
const debug = false;
// let ip1 = 'http://114.215.109.124:8805/';
let ip1 = 'http://47.100.191.150:9029/';
// console.log(import.meta.env);
if (import.meta.env.VITE_DATA_MODE == 'jingan') {
  ip1 = 'http://114.215.109.124:8805/';
}
if (debug) {
  ip1 = 'http://192.168.0.138:8084/';
@@ -21,17 +24,21 @@
  i.interceptors.request.use(
    function (config) {
      // 在发送请求之前做些什么
      console.log('==>请求开始');
      console.log(`${config.baseURL}${config.url}`);
      if (config.data) {
        console.log('==>请求数据', config.data);
      if (import.meta.env.DEV) {
        console.log('==>请求开始');
        console.log(`${config.baseURL}${config.url}`);
        if (config.data) {
          console.log('==>请求数据', config.data);
        }
      }
      return config;
    },
    function (error) {
      // 对请求错误做些什么
      console.log('==>请求开始');
      console.log(error);
      if (import.meta.env.DEV) {
        console.log('==>请求开始');
        console.log(error);
      }
      ElMessage({
        message: error,
        type: 'error'
@@ -45,8 +52,10 @@
    function (response) {
      // 2xx 范围内的状态码都会触发该函数。
      // 对响应数据做点什么
      console.log(response);
      console.log('==>请求结束');
      if (import.meta.env.DEV) {
        console.log(response);
        console.log('==>请求结束');
      }
      if (response.status == 200) {
        if (
          response.data.success != undefined &&
@@ -71,8 +80,10 @@
    function (error) {
      // 超出 2xx 范围的状态码都会触发该函数。
      // 对响应错误做点什么
      console.log(error);
      console.log('==>请求结束');
      if (import.meta.env.DEV) {
        console.log(error);
        console.log('==>请求结束');
      }
      ElMessage({
        message: error,
        type: 'error'
@@ -82,4 +93,40 @@
  );
});
export { $http };
// const $http = {
//   get(url) {
//     const controller = new AbortController();
//     return {
//       con: controller,
//       resp: axiosInstance.get(url, { signal: controller.signal })
//     };
//   },
//   put(url, data) {
//     const controller = new AbortController();
//     return {
//       con: controller,
//       resp: axiosInstance.put(url, data, { signal: controller.signal })
//     };
//   },
//   post(url, data) {
//     const controller = new AbortController();
//     return {
//       con: controller,
//       resp: axiosInstance.post(url, data, { signal: controller.signal })
//     };
//   },
//   delete(url) {
//     const controller = new AbortController();
//     return {
//       con: controller,
//       resp: axiosInstance.delete(url, { signal: controller.signal })
//     };
//   }
// };
function resToData(res) {
  res.resp = res.resp.then((res) => res.data);
  return res;
}
export { $http, resToData };