blob: d830a76788692492a8e29f850bd788f4c3a4f729 [file] [log] [blame]
// pages/wxlogin/wxlogin.js
Page({
/**
* 页面的初始数据
*/
data: {
phone: '',
password: ''
},
setPhone: function(e) {
this.setData({
phone: e.detail.value
})
},
setPassword: function(e) {
this.setData({
password: e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
toRegister: function() {
wx.navigateTo({
url: '../register/register',
})
},
doLogin: function() {
var phone = this.data.phone;
var pwd = this.data.password;
if (wx.$isEmpty(phone) || wx.$isEmpty(pwd)) {
return;
}
//loadingElement('loginBtn', '登录中...')
wx.showLoading({
title: '登录中',
})
var platform = wx.getStorageInfoSync('platform')
var param = {
"username": phone,
"password": pwd,
"platform": platform
}
wx.$doPost('/login', param, function(ok, ret) {
wx.hideLoading();
if (ok) {
if (ret.data.code != 200) {
wx.showModal({
title: '错误',
content: ret.data.msg ,
duration: 2000
})
} else {
console.log(ret.data);
wx.setStorageSync("phone", phone);
wx.setStorageSync("phoneX", ret.data.phone);
wx.setStorageSync("token", ret.data.token);
wx.setStorageSync("uid", ret.data.uid);
wx.setStorageSync("tenantid", ret.data.tenantid);
wx.setStorageSync("tokenexpire", ret.data.expire);
wx.setStorageSync("tokentime", ret.data.now);
wx.setStorageSync("userid", ret.data.userid);
wx.setStorageSync("signed", ret.data.signed);
wx.setStorageSync("paypwdset", ret.data.paypwdset);
wx.setStorageSync("name", ret.data.name);
wx.redirectTo({
url: '../index/index',
})
}
} else {
wx.showModal({
title: '错误',
content: "请求失败了" + ret.status + ",请稍后再试",
duration: 2000
})
}
})
}
})