import http from '../../base/httputil' const app = getApp() Page({ /** * 页面的初始数据 */ data: { isShowAccoutDialog : false, isBindSuccess : false, userInfo:null, userName :"点击登录", password: null, openid: null }, inputUserName(e){ this.userName = e.detail.value }, inputPassword(e){ this.password = e.detail.value }, init_userInfo() { let that = this if (app.globalToken == null) { http.showLoading() wx.getUserProfile({ desc: 'desc', success: (res) => { this.getSysUserInfo(res.userInfo) that.setData({ userInfo : res.userInfo }) }, fail: res => { console.log(res) }, }) } }, getSysUserInfo(info) { let that = this wx.login({ success(res) { var code = res.code var data = { wxCode: code, wxNickName: info.nickName, wxAvatarUrl: info.avatarUrl } http.send_post("/auth/applogin", data, that.loginSuccess) }, fail(res) { console.log("ffff", res) } }) }, loginSuccess(res) { console.log(res) let that = this if (res.data.code != 200) { that.openid = res.data.data wx.showToast({ title: res.data.msg, icon: "none" }) http.hideLoading() that.setData({ isShowAccoutDialog : true }) } else { app.globalToken = res.data.data.access_token console.log("我的令牌:",app.globalToken ) //登录成功,获取首页数据 http.hideLoading() this.setData({ isBindSuccess : true }) } }, clear(){ wx.clearStorage({ success: (res) => { wx.showToast({ title: '清理成功', }) wx.removeStorageSync('userInfo'); wx.removeStorageSync('openid'); app.globalToken=null; this.setData({ isShowAccoutDialog : false, isBindSuccess : false, userInfo:null, userName :"游客", password: null, openid: null }) wx.reLaunch({ url: '../index/index' }) }, }) }, modalCancel(){ this.setData({ isShowAccoutDialog : false }) }, modalSubmit(){ let obj = new Object() obj.openid = this.openid obj.userName = this.userName obj.password = this.password http.send_post("/system/minapp/AppLoginController/bindWxUser",obj,this.modalSubmitSuccess) }, modalSubmitSuccess(res){ wx.showToast({ title: res.data.msg, icon: "none" }) if (res.data.code == 200) { this.setData({ isShowAccoutDialog : false, isBindSuccess : true }) } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })