yin_yu820 2 дней назад
Родитель
Сommit
61d874eacf
1 измененных файлов с 34 добавлено и 51 удалено
  1. 34 51
      jp-mobile/pages/user/setting/password/password.vue

+ 34 - 51
jp-mobile/pages/user/setting/password/password.vue

@@ -17,7 +17,7 @@
 				<view class="title"><text class="red-color">*</text>确认新密码</view>
 				<view class="title"><text class="red-color">*</text>确认新密码</view>
 				<input placeholder="请确认新密码" type="password" v-model="inputForm.confirmNewPassword" name="confirmNewPassword"></input>
 				<input placeholder="请确认新密码" type="password" v-model="inputForm.confirmNewPassword" name="confirmNewPassword"></input>
 			</view>
 			</view>
-			<view class="info">注意:新密码长度必须在6-16位,并且同时包含字母和数字</view>
+			<view class="info">注意:密码须同时包含大小写字母、数字及特殊字符,长度 8-20 位</view>
 			<view class="padding-xl">
 			<view class="padding-xl">
 				<button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg" >提交</button>
 				<button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg" >提交</button>
 			</view>
 			</view>
@@ -45,56 +45,39 @@
 	},
 	},
 
 
     methods:{
     methods:{
-		formSubmit: function(e) {
-		    //定义表单规则
-		    var rule = [
-		        {name:"oldPassword", checkType : "notnull", checkRule:"",  errorMsg:"密码不能为空"},
-		        {name:"newPassword", checkType : "notnull", checkRule:"",  errorMsg:"新密码不能为空"},
-		        {name:"confirmNewPassword", checkType : "notnull", checkRule:"",  errorMsg:"确认新密码不能为空"},
-				{name:"confirmNewPassword", checkType : "same", checkRule: this.inputForm.newPassword,  errorMsg:"两次输入的新密码不一致,请重新输入!"}
-		    ];
-		    //进行表单检查
-		    var formData = e.detail.value;
-		    var checkRes = graceChecker.check(formData, rule);
-			
-		    if(checkRes){
-				console.log(this.inputForm.newPassword)
-				uni.showLoading()
-				if (this.inputForm.newPassword && (this.inputForm.newPassword.length < 6 || this.inputForm.newPassword.length > 16)) {
-				  uni.showToast({
-					icon: 'none',
-					title: '密码长度为6-16位'
-				  });
-				  return;
-				} else if (!(/\d/.test(this.inputForm.newPassword) && /[a-zA-Z]/.test(this.inputForm.newPassword))) {
-				  uni.showToast({
-					icon: 'none',
-					title: '密码必须包含字母+数字'
-				  });
-				  return;
-				}
-				let which=$auth.whichLogin();
-				userService.savePwd(this.inputForm).then(({data}) => {
-					uni.showToast({title:data, icon:"success"});
-					
-					if(which=='dzf'){
-						uni.reLaunch({
-							url: '/pages/login/dzflogin'
-						});
-					}else{
-						uni.reLaunch({
-							url: '/pages/login/login'
-						});
-					}
-					
-					
-				}).catch((e)=>{
-					
-				})
-		        
-		    }else{
-		        uni.showToast({ title: graceChecker.error, icon: "none" });
-		    }
+		formSubmit: function (e) {
+		  // 原有 graceChecker 规则保留
+		  var rule = [
+		    {name:"oldPassword", checkType:"notnull", errorMsg:"密码不能为空"},
+		    {name:"newPassword", checkType:"notnull", errorMsg:"新密码不能为空"},
+		    {name:"confirmNewPassword", checkType:"notnull", errorMsg:"确认新密码不能为空"},
+		    {name:"confirmNewPassword", checkType:"same", checkRule:this.inputForm.newPassword, errorMsg:"两次输入的新密码不一致,请重新输入!"}
+		  ];
+		  var formData = e.detail.value;
+		  if(!graceChecker.check(formData, rule)){
+		    uni.showToast({title: graceChecker.error, icon:"none"});
+		    return;
+		  }
+		
+		  /* ========== 新规则校验 ========== */
+		  const pwd = this.inputForm.newPassword;
+		  if(pwd.length<8 || pwd.length>20){
+		    uni.showToast({icon:'none',title:'密码长度为 8-20 位'});
+		    return;
+		  }
+		  // 必须同时包含:大写、小写、数字、特殊字符
+		  if(!/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9])/.test(pwd)){
+		    uni.showToast({icon:'none',title:'密码须同时包含大小写字母、数字及特殊字符'});
+		    return;
+		  }
+		
+		  /* ========== 提交后台 ========== */
+		  uni.showLoading();
+		  userService.savePwd(this.inputForm).then(({data})=>{
+		    uni.showToast({title:data, icon:"success"});
+		    const which = $auth.whichLogin();
+		    uni.reLaunch({url: which=='dzf' ? '/pages/login/dzflogin' : '/pages/login/login'});
+		  }).catch(()=>{});
 		}
 		}
     }
     }
   }
   }