fix(登录): 将登录页面的邮箱字段替换为手机号字段
fix(忘记密码): 增加手机号验证逻辑和输入限制 fix(注册): 优化手机号验证逻辑并增加密码最小长度限制 本次提交主要修复了以下问题: 1. 登录页面将邮箱字段替换为手机号字段,以适配新的登录方式。 2. 忘记密码页面增加了手机号验证逻辑,确保输入格式正确,并限制了输入长度。 3. 注册页面优化了手机号验证逻辑,并增加了密码的最小长度限制,提升安全性。
Showing
3 changed files
with
32 additions
and
9 deletions
| ... | @@ -22,6 +22,9 @@ | ... | @@ -22,6 +22,9 @@ |
| 22 | type="tel" | 22 | type="tel" |
| 23 | required | 23 | required |
| 24 | pattern="^1[3-9]\d{9}$" | 24 | pattern="^1[3-9]\d{9}$" |
| 25 | + maxlength="11" | ||
| 26 | + @input="formData.phone = formData.phone.replace(/\D/g, '')" | ||
| 27 | + @blur="validatePhone" | ||
| 25 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" | 28 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" |
| 26 | /> | 29 | /> |
| 27 | </div> | 30 | </div> |
| ... | @@ -41,7 +44,7 @@ | ... | @@ -41,7 +44,7 @@ |
| 41 | /> | 44 | /> |
| 42 | <button | 45 | <button |
| 43 | type="button" | 46 | type="button" |
| 44 | - :disabled="countdown > 0" | 47 | + :disabled="countdown > 0 || !isPhoneValid" |
| 45 | @click="sendVerificationCode" | 48 | @click="sendVerificationCode" |
| 46 | class="mt-1 px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap" | 49 | class="mt-1 px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap" |
| 47 | > | 50 | > |
| ... | @@ -112,6 +115,7 @@ const router = useRouter() | ... | @@ -112,6 +115,7 @@ const router = useRouter() |
| 112 | const error = ref('') | 115 | const error = ref('') |
| 113 | const loading = ref(false) | 116 | const loading = ref(false) |
| 114 | const countdown = ref(0) | 117 | const countdown = ref(0) |
| 118 | +const isPhoneValid = ref(false) | ||
| 115 | 119 | ||
| 116 | const formData = reactive({ | 120 | const formData = reactive({ |
| 117 | phone: '', | 121 | phone: '', |
| ... | @@ -130,9 +134,25 @@ const startCountdown = () => { | ... | @@ -130,9 +134,25 @@ const startCountdown = () => { |
| 130 | }, 1000) | 134 | }, 1000) |
| 131 | } | 135 | } |
| 132 | 136 | ||
| 133 | -const sendVerificationCode = async () => { | 137 | +const validatePhone = () => { |
| 138 | + if (!formData.phone) { | ||
| 139 | + error.value = '请输入手机号' | ||
| 140 | + isPhoneValid.value = false | ||
| 141 | + return | ||
| 142 | + } | ||
| 143 | + | ||
| 134 | if (!/^1[3-9]\d{9}$/.test(formData.phone)) { | 144 | if (!/^1[3-9]\d{9}$/.test(formData.phone)) { |
| 135 | error.value = '请输入正确的手机号' | 145 | error.value = '请输入正确的手机号' |
| 146 | + isPhoneValid.value = false | ||
| 147 | + return | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + error.value = '' | ||
| 151 | + isPhoneValid.value = true | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +const sendVerificationCode = async () => { | ||
| 155 | + if (!isPhoneValid.value) { | ||
| 136 | return | 156 | return |
| 137 | } | 157 | } |
| 138 | 158 | ... | ... |
| ... | @@ -176,7 +176,7 @@ const handleSubmit = async () => { | ... | @@ -176,7 +176,7 @@ const handleSubmit = async () => { |
| 176 | const mockUserData = { | 176 | const mockUserData = { |
| 177 | id: 1, | 177 | id: 1, |
| 178 | name: '测试用户', | 178 | name: '测试用户', |
| 179 | - email: email.value, | 179 | + mobile: mobile.value, |
| 180 | avatar: 'https://cdn.ipadbiz.cn/mlaj/images/user-avatar-2.jpg', | 180 | avatar: 'https://cdn.ipadbiz.cn/mlaj/images/user-avatar-2.jpg', |
| 181 | checkInDays: 3, | 181 | checkInDays: 3, |
| 182 | completedCourses: 12 | 182 | completedCourses: 12 | ... | ... |
| ... | @@ -36,11 +36,11 @@ | ... | @@ -36,11 +36,11 @@ |
| 36 | type="tel" | 36 | type="tel" |
| 37 | required | 37 | required |
| 38 | pattern="^1[3-9]\d{9}$" | 38 | pattern="^1[3-9]\d{9}$" |
| 39 | + maxlength="11" | ||
| 40 | + @input="formData.phone = formData.phone.replace(/\D/g, '')" | ||
| 39 | @blur="validatePhone" | 41 | @blur="validatePhone" |
| 40 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" | 42 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" |
| 41 | - :class="{ 'border-red-300': phoneError }" | ||
| 42 | /> | 43 | /> |
| 43 | - <p v-if="phoneError" class="mt-1 text-sm text-red-600">{{ phoneError }}</p> | ||
| 44 | </div> | 44 | </div> |
| 45 | 45 | ||
| 46 | <div> | 46 | <div> |
| ... | @@ -77,6 +77,7 @@ | ... | @@ -77,6 +77,7 @@ |
| 77 | type="password" | 77 | type="password" |
| 78 | autocomplete="new-password" | 78 | autocomplete="new-password" |
| 79 | required | 79 | required |
| 80 | + minlength="6" | ||
| 80 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" | 81 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" |
| 81 | /> | 82 | /> |
| 82 | </div> | 83 | </div> |
| ... | @@ -91,6 +92,7 @@ | ... | @@ -91,6 +92,7 @@ |
| 91 | type="password" | 92 | type="password" |
| 92 | autocomplete="new-password" | 93 | autocomplete="new-password" |
| 93 | required | 94 | required |
| 95 | + minlength="6" | ||
| 94 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" | 96 | class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" |
| 95 | /> | 97 | /> |
| 96 | </div> | 98 | </div> |
| ... | @@ -211,23 +213,24 @@ const startCountdown = () => { | ... | @@ -211,23 +213,24 @@ const startCountdown = () => { |
| 211 | }, 1000) | 213 | }, 1000) |
| 212 | } | 214 | } |
| 213 | 215 | ||
| 214 | -const phoneError = ref('') | 216 | +const error = ref('') |
| 217 | +const loading = ref(false) | ||
| 215 | const isPhoneValid = ref(false) | 218 | const isPhoneValid = ref(false) |
| 216 | 219 | ||
| 217 | const validatePhone = () => { | 220 | const validatePhone = () => { |
| 218 | if (!formData.phone) { | 221 | if (!formData.phone) { |
| 219 | - phoneError.value = '请输入手机号' | 222 | + error.value = '请输入手机号' |
| 220 | isPhoneValid.value = false | 223 | isPhoneValid.value = false |
| 221 | return | 224 | return |
| 222 | } | 225 | } |
| 223 | 226 | ||
| 224 | if (!/^1[3-9]\d{9}$/.test(formData.phone)) { | 227 | if (!/^1[3-9]\d{9}$/.test(formData.phone)) { |
| 225 | - phoneError.value = '请输入正确的手机号' | 228 | + error.value = '请输入正确的手机号' |
| 226 | isPhoneValid.value = false | 229 | isPhoneValid.value = false |
| 227 | return | 230 | return |
| 228 | } | 231 | } |
| 229 | 232 | ||
| 230 | - phoneError.value = '' | 233 | + error.value = '' |
| 231 | isPhoneValid.value = true | 234 | isPhoneValid.value = true |
| 232 | } | 235 | } |
| 233 | 236 | ... | ... |
-
Please register or login to post a comment