| | |
| | | import axios from 'axios'; |
| | | import { ElMessage } from 'element-plus'; |
| | | |
| | | const debug = false; |
| | | const openLog = true; |
| | | const debug = true; |
| | | |
| | | let ip1 = 'http://47.100.191.150:9029/'; |
| | | let ws = `47.100.191.150:9031`; |
| | | // 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:9031`; |
| | | } |
| | | |
| | | 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({ |
| | |
| | | i.interceptors.request.use( |
| | | function (config) { |
| | | // 在发送请求之前做些什么 |
| | | if (import.meta.env.DEV) { |
| | | console.log('==>请求开始'); |
| | | console.log(`${config.baseURL}${config.url}`); |
| | | if (config.data) { |
| | | console.log('==>请求数据', config.data); |
| | | } |
| | | } |
| | | // if (import.meta.env.DEV && openLog) { |
| | | // console.log('==>请求开始'); |
| | | // console.log(`${config.baseURL}${config.url}`); |
| | | // if (config.data) { |
| | | // console.log('==>请求数据', config.data); |
| | | // } |
| | | // } |
| | | return config; |
| | | }, |
| | | function (error) { |
| | | // 对请求错误做些什么 |
| | | if (import.meta.env.DEV) { |
| | | if (import.meta.env.DEV && openLog) { |
| | | console.log('==>请求开始'); |
| | | console.log(error); |
| | | } |
| | |
| | | function (response) { |
| | | // 2xx 范围内的状态码都会触发该函数。 |
| | | // 对响应数据做点什么 |
| | | if (import.meta.env.DEV) { |
| | | console.log(response); |
| | | console.log('==>请求结束'); |
| | | if (import.meta.env.DEV && openLog) { |
| | | console.log('|------------------------------------------'); |
| | | console.log('|--请求: ', `${response.request.responseURL}`); |
| | | if (response.config.data) { |
| | | console.log('|--数据: ', response.config.data); |
| | | } |
| | | console.log('|--结果: ', response.data); |
| | | } |
| | | if (response.status == 200) { |
| | | if ( |
| | |
| | | function (error) { |
| | | // 超出 2xx 范围的状态码都会触发该函数。 |
| | | // 对响应错误做点什么 |
| | | if (import.meta.env.DEV) { |
| | | if (import.meta.env.DEV && openLog) { |
| | | console.log(error); |
| | | console.log('==>请求结束'); |
| | | } |
| | |
| | | ); |
| | | }); |
| | | |
| | | // 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 }; |