// pages/meeting/meeting.js import UserApi from '../../assets/js/http/userApi' import { encrypt } from '../../assets/js/jsencrypt/rsa' import { wxBind } from '../../assets/js/common' // var countdown = 60; // 倒计时秒数 Page({ /** * 页面的初始数据 */ data: { form: { currdatetime: '', requestCodeSuccess: true, randCodeImage: '' // 验证码 }, rsaPublicKey: '', // 公钥 flag: false }, back(){ wx.navigateBack({ delta: 1 }) }, // 改变验证码 handleChangeCheckCode() { this.data.currdatetime = new Date().getTime() UserApi.sendImage({time: this.data.currdatetime}).then(res=>{ if (res.success) { this.setData({ "form.randCodeImage": res.result, "form.requestCodeSuccess": true }) } else { this.setData({ "form.requestCodeSuccess": false }) } }).catch(() => { this.setData({ "form.requestCodeSuccess": false }) }) }, // 提交 formSubmit(e) { if(!e.detail.value.phone){ this.data.flag = false wx.showToast({ title: '请输入手机号', icon: 'none' }) return } else { let pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/ if(!pattern.test(e.detail.value.phone)){ wx.showToast({ title: '请输入正确的手机号!', icon: 'none' }) this.data.flag = false return } else { this.data.flag = true } } if(!e.detail.value.password){ this.data.flag = false wx.showToast({ title: '请输入密码', icon: 'none' }) return } else { let pattern = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,}$/ if(!pattern.test(e.detail.value.password)){ wx.showToast({ title: '密码由8位数字、大小写字母和特殊符号组成!', icon: 'none' }) this.data.flag = false return } else { this.data.flag = true } } if(!e.detail.value.captcha){ this.data.flag = false wx.showToast({ title: '请输入验证码', icon: 'none' }) return }else{ this.data.flag = true } console.log('form发生了submit事件,携带数据为:', e.detail.value) // const time = new Date().getTime() let params = { username: encrypt(this.data.rsaPublicKey, e.detail.value.phone), password: encrypt(this.data.rsaPublicKey, e.detail.value.password), checkKey: this.data.currdatetime, captcha: e.detail.value.captcha, rsaPublicKey: this.data.rsaPublicKey, } if(this.data.flag){ UserApi.passWordLogin(params).then(res => { if(res.success){ // 如果绑定过微信就不再进行绑定 if(!res.result.userInfo.openId){ // 绑定微信 this.wxBindPhone() } // 存token和userInfo wx.setStorage({ key: 'X-Access-Token', data: res.result.token }) wx.setStorage({ key: 'userInfo', data: res.result.userInfo }) // 跳转首页 wx.switchTab({ url: '../home/home', }) }else{ wx.showToast({ title: res.message, icon: 'none', duration: 2000 }) this.handleChangeCheckCode() } }).catch(err => { wx.hideToast() }) } }, // 绑定微信 wxBindPhone(){ const that = this // 获取openid进行手机号和微信的绑定 wxBind((res)=>{ let params = { openId: res.data.openid, rsaPublicKey: that.data.rsaPublicKey } // 需要判断是否绑定过微信,再进行绑定请求 UserApi.wxBind(params).then(res=>{}) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.handleChangeCheckCode() const that = this wx.getStorage({ key: 'rsaPublicKey', success (res) { that.setData({ rsaPublicKey: res.data }) }, fail: function(){ // 缓存中没有登录过默认app.json的登录页 } }) } })