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.
117 lines
2.2 KiB
117 lines
2.2 KiB
// pages/login/login.js
|
|
import { loginUrl } from "../../utils/getApiUrl";
|
|
import { Request } from "../../common";
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
userNameCan: false,
|
|
passwordCan: false,
|
|
},
|
|
|
|
setColor: function () {
|
|
this.setData({
|
|
backgroundInput: this.data.userNameCan == true && this.data.passwordCan == true ? 'rgb(51, 133, 255)' : 'rgb(255,255,255)',
|
|
colorInput: this.data.userNameCan == true && this.data.passwordCan == true ? 'rgb(255, 255, 255)' : 'rgb(201,201,201)',
|
|
})
|
|
},
|
|
bindUserName: function (e) {
|
|
this.setData({
|
|
userNameCan: e.detail.value.length > 0 ? true : false,
|
|
})
|
|
this.setColor();
|
|
},
|
|
bindPassword: function (e) {
|
|
this.setData({
|
|
passwordCan: e.detail.value.length > 0 ? true : false,
|
|
})
|
|
this.setColor();
|
|
},
|
|
|
|
// 登录
|
|
getLogin: function (e) {
|
|
if (e.detail.value.username.length == 0 || e.detail.value.password == 0) {
|
|
wx.showToast({
|
|
title: '请输入用户名密码',
|
|
icon: 'none',
|
|
})
|
|
return
|
|
}
|
|
wx.showLoading()
|
|
Request.post(loginUrl(), {
|
|
"username": e.detail.value.username,
|
|
"password": e.detail.value.password
|
|
}).then((res) => {
|
|
if (!res.authorized) {
|
|
wx.showToast({ title: "登录失败", icon: "none" });
|
|
return;
|
|
}
|
|
wx.setStorageSync('token', res.token);
|
|
wx.setStorageSync("userInfo", res);
|
|
getApp().globalData.userInfo = res
|
|
wx.switchTab({
|
|
url: '/pages/index/index',
|
|
})
|
|
wx.hideLoading()
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
})
|