You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
1.7 KiB

7 months ago
/**
* 支付专用网络请求
* url: 绝对路径请求地址
* token: 如需请传
* data: 参数
*/
function http(options) {
return new Promise((resolve, reject) => {
uni.showLoading({
title: '加载中...',
mask: true
});
var url = options.url
uni.request({
// 组装请求地址
url: url,
// 请求方式 POST
method: 'POST',
header: {
'content-type': "application/x-www-form-urlencoded",
'token': (options.token == undefined || options.token == '') ? "token is null" : options
.token
},
// 具体参数
data: options.data,
success: res => {
// 关闭显示框
uni.hideLoading();
console.log('Http网络路径', url)
console.log('Http网络请求结果', JSON.stringify(res.data))
if (res.statusCode == 200) {
// 进行success字段检查
if (!res.data.success) {
uni.showToast({
title: res.data.msg,
// 保证文字长度
icon: "none",
duration: 3000
})
// 直接返回Response
reject(res.data)
} else {
// 直接返回Response
resolve(res.data)
}
} else {
uni.showToast({
title: res.statusCode + ":" + res.data.error,
// 保证文字长度
icon: "none",
duration: 3000
})
// 返回错误数据
reject({
success: false,
msg: res.data.error,
code: '1111'
})
}
},
fail: (err) => {
// 关闭显示框
uni.hideLoading();
console.log("Http网络请求fail", err)
uni.showToast({
title: err.errMsg,
icon: 'none'
})
// 返回错误数据
reject({
success: false,
msg: err.errMsg,
code: '1111'
})
},
complete: () => {
}
});
})
}
export {
http
}