var that = this
var url = url
var random = Math.random()
if(!this.data.phone || !this.data.password){
wx.showToast({
title: '不能为空',
icon: 'none',
duration: 1000,
mask:true
})
wx.hideToast();
return
}
wx.request({
url: url,
data:{
phone:this.data.phone,
pwd:this.data.password,
random:random
},
header: {
'content-type': 'application/json' // 默认值
},
success: function(res) {
console.log(res.data);
// that.setData({teachers:res.data});
var data = res.data
if(data.ret){
wx.showToast({
title: '登录成功',
icon: 'succes',
duration: 1000,
mask:true
})
wx.hideToast();
var app = getApp();
app.appData.userInfo = {"user_id":res.data.user_id,"s_id":res.data.s_id};
wx.setStorage({
key: 'userInfo',
data: JSON.stringify(res.data)
})
wx.navigateTo({ url: '/pages/index/index',})
}else if(res.data.msg == 'phone is error'){
wx.showToast({
title: '手机号码错误',
icon: 'none',
duration: 1000,
mask:true
})
wx.hideToast();
}else if(res.data.msg == 'pwd is error'){
wx.showToast({
title: '密码错误',
icon: 'none',
duration: 1000,
mask:true
})
wx.hideToast();
}else if(res.data.msg == 'phone unregist now!'){
wx.showToast({
title: '该账号还没有注册',
icon: 'none',
duration: 1000,
mask:true
})
wx.hideToast();
}else{
wx.showToast({
title: '登录失败',
icon: 'none',
duration: 1000,
mask:true
})
wx.hideToast();
}
}
})
微信小程序的wx-request请求
最新推荐文章于 2024-08-20 20:34:21 发布