| | |
| | | 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: '', |
| | |
| | | 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 => { |