import Toast from '@vant/weapp/toast/toast'; const _Http = getApp().globalData.http; const md5 = require("../../utils/md5"); Page({ /** * 页面的初始数据 */ data: { isAgree: true, accountno: "", 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 }) _Http.login({ "accountno": this.data.accountno, "password": md5.hexMD5(this.data.password), "systemclient": "wechatsaletool" }).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', { accountno: this.data.accountno, password: (this.data.memory) ? this.data.password : '' }) if (res.account_list.length == 1) { wx.setStorageSync('userMsg', res.account_list[0]) wx.switchTab({ url: '/pages/tabbar/home/index' }) } else { wx.redirectTo({ url: './selectSite', }) } }) }, /* 改变密码输入框类型 */ changePasswordType() { this.setData({ inputType: this.data.inputType == "text" ? 'password' : 'text' }) }, /* 授权 */ agreementChange({ detail }) { this.setData({ isAgree: detail }) }, /* 手机号 */ inputPhone(e) { this.setData({ accountno: e.detail.value.trim() }) this.allowOrNot() }, /* 密码 */ inputPassword(e) { this.setData({ password: e.detail.value.trim() }) this.allowOrNot() }, /* 验证是否允许登录 */ allowOrNot() { this.setData({ disabled: (this.data.accountno.length > 0 && this.data.password.length > 5) ? false : true }) }, /* 是否记忆密码 */ isMemory() { this.setData({ memory: !this.data.memory }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })