From 18f57480d27631d022cee275b4a4e193d39955cd Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Mon, 03 Nov 2025 10:55:52 +0800
Subject: [PATCH] feat:密码校验

---
 src/subPackages/userDetail/password/index.vue |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/subPackages/userDetail/password/index.vue b/src/subPackages/userDetail/password/index.vue
index cb72c4b..2f9543e 100644
--- a/src/subPackages/userDetail/password/index.vue
+++ b/src/subPackages/userDetail/password/index.vue
@@ -49,6 +49,39 @@
 		newPassword: '',
 		newPassword1: '',
 	});
+	// 校验密码不能包含中文
+	const validatePasswordNoChinese = (password) => {
+	  const chineseRegex = /[\u4e00-\u9fa5]/;
+	  if (chineseRegex.test(password)) {
+	  
+		uni.showToast({
+			title: '密码不能包含中文字符',
+			icon: 'none',
+			duration: 2000
+		});
+	    return false;
+	  }
+	  return true;
+	};
+	// 校验密码复杂度(长度≥6位,包含字母和数字)
+	const validatePasswordStrength = (password) => {
+	  if (password.length < 6) {
+	 
+		uni.showToast({
+			title: '密码长度不能少于6位',
+			icon: 'none',
+			duration: 2000
+		});
+	    return false;
+	  }
+	  // const hasLetter = /[a-zA-Z]/.test(password);
+	  // const hasNumber = /\d/.test(password);
+	  // if (!hasLetter || !hasNumber) {
+	  //   ElMessage.error('密码需同时包含字母和数字');
+	  //   return false;
+	  // }
+	  return true;
+	};
 	const clearForm = () => {
 		passwordForm.value = {
 			oldPassword: '',
@@ -60,7 +93,41 @@
 		clearForm();
 	};
 	const submit = () => {
+// 原始密码校验
+    if (!passwordForm.value.oldPassword) {
+   
+	  uni.showToast({
+	  	title: '请输入原始密码',
+	  	icon: 'none',
+	  	duration: 2000
+	  });
+      return;
+    }
+     // 中文校验
+    if (!validatePasswordNoChinese(passwordForm.value.newPassword)) return;
+    // 新密码校验
+    if (!passwordForm.value.newPassword) {
+ 
+	  uni.showToast({
+	  	title: '请输入新密码',
+	  	icon: 'none',
+	  	duration: 2000
+	  });
+      return;
+    }
+    // 确认密码校验
+    if (passwordForm.value.newPassword !== passwordForm.value.newPassword1) {
 
+	  uni.showToast({
+	  	title: '两次输入的新密码不一致',
+	  	icon: 'none',
+	  	duration: 2000
+	  });
+      return;
+    }
+   
+    // 复杂度校验
+    if (!validatePasswordStrength(passwordForm.value.newPassword)) return;
 		updatePassword(md5(passwordForm.value.oldPassword),
 			md5(passwordForm.value.newPassword),
 			md5(passwordForm.value.newPassword1)).then(res => {

--
Gitblit v1.9.3