Эх сурвалжийг харах

登录、注册、忘记密码如果缓存中有重定向的url,就跳转到重定向的url,如果没有就跳到首页

littleblue55 1 өдөр өмнө
parent
commit
ce74f7de03

+ 1 - 1
pages/forget/forget.vue

@@ -111,7 +111,7 @@
 								msgSuccess("重置成功!");
 								setTimeout(()=>{
 									uni.reLaunch({
-										url: "/pages/initial/initial",
+										url: "/pages/login/login",
 									})
 								}, 1000)
 							}

+ 4 - 2
pages/login/login.vue

@@ -509,9 +509,11 @@
 				that.canIUseGetUserProfile = true
 			}
 			if(option.redirect){
-				console.log("重定向", JSON.parse(option.redirect))
+				// console.log("重定向", JSON.parse(option.redirect))
 				uni.setStorageSync("redirect", JSON.parse(option.redirect))
-				this.redirect = JSON.parse(option.redirect)
+			}
+			if(uni.getStorageSync("redirect")){
+				this.redirect = uni.getStorageSync("redirect")
 			}
 		}
 	}

+ 52 - 7
pages/register/register.vue

@@ -51,11 +51,15 @@
 		encryptAESCBC
 	} from "@/utils/crypto.js"
 	import {
-		register
+		register,
+		wxLoginOpenid
 	} from "@/api/login.js"
 	import {
 		useAuthStore
 	} from '@/store/authStore.js'
+	import {
+		me
+	} from '@/api/user.js'
 	export default {
 		data() {
 			return {
@@ -122,7 +126,8 @@
 						message: '请选择性别',
 						trigger: ['change']
 					}]
-				}
+				},
+				redirect: null,
 			};
 		},
 		methods: {
@@ -149,15 +154,51 @@
 								zhangHao
 							})
 							msgSuccess("注册成功");
-							setTimeout(() => {
-								uni.switchTab({
-									url: "/pages/index/index"
-								})
-							}, 1000)
+							this.initUser()
+							// setTimeout(() => {
+							// 	if(this.redirect){
+							// 		uni.removeStorageSync("redirect")
+							// 		uni.reLaunch({
+							// 			url: this.redirect.url+'?id='+this.redirect.id+'&title='+this.redirect.title
+							// 		})
+							// 	}else{
+							// 		uni.switchTab({
+							// 			url: "/pages/index/index"
+							// 		})
+							// 	}
+								
+							// }, 1000)
 						}
 					})
 				})
 			},
+			async initUser(){
+				const loginRes = await wx.login();
+				const code = loginRes.code;
+				let userRes = await me();
+				let wxRes = await wxLoginOpenid({code})
+				// 加载用户信息
+				if(userRes && userRes?.code===0){
+					this.useAuthStore.setUserInfo(userRes.data)
+				}
+				// 加载openid
+				if(wxRes && wxRes?.data){
+					const { openid, sessionKey } = wxRes.data
+					this.useAuthStore.setOpenid(openid)
+				}
+				setTimeout(() => {
+					if(this.redirect){
+						uni.removeStorageSync("redirect")
+						uni.reLaunch({
+							url: this.redirect.url+'?id='+this.redirect.id+'&title='+this.redirect.title
+						})
+					}else{
+						uni.switchTab({
+							url: "/pages/index/index"
+						})
+					}
+				}, 1000)
+			},
 			// 提示
 			showToast(msg, type) {
 				uni.showToast({
@@ -189,6 +230,10 @@
 				})
 				this.mode = 'register'
 			}
+			if(uni.getStorageSync("redirect")){
+				this.redirect = uni.getStorageSync("redirect")
+			}
+			console.log(this.redirect,"重定")
 		},
 		onReady() {
 			this.$refs.registerForm.setRules(this.rules);