80 lines
1.7 KiB
JavaScript
80 lines
1.7 KiB
JavaScript
//请求接口
|
|
let request = function (obj){
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask:true
|
|
})
|
|
let {
|
|
url,
|
|
data,
|
|
method,
|
|
header,
|
|
dataType,
|
|
responseType,
|
|
complete,
|
|
name,
|
|
urldata
|
|
} = obj
|
|
url="https://daigou.sdbairui.com/index.php/WXAPI/" + url
|
|
let text = ""
|
|
for(let i in urldata){
|
|
if(urldata[i] === ''){
|
|
text += `/${i}`
|
|
|
|
}else{
|
|
text += `/${i}/${urldata[i]}`
|
|
|
|
}
|
|
}
|
|
url+=text
|
|
// if(method == "POST" || method == "post"){
|
|
// if(header == undefined){
|
|
// header ={}
|
|
// }
|
|
// header['content-type'] = "application/x-www-form-urlencoded"
|
|
// }
|
|
if(data == undefined){
|
|
data = {}
|
|
}
|
|
data[name || 'openid'] = wx.getStorageSync("openid")
|
|
return new Promise((res,rej)=>{
|
|
wx.request({
|
|
url,
|
|
data,
|
|
method,
|
|
header,
|
|
dataType,
|
|
responseType,
|
|
success(data){
|
|
res(data)
|
|
|
|
},
|
|
fail(data){
|
|
rej(data)
|
|
},
|
|
complete(){
|
|
wx.hideLoading()
|
|
}
|
|
})
|
|
})
|
|
}
|
|
let getuserid = function(){
|
|
return new Promise((res,rej)=>{
|
|
request({
|
|
url:"User/validateOpenid"
|
|
|
|
}).then((r)=>{
|
|
if(r.data.code == 400){
|
|
res(0)
|
|
}else{
|
|
res(r.data.data.user_id)
|
|
|
|
}
|
|
})
|
|
})
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
request,getuserid
|
|
} |