riku
2025-07-16 c23ac06446a9a1edc41cc13723e5d0b8eabdfd63
src/api/index.js
@@ -1,16 +1,22 @@
import axios from 'axios';
import { ElMessage } from 'element-plus';
const openLog = false;
const debug = true;
let ip1 = 'http://47.100.191.150:9029/';
let ws = `47.100.191.150:9030`;
// console.log(import.meta.env);
if (import.meta.env.VITE_DATA_MODE == 'jingan') {
  ip1 = 'http://114.215.109.124:8805/';
  ws = `114.215.109.124:9030`;
}
if (debug) {
  ip1 = 'http://192.168.0.110:8084/';
  ip1 = 'http://192.168.0.103:8084/';
  // ip1 = 'http://localhost:8084/';
  ws = `192.168.0.103:9031`;
  // ws = `localhost:9031`;
}
const $http = axios.create({
@@ -24,7 +30,7 @@
  i.interceptors.request.use(
    function (config) {
      // 在发送请求之前做些什么
      if (import.meta.env.DEV) {
      if (import.meta.env.DEV && openLog) {
        console.log('==>请求开始');
        console.log(`${config.baseURL}${config.url}`);
        if (config.data) {
@@ -35,7 +41,7 @@
    },
    function (error) {
      // 对请求错误做些什么
      if (import.meta.env.DEV) {
      if (import.meta.env.DEV && openLog) {
        console.log('==>请求开始');
        console.log(error);
      }
@@ -52,7 +58,7 @@
    function (response) {
      // 2xx 范围内的状态码都会触发该函数。
      // 对响应数据做点什么
      if (import.meta.env.DEV) {
      if (import.meta.env.DEV && openLog) {
        console.log(response);
        console.log('==>请求结束');
      }
@@ -80,7 +86,7 @@
    function (error) {
      // 超出 2xx 范围的状态码都会触发该函数。
      // 对响应错误做点什么
      if (import.meta.env.DEV) {
      if (import.meta.env.DEV && openLog) {
        console.log(error);
        console.log('==>请求结束');
      }
@@ -93,40 +99,9 @@
  );
});
// 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 };
export { $http, resToData, ws };