const httpRequest = (opts, data) => {
if(opts.type == 2){
baseUrl = 'http://lcsjfx.com/web';
}else{
baseUrl = 'http://lcsjfx.com/web';
}
uni.onNetworkStatusChange(function(res) {
if (!res.isConnected) {
uni.showToast({
title: '网络连接不可用!',
icon: 'none'
});
}
return false
});
let httpDefaultOpts = {
url: baseUrl + opts.url,
data: data,
method: opts.method,
header: opts.method == 'get' ? {
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
} : {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8'
},
dataType: 'json',
}
let promise = new Promise(function(resolve, reject) {
uni.request(httpDefaultOpts).then(
(res) => {
resolve(res[1])
}
).catch(
(response) => {
reject(response)
}
)
})
return promise
};
var post_url = 'xxxx';
let opts = {
type: 1, //1为数据接口;2为静态资源请求
url: post_url,
method: 'get'
};
request.httpRequest(opts).then(res => {
// todo 逻辑
});