市北党建引领小程序初始化
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.2 KiB

// pages/login/login.js
var api = require("../../utils/api.js");
Page({
/**
* 页面的初始数据
*/
data: {
userName: '13000000001',
password: '123456'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
handleLogin () {
var that = this;
if (that.data.userName == '') {
wx.showToast({
title: '请输入用户名',
icon: 'none',
duration: 2000
});
return false;
}
if (that.data.password == '') {
wx.showToast({
title: '请输入密码',
icon: 'none',
duration: 2000
});
return false;
}
wx.login({
success: function (res) {
wx.showLoading({
title: '登录中,请稍后',
});
var code = res.code;
if (code) {
var params = {
username: that.data.userName,
password: that.data.password,
wxCode: code
};
api.userLogin(params).then( (res) =>{
console.log(res);
if (res.code == 0) {
wx.setStorageSync('token', res.data.token);
wx.setStorageSync('userTagKey', res.data.userTagKey);
wx.setStorageSync('deptDataScopeList', JSON.stringify(res.data.deptDataScopeList));
wx.redirectTo({
url: '/pages/home/home'
});
}
else {
console.log(222);
wx.showToast({
title: res.msg,
icon: 'none',
duration: 2000
});
}
wx.hideLoading();
});
}
}
});
},
getUserName(e) {
this.setData({
userName: e.detail.value
});
},
getPassword (e) {
this.setData({
password: e.detail.value
});
},
toRegister(){
// wx.navigateTo({
// url: `/subpages/home/pages/newsDetail/newsDetail`
// })
wx.navigateTo({
url: `/pages/formid/formid`
})
}
})