import http from '../../base/httputil' const app = getApp() // pages/denglu/denglu.js Page({ /** * 页面的初始数据 */ data: { userName:"", password:"", wxCode:"", openid:"", }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { app.isLoginSuccess=false; let that=this; wx.login({ success(res) { that.data.wxCode = res.code console.log("login_wxCode_load",":"+that.data.wxCode) that.getOpenIdBywxCode() }, fail(res) { console.log("ffff", res) } }) }, bindViewlogin(){ if(!this.data.userName||!this.data.password){ wx.showToast({ title: '请输入用户名', icon:'none', duration:2000 }) return } if(!this.data.password){ wx.showToast({ title: '请输入密码', icon:'none', duration:2000 }) return } let that=this; console.log("要提交给服务器的用户名和密码是",this.data.wxCode+"_"+this.data.userName+"_"+this.data.password); var data = { wxCode: this.data.wxCode, // wxNickName: this.data.userName, // wxAvatarUrl: info.avatarUrl userName:this.data.userName, password:this.data.password, } http.send_post("/system/minapp/AppLoginController/bindWxUser", data, that.bindSuccess) }, bindSuccess(res) { let that = this if (res.code != 200) { that.openid = res.openid wx.showToast({ title: res.msg, icon: "none" }) // that.setData({ // isShowAccoutDialog : true // }) } else { app.globalToken = res.data.access_token console.log("登陆成功的令牌:",app.globalToken) wx.setStorageSync('userName', that.data.userName) wx.setStorageSync('password', that.data.password) app.isLoginSuccess=true; this.setData({ isBindSuccess : true }) wx.reLaunch({ url: '../index/index', }) } }, bindViewUserName(e){ this.data.userName = e.detail.value; }, bindViewPassword(e){ this.data.password = e.detail.value }, getOpenIdBywxCode(){ let that=this var data = { wxCode: that.data.wxCode, } console.log("login_wxCode",":"+that.data.wxCode) http.send_post("/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess) }, openIdSuccess(res){ let that = this if (res.code != 200) { that.data.openid = res.openid console.log("login_wxOpenid",":"+that.data.openid ) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })