Explorar o código

feat:pc扫码登录小程序

xuqiaoying %!s(int64=3) %!d(string=hai) anos
pai
achega
edb352a270

+ 1 - 0
.gitignore

@@ -8,6 +8,7 @@ yarn-error.log*
 /test/unit/coverage/
 /test/e2e/reports/
 selenium-debug.log
+project.private.config.json
 
 # Editor directories and files
 .idea

+ 8 - 0
common/httpList/login.js

@@ -155,5 +155,13 @@ export default {
 			method: 'post',
 			data: data
 		})
+	},
+	// 小程序校验PC登录二维码
+	scanLoginCheck(data) {
+		return myRequest({
+			url: '/scan_login_check',
+			method: 'post',
+			data: data
+		})
 	}
 }

+ 13 - 0
pages.json

@@ -819,6 +819,19 @@
 					"bounce": "none"
 				}
 			}
+		},
+        {
+			"path": "login/pcLoginSuccess",
+			"style": {
+				"navigationBarTitleText": "登录成功",
+				"navigationBarBackgroundColor": "#0386FD",
+				"navigationBarTextStyle": "white",
+				"navigationStyle": "custom", // 隐藏系统导航栏
+				"app-plus": {
+					"titleNView": false, //禁用原生导航栏 
+					"bounce": "none"
+				}
+			}
 		}
     ]
 			

+ 22 - 5
pages2/register/bind.vue

@@ -26,7 +26,8 @@ export default {
 				idCard:''
 			},
 			codeTips: '',
-			read:''
+			read:'',
+			scanCode: '', // 获取扫码的路径最后面的6位标识码
 		};
 	},
 	mounted() {},
