let app = getApp(); Page({ /** * 页面的初始数据 */ data: { type: 'log', getCodeTime: 40, //发送短信的间隔时间 verifyCodeTime: '获取验证码', passwordfocus: false, mobilefocus: false, codefocus: false, typeName: 'password', passFlag: 1 }, onShow() { // wx.hideHomeButton() }, tapType: function (e) { var type = e.currentTarget.dataset.type; this.setData({ type }) }, foget: function () { wx.navigateTo({ url: '/pages/my/retrievePassword/retrievePassword', }) }, navlogs () { wx.navigateTo({ url: '/pages/logs/logs', }) }, codelog: function () { this.setData({ codelog: 1 }) }, getphone: function (e) { this.setData({ mobile: e.detail.value }) }, passWordInput: function (e) { var type = e.currentTarget.dataset.type if (this.data.typeName = 'text') { this.setData({ typeName: 'password' }) } else if (this.data.typeName = 'password') { this.setData({ typeName: 'text' }) } }, showPass() { // 显示密码而非*号 console.log(this.data.storePass) if (this.data.passFlag == 1) { // 第一次点击 this.setData({ passFlag: 2, typeName: 'text' }); } else { // 第二次点击 this.setData({ passFlag: 1, typeName: 'password' }); } }, bSubmit: function (e) { var that = this, mobile = e.detail.value.mobile, password = e.detail.value.password if (!mobile) { wx.showToast({ title: '请先填写手机号', duration: 3000, icon: 'none' }); that.setData({ mobilefocus: true }) return false; } if (!password) { that.setData({ passwordfocus: true }); return false } app.AjaxRequest('POST', { 'content-type': 'application/json' }, '/auth/login', { username: mobile, password: password }, function (res) { wx.showToast({ title: res.message, duration: 3000, icon: 'none' }); if (res.code == 0) { wx.cloud.init() wx.cloud.callFunction({ name: "pay", success(res) { wx.setStorageSync('OPENID', res.result.OPENID) } }) wx.setStorageSync('parkId', res.parkId) wx.setStorageSync('token', res.token) wx.setStorageSync('userId', res.userId) wx.reLaunch({ url: '/pages/index/index', }) } }) }, bindGetUserInfo(e) { var userInfo = e.detail.userInfo wx.cloud.init() wx.cloud.callFunction({ // 云函数名称 name: 'pay', }).then(res => { console.log(e.detail.userInfo) app.AjaxRequest('POST', { 'content-type': 'application/json' }, '/wx/login', { avatar: userInfo.avatarUrl, username: userInfo.nickName, gender: userInfo.gender === 1 ? '0' : '1', openid: res.result.OPENID }, function (res) { if (res.code == 0) { wx.setStorageSync('userId', res.userId) wx.setStorageSync('token', res.token) wx.reLaunch({ url: '/pages/index/index', }) } }) }) }, /** * 执行发送验证码 */ verifyCodeEvent: function (e) { var that = this; //验证手机号 if (that.data.buttonDisable == true) return false; var mobile = that.data.mobile; var regMobile = /^[1]([3-9])[0-9]{9}$/; if (!regMobile.test(mobile)) { wx.showToast({ title: '手机号错误', duration: 3000, icon: 'none' }); that.setData({ mobilefocus: true }); return false; } that.Countdown() //验证手机号 END wx.showLoading(); wx.request({ header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'GET', url: app.DOMAIN_NAME + '/sms/send', data: { username: mobile, type: 'MEMBER_REGISTER' }, success: res => { var mes = res.data.message, code = mes.slice(21, 25) that.setData({ code }) wx.hideLoading() that.Countdown(); } }) }, /** * 发送短信倒计时,防止恶意刷短信 */ Countdown: function () { var that = this; that.setData({ buttonDisable: true }); var getCodeTime = wx.getStorageSync('getCodeTime'); var intervalId = setInterval(function () { getCodeTime--; wx.setStorageSync('getCodeTime', getCodeTime); that.setData({ verifyCodeTime: '重新获取' + '(' + getCodeTime + 's' + ')' }); //倒计时完成 if (getCodeTime == 0) { wx.setStorageSync('getCodeTime', that.data.getCodeTime); clearInterval(intervalId); that.setData({ verifyCodeTime: '获取验证码', buttonDisable: false }) } }, 1000); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (e) { var that = this; //限制发送验证码的时间,防止恶意刷短信 var getCodeTime = wx.getStorageSync('getCodeTime'); if (getCodeTime <= that.data.getCodeTime - 1 && getCodeTime > 0) { that.Countdown(that); } else { wx.setStorageSync('getCodeTime', that.data.getCodeTime) that.setData({ buttonDisable: false }) } }, /** * 授权登录 */ authorLogin: function (e) { let _this = this; if (e.detail.errMsg !== 'getUserInfo:ok') { return false; } wx.showLoading({ title: "正在登录", mask: true }); // 执行微信登录 wx.login({ success: function (res) { //发送请求 wx.request({ header: { 'content-type': 'application/json' }, method: 'POST', url: app.DOMAIN_NAME + '/social_user_login/login', data: { code: res.code, rawData: e.detail.rawData, encryptedData: e.detail.encryptedData, ivStr: e.detail.iv, signature: e.detail.signature }, success(res) { console.log(res); if (res.data.code != 0) { wx.showModal({ confirmText: '好的', content: res.data.errmsg || '服务器开小差去了,请重试', showCancel: false }); } else if (res.data.code == 0) { wx.setStorageSync('userId', res.data.userId) wx.setStorageSync('token', res.data.token) wx.hideLoading() wx.reLaunch({ url: '/pages/index/index', }) } }, fail(ret) {} }) } }); }, /** * 授权成功 跳转回原页面 */ navigateBack: function () { wx.navigateBack(); // let currentPage = wx.getStorageSync('currentPage'); // wx.redirectTo({ // url: '/' + currentPage.route + '?' + App.urlEncode(currentPage.options) // }); }, })