init
This commit is contained in:
39
common/request.js
Normal file
39
common/request.js
Normal file
@ -0,0 +1,39 @@
|
||||
const request = (config) => {
|
||||
uni.showLoading({
|
||||
title: '数据加载中...',
|
||||
mask: true
|
||||
})
|
||||
// 处理 apiUrl
|
||||
config.url = 'http://192.168.0.125:1777' + 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;
|
Reference in New Issue
Block a user