Files
jinhuaihua-h5/common/request.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-01 10:55:59 +08:00
const request = (config) => {
uni.showLoading({
title: '数据加载中...',
mask: true
})
// 处理 apiUrl
2021-09-03 18:50:45 +08:00
// config.url = 'http://192.168.0.125:1777' + config.url;
config.url = 'http://golden.shangqie.cn/api' + config.url;
2021-09-01 10:55:59 +08:00
if(!config.data){
config.data = {};
}
// if (config.url.indexOf('/distribution') !== -1) {
// config.header = {
// token: uni.getStorageSync('fxToken')
// }
// }
// else if (config.url.indexOf('.do') !== -1) {
// config.header = {
// token: uni.getStorageSync('token')
// }
// }
console.log(JSON.stringify(config.data));
let promise = new Promise(function(resolve, reject) {
uni.request(config).then(responses => {
// 异常
if (responses[0]) {
reject({message : "网络超时"});
} else {
let response = responses[1].data; // 如果返回的结果是data.data的嫌麻烦可以用这个return res,这样只返回一个data
resolve(response);
}
uni.hideLoading()
}).catch(error => {
reject(error);
})
})
return promise;
};
export default request;