浏览代码

feat:登录注册防止多次点击

zhanghui 2 年之前
父节点
当前提交
33d507a492
共有 2 个文件被更改,包括 32 次插入1 次删除
  1. 17 1
      pages/login/login.vue
  2. 15 0
      pages/register/register.vue

+ 17 - 1
pages/login/login.vue

@@ -58,6 +58,7 @@
 	export default {
 		data() {
 			return {
+				requestStatus:false,
 				savePassword:false,
 				form: {
 					username: '',
@@ -109,6 +110,11 @@
 			},
 
 			login() {
+
+				if (this.requestStatus){
+					return
+				}
+				this.requestStatus=true
 				this.$refs.uForm.validate().then(res => {
 					if (this.savePassword){
 						uni.setStorageSync('savePassword', this.savePassword)
@@ -120,9 +126,16 @@
 						uni.removeStorageSync('password');
 					}
 
+					uni.showLoading({
+						title: '登录中...'
+					});
+
 					this.$api.login.expandLogin(this.form).then(res => {
+						uni.hideLoading();
+						this.requestStatus=false
 						uni.setStorageSync('accessToken', res.data.data.access_token)
 						this.$api.user.getUserInfo().then(res=>{
+
 							this.userInfo = res.data.data
 							uni.setStorageSync('spreadUserInfo', this.userInfo)
 							uni.showToast({
@@ -136,8 +149,11 @@
 								})
 							},1000)
 						})
-
+					}).catch(err=>{
+						this.requestStatus=false
 					})
+				}).catch(err=>{
+					this.requestStatus=false
 				})
 			}
 		}

+ 15 - 0
pages/register/register.vue

@@ -67,6 +67,7 @@
 	export default {
 		data() {
 			return {
+				requestStatus:false,
 				disabled1:false,
 				showBirthday:false,
 				showSex:false,
@@ -218,8 +219,18 @@
 			},
 			expandRegister(){
 				console.log(this.form)
+				if (this.requestStatus){
+					return
+				}
+				this.requestStatus=true
 				this.$refs.uForm.validate().then(res => {
+					uni.showLoading({
+						title: '正在注册...'
+					});
+
 					this.$api.login.expandRegister(this.form).then(res=>{
+						uni.hideLoading();
+						this.requestStatus=false
 						uni.showToast({
 							icon: 'success',
 							duration: 2000,
@@ -229,7 +240,11 @@
 							this.gologin()
 						},2000)
 
+					}).catch(err=>{
+						this.requestStatus=false
 					})
+				}).catch(err=>{
+					this.requestStatus=false
 				})
 			},
 			logout(){