199 lines
4.6 KiB
JavaScript
199 lines
4.6 KiB
JavaScript
// pages/meeting/meeting.js
|
|
import UserApi from '../../assets/js/http/userApi'
|
|
import { encrypt } from '../../assets/js/jsencrypt/rsa'
|
|
import { wxBind } from '../../assets/js/common'
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
show: true, // 默认显示的是闭眼睛
|
|
form: {
|
|
currdatetime: '',
|
|
requestCodeSuccess: true,
|
|
randCodeImage: '' // 验证码
|
|
},
|
|
rsaPublicKey: '', // 公钥
|
|
flag: false
|
|
},
|
|
showPassword(){
|
|
this.setData({
|
|
show: !this.data.show
|
|
})
|
|
},
|
|
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',
|
|
duration: 2000
|
|
})
|
|
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',
|
|
duration: 2000
|
|
})
|
|
this.data.flag = false
|
|
return
|
|
} else {
|
|
this.data.flag = true
|
|
}
|
|
}
|
|
if(!e.detail.value.password){
|
|
this.data.flag = false
|
|
wx.showToast({
|
|
title: '请输入密码',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return
|
|
} else {
|
|
this.data.flag = true
|
|
}
|
|
if(!e.detail.value.captcha){
|
|
this.data.flag = false
|
|
wx.showToast({
|
|
title: '请输入验证码',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return
|
|
}else{
|
|
this.data.flag = true
|
|
}
|
|
console.log('form发生了submit事件,携带数据为:', e.detail.value)
|
|
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.message == '请先用手机号登录'){
|
|
wx.showToast({
|
|
title: '首次登录请用验证码方式登录',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
setTimeout(() => {
|
|
wx.navigateBack()
|
|
}, 2000);
|
|
return
|
|
}else{
|
|
// 绑定微信
|
|
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: 3000
|
|
})
|
|
this.handleChangeCheckCode()
|
|
}
|
|
}).catch(err=>{
|
|
wx.showToast({
|
|
title: err.message,
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
})
|
|
}
|
|
},
|
|
|
|
// 绑定微信
|
|
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的登录页
|
|
}
|
|
})
|
|
}
|
|
})
|