一些问题的修复
This commit is contained in:
@@ -303,6 +303,85 @@
|
||||
</div>
|
||||
</a-form>
|
||||
</div>
|
||||
|
||||
<!-- 忘记密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="forgotPasswordVisible"
|
||||
title="忘记密码"
|
||||
:footer="null"
|
||||
width="90%"
|
||||
:destroyOnClose="true"
|
||||
>
|
||||
<a-form
|
||||
:model="forgotPasswordForm"
|
||||
:rules="forgotPasswordRules"
|
||||
@finish="handleResetPassword"
|
||||
layout="vertical"
|
||||
>
|
||||
<a-form-item name="phone" label="手机号">
|
||||
<a-input
|
||||
v-model:value="forgotPasswordForm.phone"
|
||||
placeholder="请输入绑定的手机号"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="verificationCode" label="验证码">
|
||||
<a-input
|
||||
v-model:value="forgotPasswordForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="forgotCountdown > 0 || !forgotPasswordForm.phone"
|
||||
@click="handleSendForgotCode"
|
||||
>
|
||||
{{ forgotCountdown > 0 ? `${forgotCountdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="newPassword" label="新密码">
|
||||
<a-input-password
|
||||
v-model:value="forgotPasswordForm.newPassword"
|
||||
placeholder="请输入新密码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="resettingPassword"
|
||||
>
|
||||
重置密码
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button size="large" block @click="forgotPasswordVisible = false">
|
||||
取消
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -327,6 +406,16 @@ const accountStatus = ref<any>(null)
|
||||
const phoneUserStatus = ref<any>(null)
|
||||
const countdown = ref(0)
|
||||
|
||||
const forgotPasswordVisible = ref(false)
|
||||
const forgotCountdown = ref(0)
|
||||
const resettingPassword = ref(false)
|
||||
|
||||
const forgotPasswordForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: '',
|
||||
newPassword: ''
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
@@ -342,6 +431,14 @@ const validatePassword = async (_rule: any, value: string) => {
|
||||
if (value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于6位')
|
||||
}
|
||||
let count = 0
|
||||
if (/\d/.test(value)) count++
|
||||
if (/[a-z]/.test(value)) count++
|
||||
if (/[A-Z]/.test(value)) count++
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value)) count++
|
||||
if (count < 3) {
|
||||
return Promise.reject('密码必须包含数字、小写字母、大写字母和符号中的至少3种')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
@@ -357,9 +454,7 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
|
||||
const rules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
@@ -379,13 +474,28 @@ const rules: Record<string, Rule[]> = {
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' }
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' },
|
||||
{ pattern: /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/, message: '昵称不能包含特殊符号', trigger: 'blur' }
|
||||
],
|
||||
shopId: [
|
||||
{ required: true, message: '请选择店铺', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
|
||||
const forgotPasswordRules: Record<string, Rule[]> = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -474,7 +584,55 @@ const handleSubmit = async () => {
|
||||
}
|
||||
|
||||
const handleForgotPassword = () => {
|
||||
message.info('忘记密码功能开发中')
|
||||
forgotPasswordVisible.value = true
|
||||
}
|
||||
|
||||
const handleSendForgotCode = async () => {
|
||||
if (!forgotPasswordForm.phone) {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(forgotPasswordForm.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await authApi.sendVerificationCode({ phone: forgotPasswordForm.phone })
|
||||
message.success('验证码已发送')
|
||||
forgotCountdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
forgotCountdown.value--
|
||||
if (forgotCountdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.message || '发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetPassword = async () => {
|
||||
resettingPassword.value = true
|
||||
try {
|
||||
await authApi.resetPasswordByPhone({
|
||||
phone: forgotPasswordForm.phone,
|
||||
verificationCode: forgotPasswordForm.verificationCode,
|
||||
newPassword: forgotPasswordForm.newPassword
|
||||
})
|
||||
message.success('密码重置成功,请使用新密码登录')
|
||||
forgotPasswordVisible.value = false
|
||||
|
||||
forgotPasswordForm.phone = ''
|
||||
forgotPasswordForm.verificationCode = ''
|
||||
forgotPasswordForm.newPassword = ''
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.message || '重置密码失败')
|
||||
} finally {
|
||||
resettingPassword.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleWeChatLogin = () => {
|
||||
@@ -542,6 +700,12 @@ const handleSendVerificationCode = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||
message.success('验证码已发送')
|
||||
|
||||
Reference in New Issue
Block a user