// pages/login/login.js const utils = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { uid: '', account: '', smsCode: '', canSend: false, //是否可以发送手机验证码(true为不行,false为可以) time: 60, //倒计时 timeText: '获取验证码', //倒计时文字 mobileActive: false, //是否激活 codeActive: false, //是否激活 mLine: false, //下划线 cLine: false, //下划线 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ uid: options.uid }) }, //登录请求 login() { let params = { account: utils.trimAll(this.data.account), smsCode: utils.trimAll(this.data.smsCode), reqChannel: 5, loginType: 2 } if (this.data.uid) { params.unionId = this.data.uid } if (params.account === '') { utils.toast('手机号码不能为空') return } if (!utils.testMobile(params.account)) { utils.toast('请填写正确的手机号码') return } if (params.smsCode === '') { utils.toast('验证码不能为空') return } /* 12345678901服务商 12345678902企业 12345678903运营商*/ // let params = { // account: '12345678902', // password: '123456', // reqChannel: 5, // loginType: 1 // } utils.axios({ method: 'post', url: '/login', data: params, sendBefore() { wx.showLoading({ title: '登录中...', mask: true }) }, complete() { wx.hideLoading() }, success: res => { this.loginSuccess(res.data) } }) }, //登录成功后的执行函数 loginSuccess(result) { utils.toast('登录成功') let userInfo = { roles: result.usertype, mobile: result.account, userName: result.userName, roleName: result.roleName } wx.setStorageSync('expirationTime', result.expirationTime) wx.setStorageSync('userInfo', userInfo) wx.setStorageSync('token', result.token) wx.reLaunch({ url: '/pages/index/index' }) }, //获取验证码 sendCode(e) { let params = { phoneNo: utils.trimAll(this.data.account), } if (params.phoneNo === '') { utils.toast('手机号码不能为空') return } if (!utils.testMobile(params.phoneNo)) { utils.toast('请填写正确的手机号码') return } utils.axios({ method: 'post', url: '/sms/getSmscode', data: params, sendBefore() { wx.showLoading({ title: '验证码发送中...', mask: true }) }, complete() { wx.hideLoading() }, success: () => { this.countDown() utils.toast('发送成功') } }) }, //获取手机 getAccount(e) { this.setData({ account: e.detail.value }) }, //获取验证码 getSmsCode(e) { this.setData({ smsCode: e.detail.value }) }, //控制发送验证码按钮是否可以点击 controlSend() { if (utils.testMobile(this.data.account)) { this.setData({ canSend: false }) } else { this.setData({ canSend: true }) } }, //倒计时 countDown() { let time = this.data.time this.setData({ canSend: true }) let clearTimer = setInterval(() => { if (time <= 0) { clearInterval(clearTimer) this.setData({ time: 60, timeText: '重发验证码', canSend: false }) } else { time-- this.setData({ time: time, timeText: time + '秒后可重发' }) } }, 1000) }, //聚焦失焦 mfocusInput() { this.setData({ mobileActive: true, mLine: true }) }, mblurInput(e) { this.setData({ mLine: false }) if (!utils.trimAll(this.data.account)) { this.setData({ mobileActive: false }) } }, cfocusInput() { this.setData({ codeActive: true, cLine: true }) }, cblurInput(e) { this.setData({ cLine: false }) if (!utils.trimAll(this.data.smsCode)) { this.setData({ codeActive: false }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function (res) { return { title: '诺信云', path: '/pages/index/index' } } })