@@ -56,6 +57,7 @@ export default {
 			this.$set(this.form,'realname',this.form.realname.trim()) //去除姓名两头空格
 			
 			that.isUse = true
+			// 绑定身份证号信息 /app/user/bind_idcard
 			that.$api.bindId(this.form).then(
 				res => {
 					that.isUse = false
@@ -64,9 +66,22 @@ export default {
 						uni.setStorageSync('token',uni.getStorageSync('token_temp'));
 						uni.removeStorageSync('user_account_temp') //移除临时账号
 						uni.removeStorageSync('token_temp') //移除临时token
-						uni.reLaunch({
-							url:'/pages/index/index'
-						})
+						if (this.scanCode) { // pc扫码注册成功后提交/跳转
+							this.$api.scanLoginCheck({
+								scanCode: this.scanCode
+							}).then((res) => {
+								if (res.data.code == 200) {
+									uni.navigateTo({
+										url: '/pages4/login/pcLoginSuccess'
+									})
+								}
+							})
+						} else { // 跳转到首页是原来的逻辑
+							uni.reLaunch({
+								url:'/pages/index/index'
+							})
+						}
+						
 						this.$method.setUuid(new Date().valueOf() + "")
 						that.$api.getInfo().then(resdata => {
 							if(resdata.data.code == 200){
@@ -173,8 +188,10 @@ export default {
 		}
 	},
 	onLoad(option) {
+		console.log('注册:', option.scanCode)
 		let that = this;
-		this.from = option.from;
+		option.scanCode && (this.scanCode = option.scanCode)
+		// this.from = option.from; // this.from 看了页面没有用到,注释了
 		uni.removeStorageSync('user_account') //移除临时账号
 		uni.removeStorageSync('token')
 		uni.login({

+ 1 - 1
pages2/register/forget.vue

@@ -238,7 +238,7 @@ export default {
 	onLoad(option) {
 		this.$refs.uForm.setRules(this.rules)
 		let that = this;
-		this.from = option.from;
+		// this.from = option.from; // 看页面没有用到
 		uni.login({
 			provider: 'weixin',
 			success: function(loginRes) {

+ 24 - 4
pages2/register/register.vue

@@ -354,7 +354,8 @@ export default {
 					}
 				],
 			},
-			isUse:false
+			isUse:false,
+			scanCode: '', // 标识码
 		};
 	},
 	mounted() {},
@@ -429,7 +430,9 @@ export default {
 													that.$api.getInfo().then(resdata => {
 														if(resdata.data.code == 200){
 															that.$store.state.userInfo = resdata.data.data;
-															if(!that.isBack){
+															if (this.scanCode) { // pc扫码进来登录成功
+																this.submitCode()
+															} else if(!that.isBack){
 																uni.reLaunch({
 																	url:'/pages/index/index'
 																})
@@ -444,8 +447,9 @@ export default {
 													//未完善信息,存为临时信息
 													uni.setStorageSync('user_account_temp', res.data.data.user_account);
 													uni.setStorageSync('token_temp', res.data.data.token);
+													let url = this.scanCode ? '/pages2/register/bind?scanCode=' + this.scanCode : '/pages2/register/bind'
 													uni.redirectTo({
-														url:'/pages2/register/bind'
+														url: url
 													})
 												}	
 											} else {
@@ -467,6 +471,19 @@ export default {
 			})
 			
 		},
+		// scanLoginCheck小程序校验PC登录二维码,执行登录获取到令牌,然后把扫码的路径最后面的6位标识码提交给后台就行
+		submitCode() {
+			console.log('注册:跳转请求提交code到接口', this.scanCode)
+			this.$api.scanLoginCheck({
+				scanCode: this.scanCode
+			}).then((res) => {
+				if (res.data.code == 200) {
+					uni.navigateTo({
+						url: '/pages4/login/pcLoginSuccess'
+					})
+				}
+			})
+		},
 		radioGroupChange(e) {
 			 console.log(e);
 		},
@@ -562,9 +579,12 @@ export default {
 		}
 	},
 	onLoad(option) {
+		console.log(option)
 		let that = this;
 		this.$refs.uForm.setRules(this.rules)
-		this.from = option.from;
+		option.scanCode && (this.scanCode = option.scanCode)
+		console.log('跳转注册时的scanCode', this.scanCode)
+		// this.from = option.from; // 看了页面没有用到,注释了
 		uni.login({
 			provider: 'weixin',
 			success: function(loginRes) {

+ 194 - 94
pages4/login/login.vue

@@ -19,7 +19,7 @@
 					</u-form-item>
 				</u-form>
 			</view>
-			<button class="loginBtn" :class="{able:canLogin()}" @click="login" v-if="current==0"> 
+			<button class="loginBtn" :class="{able:canLogin()}" @click="pwlogin" v-if="current==0"> 
 				登录
 			</button>
 			<button :disabled="isUse" :class="{able:canLogin()}" class="loginBtn" @click="sms_login" v-if="current==1">
@@ -27,7 +27,7 @@
 			</button>
 			<view style="width: 100%;margin: 40rpx auto;">
 				<view  style="display: flex;align-items: center;color: #007AFF;font-size: 24rpx;justify-content:center;">
-					<navigator  hover-class="none" url="/pages2/register/register" style="margin: 0 40rpx;">立即注册</navigator>
+					<navigator  hover-class="none" :url="'/pages2/register/register?scanCode=' + scanCode" style="margin: 0 40rpx;">立即注册</navigator>
 					<view style="width: 3rpx;height: 20rpx;background-color: #007AFF;"></view>
 					<navigator  hover-class="none" url="/pages2/register/forget" style="margin: 0 40rpx;">忘记密码</navigator>
 				</view>
@@ -115,14 +115,18 @@ export default {
 			current: 0,
 			codeTips: '',
 			isUse:false,
+			scanCode: '', // pc端扫码登录获取的标志码
 			isBack:false
 		};
 	},
 	onLoad(option) {
+		console.log('dsfs-----:', option)
 		this.$refs.uForm1.setRules(this.rules)
 		this.$refs.uForm2.setRules(this.rules)
 		if(option.isBack){
 			this.isBack = option.isBack;
+		} else if (option.scanCode) {
+			this.scanCode = option.scanCode
 		}
 		let that = this;
 		// this.from = option.from; 
@@ -144,47 +148,56 @@ export default {
 				encryptedData: e.detail.encryptedData,
 				iv:  e.detail.iv
 			}).then(res => {
-				if(res.data.data.full_info){
-					//信息完善,直接进入页面
-					uni.setStorageSync('user_account', res.data.data.user_account);
-					uni.setStorageSync('token', res.data.data.token);
-					this.$api.getInfo().then(resdata => {
-						if(resdata.data.code == 200){
-							this.$store.state.userInfo = resdata.data.data;
+				this.loginCallback(res, 'wxlogin')
+				// if(res.data.data.full_info){
+				// 	//信息完善,直接进入页面
+				// 	uni.setStorageSync('user_account', res.data.data.user_account);
+				// 	uni.setStorageSync('token', res.data.data.token);
+				// 	// /app/user/getInfo 登录用户信息
+				// 	this.$api.getInfo().then(resdata => {
+				// 		if(resdata.data.code == 200){
+				// 			this.$store.state.userInfo = resdata.data.data;
 							
-							if(!this.isBack){
-								let goPath = uni.getStorageSync('goPath')
+				// 			if (this.scanCode) { // pc扫码进来登录成功
+				// 				this.submitCode()
+				// 			} else if(!this.isBack){
+				// 				let goPath = uni.getStorageSync('goPath')
 								
-								if(goPath == 'course') {
-									uni.redirectTo({
-										url:'/pages2/wd/class'
-									})
-									this.$method.setUuid(new Date().valueOf() + "")
-								} else if(goPath == 'bank') {
-									uni.redirectTo({
-										url:'/pages2/wd/question_bank'
-									})
-									this.$method.setUuid(new Date().valueOf() + "")
-								} else {
-									uni.reLaunch({
-										url:'/pages/index/index'
-									})
+				// 				if(goPath == 'course') {
+				// 					uni.redirectTo({
+				// 						url:'/pages2/wd/class'
+				// 					})
+				// 					this.$method.setUuid(new Date().valueOf() + "")
+				// 				} else if(goPath == 'bank') {
+				// 					uni.redirectTo({
+				// 						url:'/pages2/wd/question_bank'
+				// 					})
+				// 					this.$method.setUuid(new Date().valueOf() + "")
+				// 				} else {
+				// 					uni.reLaunch({
+				// 						url:'/pages/index/index'
+				// 					})
 									
-									this.$method.setUuid(new Date().valueOf() + "")
-								}
-							}else{
-								uni.navigateBack();
-							}
-						}
+				// 					this.$method.setUuid(new Date().valueOf() + "")
+				// 				}
+				// 			}else{
+				// 				uni.navigateBack();
+				// 			}
+				// 		}
 						
-					});
+				// 	});
 					
-				}else{
-					//未完善信息,存为临时信息
-					uni.setStorageSync('user_account_temp', res.data.data.user_account);
-					uni.setStorageSync('token_temp', res.data.data.token);
-					this.$navTo.togo('/pages2/register/bind');
-				}	
+				// }else{
+				// 	//未完善信息,存为临时信息
+				// 	uni.setStorageSync('user_account_temp', res.data.data.user_account);
+				// 	uni.setStorageSync('token_temp', res.data.data.token);
+				// 	if (this.scanCode) {
+				// 		this.$navTo.togo('/pages2/register/bind', this.scanCode)
+				// 	} else {
+				// 		this.$navTo.togo('/pages2/register/bind');
+				// 	}
+					
+				// }	
 				
 			})
 		},
@@ -222,43 +235,50 @@ export default {
 						res => {
 							that.isUse = false
 							if (res.data.code == 200) {
-								if(res.data.data.full_info){
-									//信息完善,直接进入页面
-									uni.setStorageSync('user_account', res.data.data.user_account);
-									uni.setStorageSync('token', res.data.data.token);
-									that.$api.getInfo().then(resdata => {
-										if(resdata.data.code == 200){
-											that.$store.state.userInfo = resdata.data.data;
+								this.loginCallback(res, 'smslogin')
+								// if(res.data.data.full_info){
+								// 	//信息完善,直接进入页面
+								// 	uni.setStorageSync('user_account', res.data.data.user_account);
+								// 	uni.setStorageSync('token', res.data.data.token);
+								// 	that.$api.getInfo().then(resdata => {
+								// 		if(resdata.data.code == 200){
+								// 			that.$store.state.userInfo = resdata.data.data;
 											
-											if(!that.isBack){
-												let goPath = uni.getStorageSync('goPath')
+								// 			if (this.scanCode) { // pc扫码进来登录成功
+								// 				this.submitCode()
+								// 			} else if(!that.isBack){
+								// 				let goPath = uni.getStorageSync('goPath')
 												
-												if(goPath == 'course') {
-													uni.redirectTo({
-														url:'/pages2/wd/class'
-													})
-												} else if(goPath == 'bank') {
-													uni.redirectTo({
-														url:'/pages2/wd/question_bank'
-													})
-												} else {
-													uni.reLaunch({
-														url:'/pages/index/index'
-													})
-												}
-											}else{
-												uni.navigateBack();
-											}
-										}
+								// 				if(goPath == 'course') {
+								// 					uni.redirectTo({
+								// 						url:'/pages2/wd/class'
+								// 					})
+								// 				} else if(goPath == 'bank') {
+								// 					uni.redirectTo({
+								// 						url:'/pages2/wd/question_bank'
+								// 					})
+								// 				} else {
+								// 					uni.reLaunch({
+								// 						url:'/pages/index/index'
+								// 					})
+								// 				}
+								// 			}else{
+								// 				uni.navigateBack();
+								// 			}
+								// 		}
 										
-									});
+								// 	});
 									
-								}else{
-									//未完善信息,存为临时信息
-									uni.setStorageSync('user_account_temp', res.data.data.user_account);
-									uni.setStorageSync('token_temp', res.data.data.token);
-									that.$navTo.togo('/pages2/register/bind');
-								}	
+								// }else{
+								// 	//未完善信息,存为临时信息
+								// 	uni.setStorageSync('user_account_temp', res.data.data.user_account);
+								// 	uni.setStorageSync('token_temp', res.data.data.token);
+								// 	if (this.scanCode) {
+								// 		this.$navTo.togo('/pages2/register/bind', this.scanCode)
+								// 	} else {
+								// 		this.$navTo.togo('/pages2/register/bind');
+								// 	}
+								// }	
 							} else {
 								that.$u.toast(res.data.msg);
 							}
@@ -290,7 +310,7 @@ export default {
 		
 				return encrypt.encrypt(data);
 		},
-		login(){
+		pwlogin(){
 			let that = this
 			if(!this.form.account){
 				this.$u.toast('请输入手机号码/身份证号');
@@ -306,33 +326,42 @@ export default {
 			that.isUse = true
 			let form = JSON.parse(JSON.stringify(this.form))
 			form.pwd = this.encryptor(form.pwd)
+			// 账号登录用户 /app/common/account_login
 			that.$api.accountLogin(form).then(
 				res => {
 					that.isUse = false
 					if (res.data.code == 200) {
-						if(res.data.data.full_info){
-							//信息完善,直接进入页面
-							uni.setStorageSync('user_account', res.data.data.user_account);
-							uni.setStorageSync('token', res.data.data.token);
-							that.$api.getInfo().then(resdata => {
-								if(resdata.data.code == 200){
-									that.$store.state.userInfo = resdata.data.data;
-									if(!that.isBack){
-										uni.reLaunch({
-											url:'/pages/index/index'
-										})
-									}else{
-										uni.navigateBack();
-									}
-								}
+						this.loginCallback(res, 'pwlogin')
+						// if(res.data.data.full_info){
+						// 	//信息完善,直接进入页面
+						// 	uni.setStorageSync('user_account', res.data.data.user_account);
+						// 	uni.setStorageSync('token', res.data.data.token);
+						// 	that.$api.getInfo().then(resdata => {
+						// 		if(resdata.data.code == 200){
+						// 			that.$store.state.userInfo = resdata.data.data;
+						// 			if (this.scanCode) { // pc扫码进来登录成功
+						// 				this.submitCode()
+						// 			} else if(!that.isBack){
+						// 				uni.reLaunch({
+						// 					url:'/pages/index/index'
+						// 				})
+						// 			}else{
+						// 				uni.navigateBack();
+						// 			}
+						// 		}
 								
-							});
-						}else{
-							//未完善信息,存为临时信息
-							uni.setStorageSync('user_account_temp', res.data.data.user_account);
-							uni.setStorageSync('token_temp', res.data.data.token);
-							that.$navTo.togo('/pages2/register/bind');
-						}	
+						// 	});
+						// }else{
+						// 	//未完善信息,存为临时信息
+						// 	uni.setStorageSync('user_account_temp', res.data.data.user_account);
+						// 	uni.setStorageSync('token_temp', res.data.data.token);
+						// 	// that.$navTo.togo('/pages2/register/bind');
+						// 	if (this.scanCode) {
+						// 		this.$navTo.togo('/pages2/register/bind', this.scanCode)
+						// 	} else {
+						// 		this.$navTo.togo('/pages2/register/bind');
+						// 	}
+						// }	
 					} else {
 						that.$u.toast(res.data.msg);
 					}
@@ -432,6 +461,77 @@ export default {
 					}
 				);
 			}
+		},
+		// 微信、密码、验证码 登录成功的回调
+		loginCallback(res, types) {
+			console.log('登录后的回调',res)
+			if(res.data.data.full_info){
+				//信息完善,直接进入页面
+				uni.setStorageSync('user_account', res.data.data.user_account);
+				uni.setStorageSync('token', res.data.data.token);
+				// /app/user/getInfo 登录用户信息
+				this.$api.getInfo().then(resdata => {
+					if(resdata.data.code == 200){
+						this.$store.state.userInfo = resdata.data.data;
+						
+						if (this.scanCode) { // pc扫码进来登录成功
+							this.submitCode()
+						} else if(!this.isBack){
+							let goPath = ''
+							if (types == 'wxlogin' || types == 'smslogin') { //密码登录不用判断电脑goPath, 直接到首页
+								goPath = uni.getStorageSync('goPath')
+							}
+							if(goPath == 'course') {
+								console.log('course')
+								uni.redirectTo({
+									url:'/pages2/wd/class'
+								})
+								types == 'wxlogin' && this.$method.setUuid(new Date().valueOf() + "")
+							} else if(goPath == 'bank') {
+								console.log('bank')
+								uni.redirectTo({
+									url:'/pages2/wd/question_bank'
+								})
+								types == 'wxlogin' && this.$method.setUuid(new Date().valueOf() + "")
+							} else {
+								console.log('密码登录不用判断电脑goPath, 直接到首页')
+								uni.reLaunch({
+									url:'/pages/index/index'
+								})
+								types == 'wxlogin' && this.$method.setUuid(new Date().valueOf() + "")
+							}
+							
+						}else{
+							console.log('直接返回')
+							uni.navigateBack();
+						}
+					}
+					
+				});
+			} else {
+				//未完善信息,存为临时信息
+				uni.setStorageSync('user_account_temp', res.data.data.user_account);
+				uni.setStorageSync('token_temp', res.data.data.token);
+				if (this.scanCode) {
+					this.$navTo.togo('/pages2/register/bind', this.scanCode)
+				} else {
+					this.$navTo.togo('/pages2/register/bind');
+				}
+				
+			}	
+		},
+		// scanLoginCheck小程序校验PC登录二维码,执行登录获取到令牌,然后把扫码的路径最后面的6位标识码提交给后台就行
+		submitCode() {
+			console.log('跳转请求提交code到接口', this.scanCode)
+			this.$api.scanLoginCheck({
+				scanCode: this.scanCode
+			}).then((res) => {
+				if (res.data.code == 200) {
+					uni.navigateTo({
+						url: '/pages4/login/pcLoginSuccess'
+					})
+				}
+			})
 		}
 	}
 

+ 41 - 11
pages4/login/pcLogin.vue

@@ -1,11 +1,17 @@
 <template>
-    <view>
-        pc端扫码登录
-        <view>sfdogh县第十四个丰厚的</view>
-        <view>sfdogh县第十四个丰厚的</view>
-        <view>sfdogh县第十四个丰厚的</view>
-        <view>sfdogh县第十四个丰厚的</view>
-        <view>sfdogh县第十四个丰厚的</view>
+    <view class="pcLogins">
+        <u-navbar :is-back="false" title="登录" :border-bottom="false"  title-color="#333333" back-icon-color="#ffffff">
+            <view class="slot-wrap">
+                <image  src="/static/logo2.png" style="width: 178rpx;height: 31rpx;margin-left: 30rpx;"></image>
+            </view>
+        </u-navbar>
+        <u-line color="#D6D6DB" />
+        <view class="contents">
+            <!-- 正文内容 -->
+            <text>登录后您可在网页端继续浏览课程</text>
+            <view class="login_bt" @click="pcLogin()">微信登录</view>
+        </view>
+        
     </view>
 </template>
 
@@ -13,14 +19,38 @@
 export default {
     data() {
         return {
-
+            scanCode: '', // 获取扫码的路径最后面的6位标识码
         }
     },
     onLoad(query) {
         console.log('扫描参数', query)
         const q = decodeURIComponent(query.q)
-        const time = parseInt(query.scancode_time)
-        console.log('扫描后得:', q, time)
+        this.scanCode = q.substring(q.length - 6)
+        // const time = parseInt(query.scancode_time)
+        console.log('扫描后得:', q, this.scanCode)
 	},
+    methods: {
+        pcLogin() {
+            console.log('跳转')
+            uni.navigateTo({
+                url: '/pages4/login/login?scanCode=' + this.scanCode
+            });
+        },
+    }
+}
+</script>
+
+<style lang="scss" scoped>
+.contents {
+    width: 100%;
+    height: 100%;
+    text-align: center;
+    .login_bt {
+        width: 180rpx;
+        height: 80rpx;
+        line-height: 80rpx;
+        text-align: center;
+        background: #ddd;
+    }
 }
-</script>
+</style>

+ 31 - 0
pages4/login/pcLoginSuccess.vue

@@ -0,0 +1,31 @@
+<template>
+    <view class="pcLogins">
+        <u-navbar :is-back="false" title="登录成功" :border-bottom="false"  title-color="#333333" back-icon-color="#ffffff">
+            <view class="slot-wrap">
+                <image  src="/static/logo2.png" style="width: 178rpx;height: 31rpx;margin-left: 30rpx;"></image>
+            </view>
+        </u-navbar>
+        <u-line color="#D6D6DB" />
+        <view class="contents">
+            <!-- 正文内容 -->
+            <text>登录成功,你可以在电脑端学习了</text>
+            <view class="login_bt" @click="toHome()">首页</view>
+            <view>手机学习,充分利用一分一秒</view>
+            <view>手机刷题,随时随地提升分数</view>
+        </view>
+        
+    </view>
+</template>
+
+<script>
+export default {
+    name: 'pcLoginSuccess',
+    methods: {
+        toHome() {
+            uni.switchTab({
+                url: '/pages/index/index'
+            })
+        }
+    }
+}
+</script>