import Toast from '@vant/weapp/toast/toast'; const _Http = getApp().globalData.http; const md5 = require("../../utils/md5"); Page({ /** * 页面的初始数据 */ data: { isAgree: true, phoneNumber: "", password: "", inputType: "password", //密码输入框类型 memory: true, //记忆 disabled: true, //是否禁用 loading: false, //登陆中 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ ...wx.getStorageSync('loginMsg') }) this.allowOrNot() }, /* 用户登录 */ userLogin() { if (this.data.loading || this.data.disabled) return; if (!this.data.isAgree) return Toast({ message: '请阅读并勾选用户协议', position: 'bottom' }); this.setData({ loading: true }) /* "accountno": this.data.phoneNumber, "password": md5.hexMD5(this.data.password), */ _Http.login({ "accountno": "test", "password": "e10adc3949ba59abbe56e057f20f883e", "systemclient": "wechatapp" }).then(res => { console.log("登录", res) this.setData({ loading: false }) if (res.msg != '成功') return wx.showToast({ title: res.msg, icon: "none" }) wx.setStorageSync('account_list', res.account_list) wx.setStorageSync('loginMsg', { phoneNumber: this.data.phoneNumber, password: (this.data.memory) ? this.data.password : '' }) wx.switchTab({ url: '/pages/tabbar/home/index' }) }) }, /* 改变密码输入框类型 */ changePasswordType() { this.setData({ inputType: this.data.inputType == "text" ? 'password' : 'text' }) }, /* 授权 */ agreementChange({ detail }) { this.setData({ isAgree: detail }) }, /* 手机号 */ inputPhone(e) { this.setData({ phoneNumber: e.detail.value.trim() }) this.allowOrNot() }, /* 密码 */ inputPassword(e) { this.setData({ password: e.detail.value.trim() }) this.allowOrNot() }, /* 验证是否允许登录 */ allowOrNot() { this.setData({ disabled: (this.data.phoneNumber.length == 11 && this.data.password.length >= 6) ? false : true }) }, /* 是否记忆密码 */ isMemory() { this.setData({ memory: !this.data.memory }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })