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 that.getOpenIdBywxCode() }, fail(res) { } }) }, bindViewlogin(){ if(this.data.userName==null||this.data.userName==''){ wx.showToast({ title: '请输入用户名', icon:'none', duration:2000 }) return } if(this.data.password==null||this.data.password==''){ wx.showToast({ title: '请输入密码', icon:'none', duration:2000 }) return } let that=this; var data = { userName:this.data.userName, password:this.data.password, openid:this.data.openid, } http.post_token("/system/minapp/AppLoginController/bindWxUser", data, that.bindSuccess) }, bindSuccess(res) { let that = this if (res.code != 200) { wx.showToast({ title: res.msg, icon: "none" }) // that.setData({ // isShowAccoutDialog : true // }) } else { // that.data.openid = res.openid app.globalToken = res.data.access_token ("登陆成功的令牌:",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, } http.post_token("/system/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess) }, openIdSuccess(res){ let that = this if (res!=null&&res.openid!=null) { that.data.openid = res.openid // wx.setStorageSync('openid', res.openid) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })