更新秘地
This commit is contained in:
@@ -7,9 +7,12 @@ const BASE_URL = "https://md.xscmmidi.site";
|
||||
// 前端访问域名
|
||||
// tmdh.xscmmidi.site 测试
|
||||
// mdh.xscmmidi.site 正式
|
||||
const PRIMARY_BGURL = "http://mdh.xscmmidi.site/image/fy_bg.jpg";
|
||||
const PRIMARY_BGURL = "https://md.xscmmidi.site/h5/image/fy_bg.jpg";
|
||||
// 工会管理员
|
||||
const PRIMARY_BLYURL = "http://mdh.xscmmidi.site/image/fy_gly.png";
|
||||
const PRIMARY_BLYURL = "https://md.xscmmidi.site/h5/image/fy_gly.png";
|
||||
const wealth_url = "https://md.xscmmidi.site/h5/image/wealth.png";
|
||||
const charm_url = "https://md.xscmmidi.site/h5/image/charm.png";
|
||||
const kefu_url = "https://md.xscmmidi.site/h5/image/kefu.png";
|
||||
//IM app_key
|
||||
const IM_APP_TOKEN="67962a777e2b13bc6a4bde3ccd389d1e";
|
||||
const BASR_COLOR = '#6C49E4';
|
||||
@@ -19,5 +22,8 @@ export default {
|
||||
PRIMARY_BGURL,
|
||||
PRIMARY_BLYURL,
|
||||
BASR_COLOR,
|
||||
BASE_NAME
|
||||
BASE_NAME,
|
||||
wealth_url,
|
||||
charm_url,
|
||||
kefu_url
|
||||
}
|
||||
@@ -1,36 +1,53 @@
|
||||
// src/utils/http.js
|
||||
import axios from 'axios';
|
||||
import config from './config.js';
|
||||
// 创建axios实例
|
||||
const http = axios.create({
|
||||
baseURL: config.BASE_URL, // API的基础路径
|
||||
timeout: 5000
|
||||
const http = (options = {}) => {
|
||||
console.log(options)
|
||||
// 请求拦截器逻辑
|
||||
const requestConfig = {
|
||||
url: config.BASE_URL + options.url, // 拼接完整请求路径 :cite[1]:cite[2]:cite[7]
|
||||
method: options.method || 'GET',
|
||||
data: options.params || options.data || {},
|
||||
header: { // 注意:key 由 axios 的 `headers` 改为 uni.request 的 `header` :cite[1]
|
||||
'Content-Type': 'application/json', // 明确设置 Content-Type,因为 uni.request 默认可能使用 'application/x-www-form-urlencoded' :cite[1]
|
||||
...options.header, // 合并自定义请求头
|
||||
},
|
||||
timeout: options.timeout || 5000,
|
||||
sslVerify: false
|
||||
};
|
||||
|
||||
// 在发送请求前可以执行的操作,例如添加 token :cite[1]:cite[7]:cite[8]
|
||||
// 示例:添加 Token
|
||||
const token = uni.getStorageSync('token');
|
||||
if (token) {
|
||||
requestConfig.header['Authorization'] = `${token}`; // 或根据你的后端要求调整
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
...requestConfig,
|
||||
success: (response) => {
|
||||
// 响应拦截器逻辑:对响应数据做点什么
|
||||
// 这里根据你的业务需求调整,例如直接返回 data :cite[1]:cite[8]
|
||||
resolve(response.data); // 注意:uni.request 的响应结构 response.data 才是服务端返回的数据体 :cite[1]
|
||||
},
|
||||
fail: (error) => {
|
||||
// 响应错误处理
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// (可选)为方便使用,可以为不同的 HTTP 方法创建快捷方法 :cite[7]
|
||||
['get', 'post', 'put', 'delete'].forEach((method) => {
|
||||
http[method] = (url, data, options = {}) => {
|
||||
return http({
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
data,
|
||||
...options
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
// 请求拦截器
|
||||
http.interceptors.request.use(
|
||||
config => {
|
||||
// 在发送请求之前做些什么,例如添加token等
|
||||
// config.headers['token'] = `${uni.getStorageSync('token')?? ''}`;
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
// 对请求错误做些什么
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器
|
||||
http.interceptors.response.use(
|
||||
response => {
|
||||
// 对响应数据做点什么
|
||||
return response.data; // 根据实际情况可能需要返回response.data或其他处理后的数据
|
||||
},
|
||||
error => {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default http;
|
||||
Reference in New Issue
Block a user