【bug】 bug修改 微信扫描二维码签到登录后跳转的问题

This commit is contained in:
fengachen
2022-01-07 14:56:47 +08:00
parent 877622c36b
commit 878f8b52ec
9 changed files with 240 additions and 103 deletions
+56 -35
View File
@@ -1,7 +1,11 @@
// pages/meeting/meeting.js
import UserApi from '../../assets/js/http/userApi'
import { encrypt } from '../../assets/js/jsencrypt/rsa'
import { wxBind } from '../../assets/js/common'
import {
encrypt
} from '../../assets/js/jsencrypt/rsa'
import {
wxBind
} from '../../assets/js/common'
Page({
@@ -21,18 +25,20 @@ Page({
rsaPublicKey: '', // 公钥
flag: false
},
showPassword(){
showPassword() {
this.setData({
show: !this.data.show
})
},
goBack(){
goBack() {
wx.navigateBack()
},
// 改变验证码
handleChangeCheckCode() {
this.data.currdatetime = new Date().getTime()
UserApi.sendImage({time: this.data.currdatetime}).then(res=>{
UserApi.sendImage({
time: this.data.currdatetime
}).then(res => {
if (res.success) {
this.setData({
"form.randCodeImage": res.result,
@@ -49,7 +55,7 @@ Page({
})
})
},
clearrepeatval(){
clearrepeatval() {
this.data.vals = []
this.setData({
password: ''
@@ -61,22 +67,22 @@ Page({
const vals = this.data.vals
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
if (currentval) { // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
if (vals.length == 1) {
const v = vals[vals.length - 1].length
if (v > 1) { // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatval()
}
}
if(vals.length > 1){
if (vals.length > 1) {
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const lastv = vals[vals.length - 1].length // 获取最后一个值的长度
const secondv = vals[vals.length - 2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
if (dis > 1) {
this.clearrepeatval()
}
}
@@ -85,7 +91,7 @@ Page({
},
// 提交
formSubmit(e) {
if(!e.detail.value.phone){
if (!e.detail.value.phone) {
this.data.flag = false
wx.showToast({
title: '请输入手机号',
@@ -95,7 +101,7 @@ Page({
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)){
if (!pattern.test(e.detail.value.phone)) {
wx.showToast({
title: '请输入正确的手机号!',
icon: 'none',
@@ -107,7 +113,7 @@ Page({
this.data.flag = true
}
}
if(!e.detail.value.password){
if (!e.detail.value.password) {
this.data.flag = false
wx.showToast({
title: '请输入密码',
@@ -118,7 +124,7 @@ Page({
} else {
this.data.flag = true
}
if(!e.detail.value.captcha){
if (!e.detail.value.captcha) {
this.data.flag = false
wx.showToast({
title: '请输入验证码',
@@ -126,7 +132,7 @@ Page({
duration: 2000
})
return
}else{
} else {
this.data.flag = true
}
console.log('form发生了submit事件,携带数据为:', e.detail.value)
@@ -137,10 +143,10 @@ Page({
captcha: e.detail.value.captcha,
rsaPublicKey: this.data.rsaPublicKey,
}
if(this.data.flag){
if (this.data.flag) {
UserApi.passWordLogin(params).then(res => {
if(res.success){
if(res.message == '请先用手机号登录'){
if (res.success) {
if (res.message == '请先用手机号登录') {
wx.showToast({
title: '首次登录请用验证码方式登录',
icon: 'none'
@@ -149,7 +155,7 @@ Page({
wx.navigateBack()
}, 2000);
return
}else{
} else {
// 绑定微信
this.wxBindPhone()
// 存token和userInfo
@@ -161,12 +167,27 @@ Page({
key: 'userInfo',
data: res.result.userInfo
})
// 跳转首页
wx.switchTab({
url: '../home/home',
// 判断是否是微信扫描二维码签到 的登录 如果是 需要跳转到签到页面
wx.getStorage({
key: 'isSignLogin',
success(res) {
console.log(res.data)
if (res.data) {
wx.navigateTo({
url: `../scanSign/scanSign?isLoginSignIn=${res.data}`,
})
}
},
fail() {
console.log('fail');
// 跳转首页
wx.switchTab({
url: '../home/home',
})
}
})
}
}else{
} else {
wx.showToast({
title: res.message,
icon: 'none'
@@ -175,7 +196,7 @@ Page({
this.handleChangeCheckCode()
}, 2000);
}
}).catch(err=>{
}).catch(err => {
wx.showToast({
title: err.message,
icon: 'none'
@@ -185,23 +206,23 @@ Page({
},
// 绑定微信
wxBindPhone(){
wxBindPhone() {
const that = this
// 获取openid进行手机号和微信的绑定
wxBind((res)=>{
wxBind((res) => {
let params = {
openId: encrypt(that.data.rsaPublicKey, res.result.openid),
rsaPublicKey: that.data.rsaPublicKey
}
// 需要判断是否绑定过微信,再进行绑定请求
UserApi.wxBind(params).then(res=>{})
UserApi.wxBind(params).then(res => {})
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
@@ -219,14 +240,14 @@ Page({
const that = this
wx.getStorage({
key: 'rsaPublicKey',
success (res) {
success(res) {
that.setData({
rsaPublicKey: res.data
})
},
fail: function(){
fail: function () {
// 缓存中没有登录过默认app.json的登录页
}
})
}
})
})