| binquan.qiu | 7f2665f | 2020-03-27 17:19:57 +0800 | [diff] [blame^] | 1 | // pages/wxlogin/wxlogin.js |
| 2 | Page({ |
| 3 | |
| 4 | /** |
| 5 | * 页面的初始数据 |
| 6 | */ |
| 7 | data: { |
| 8 | phone: '', |
| 9 | password: '' |
| 10 | |
| 11 | }, |
| 12 | |
| 13 | setPhone: function(e) { |
| 14 | this.setData({ |
| 15 | phone: e.detail.value |
| 16 | }) |
| 17 | }, |
| 18 | setPassword: function(e) { |
| 19 | this.setData({ |
| 20 | password: e.detail.value |
| 21 | }) |
| 22 | }, |
| 23 | |
| 24 | /** |
| 25 | * 生命周期函数--监听页面加载 |
| 26 | */ |
| 27 | onLoad: function(options) { |
| 28 | |
| 29 | }, |
| 30 | |
| 31 | /** |
| 32 | * 生命周期函数--监听页面初次渲染完成 |
| 33 | */ |
| 34 | onReady: function() { |
| 35 | |
| 36 | }, |
| 37 | |
| 38 | /** |
| 39 | * 生命周期函数--监听页面显示 |
| 40 | */ |
| 41 | onShow: function() { |
| 42 | |
| 43 | }, |
| 44 | |
| 45 | /** |
| 46 | * 生命周期函数--监听页面隐藏 |
| 47 | */ |
| 48 | onHide: function() { |
| 49 | |
| 50 | }, |
| 51 | |
| 52 | /** |
| 53 | * 生命周期函数--监听页面卸载 |
| 54 | */ |
| 55 | onUnload: function() { |
| 56 | |
| 57 | }, |
| 58 | |
| 59 | /** |
| 60 | * 页面相关事件处理函数--监听用户下拉动作 |
| 61 | */ |
| 62 | onPullDownRefresh: function() { |
| 63 | |
| 64 | }, |
| 65 | |
| 66 | /** |
| 67 | * 页面上拉触底事件的处理函数 |
| 68 | */ |
| 69 | onReachBottom: function() { |
| 70 | |
| 71 | }, |
| 72 | |
| 73 | /** |
| 74 | * 用户点击右上角分享 |
| 75 | */ |
| 76 | onShareAppMessage: function() { |
| 77 | |
| 78 | }, |
| 79 | toRegister: function() { |
| 80 | wx.navigateTo({ |
| 81 | url: '../register/register', |
| 82 | }) |
| 83 | }, |
| 84 | doLogin: function() { |
| 85 | var phone = this.data.phone; |
| 86 | var pwd = this.data.password; |
| 87 | if (wx.$isEmpty(phone) || wx.$isEmpty(pwd)) { |
| 88 | return; |
| 89 | } |
| 90 | //loadingElement('loginBtn', '登录中...') |
| 91 | wx.showLoading({ |
| 92 | title: '登录中', |
| 93 | }) |
| 94 | var platform = wx.getStorageInfoSync('platform') |
| 95 | var param = { |
| 96 | "username": phone, |
| 97 | "password": pwd, |
| 98 | "platform": platform |
| 99 | } |
| 100 | wx.$doPost('/login', param, function(ok, ret) { |
| 101 | wx.hideLoading(); |
| 102 | |
| 103 | if (ok) { |
| 104 | if (ret.data.code != 200) { |
| 105 | wx.showModal({ |
| 106 | title: '错误', |
| 107 | content: ret.data.msg , |
| 108 | duration: 2000 |
| 109 | }) |
| 110 | |
| 111 | |
| 112 | } else { |
| 113 | console.log(ret.data); |
| 114 | wx.setStorageSync("phone", phone); |
| 115 | wx.setStorageSync("phoneX", ret.data.phone); |
| 116 | wx.setStorageSync("token", ret.data.token); |
| 117 | wx.setStorageSync("uid", ret.data.uid); |
| 118 | wx.setStorageSync("tenantid", ret.data.tenantid); |
| 119 | wx.setStorageSync("tokenexpire", ret.data.expire); |
| 120 | wx.setStorageSync("tokentime", ret.data.now); |
| 121 | wx.setStorageSync("userid", ret.data.userid); |
| 122 | wx.setStorageSync("signed", ret.data.signed); |
| 123 | wx.setStorageSync("paypwdset", ret.data.paypwdset); |
| 124 | wx.setStorageSync("name", ret.data.name); |
| 125 | wx.redirectTo({ |
| 126 | url: '../index/index', |
| 127 | }) |
| 128 | } |
| 129 | } else { |
| 130 | wx.showModal({ |
| 131 | title: '错误', |
| 132 | content: "请求失败了" + ret.status + ",请稍后再试", |
| 133 | duration: 2000 |
| 134 | }) |
| 135 | } |
| 136 | }) |
| 137 | |
| 138 | } |
| 139 | }) |