Files
熊丽君 9d64ce4bfa 提交
2021-09-03 18:50:45 +08:00

40 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const request = (config) => {
uni.showLoading({
title: '数据加载中...',
mask: true
})
// 处理 apiUrl
// config.url = 'http://192.168.0.125:1777' + config.url;
config.url = 'http://golden.shangqie.cn/api' + config.url;
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;