mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-12-01 19:48:14 +08:00
[Core] [UI] Fix verification code validation rules
This commit is contained in:
parent
310576422c
commit
ca7a00151c
@ -719,6 +719,7 @@ export default {
|
||||
passwordTip: 'Please enter your password',
|
||||
confirmPasswordTip: 'Please confirm your password',
|
||||
captchaTip: 'Please enter the captcha',
|
||||
captchaIsNumberTip: 'Captcha must be a number',
|
||||
notUserTip: 'Don\'t have an account?',
|
||||
hasUserTip: 'Already have an account?',
|
||||
passwordNotMatchTip: 'Password does not match',
|
||||
|
@ -719,6 +719,7 @@ export default {
|
||||
passwordTip: '请输入密码',
|
||||
confirmPasswordTip: '请输入确认密码',
|
||||
captchaTip: '请输入验证码',
|
||||
captchaIsNumberTip: '验证码必须为数字',
|
||||
notUserTip: '没有账号?',
|
||||
hasUserTip: '已有账号?',
|
||||
passwordNotMatchTip: '密码不匹配',
|
||||
|
@ -74,7 +74,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, inject, ref, watch } from 'vue'
|
||||
import { defineComponent, inject, ref } from 'vue'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import Button from '@/views/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@ -116,34 +116,22 @@ export default defineComponent({
|
||||
const captchaLoading = ref(false)
|
||||
const formState = ref<UserRequest>({ username: null, password: null })
|
||||
|
||||
const validationSchema = ref(
|
||||
z.object({
|
||||
const validationSchema = z
|
||||
.object({
|
||||
username: z.string({ required_error: $t('user.auth.usernameTip') })
|
||||
.min(2, $t('user.auth.usernameSizeTip'))
|
||||
.max(20, $t('user.auth.usernameSizeTip')),
|
||||
password: z.string({ required_error: $t('user.auth.passwordTip') })
|
||||
.min(6, $t('user.auth.passwordSizeTip'))
|
||||
.max(20, $t('user.auth.passwordSizeTip'))
|
||||
.max(20, $t('user.auth.passwordSizeTip')),
|
||||
captcha: z.coerce.number({ required_error: $t('user.auth.captchaTip'), invalid_type_error: $t('user.auth.captchaIsNumberTip') })
|
||||
.optional()
|
||||
})
|
||||
)
|
||||
|
||||
const initializeForm = () => {
|
||||
const formSchema = toTypedSchema(validationSchema.value)
|
||||
return useForm({ validationSchema: formSchema })
|
||||
}
|
||||
const formSchema = toTypedSchema(validationSchema)
|
||||
|
||||
let { handleSubmit } = initializeForm()
|
||||
|
||||
watch(showCaptcha, (newValue) => {
|
||||
if (newValue) {
|
||||
validationSchema.value = validationSchema.value.extend({
|
||||
captcha: z.string({ required_error: $t('user.auth.captchaTip') })
|
||||
.min(1, $t('user.auth.captchaSizeTip'))
|
||||
.max(6, $t('user.auth.captchaSizeTip'))
|
||||
})
|
||||
const { handleSubmit: newHandleSubmit } = initializeForm()
|
||||
handleSubmit = newHandleSubmit
|
||||
}
|
||||
const { handleSubmit } = useForm({
|
||||
validationSchema: formSchema
|
||||
})
|
||||
|
||||
const refererCaptcha = () => {
|
||||
|
@ -122,7 +122,8 @@ export default defineComponent({
|
||||
const captchaLoading = ref(false)
|
||||
const $t: any = inject('$t')
|
||||
const formState = ref<UserRequest>({ username: null, password: null })
|
||||
const validator = z
|
||||
|
||||
const validationSchema = z
|
||||
.object({
|
||||
username: z.string({ required_error: $t('user.auth.usernameTip') })
|
||||
.min(2, $t('user.auth.usernameSizeTip'))
|
||||
@ -132,22 +133,16 @@ export default defineComponent({
|
||||
.max(20, $t('user.auth.passwordSizeTip')),
|
||||
confirmPassword: z.string({ required_error: $t('user.auth.confirmPasswordTip') })
|
||||
.min(6, $t('user.auth.passwordSizeTip'))
|
||||
.max(50, $t('user.auth.passwordSizeTip'))
|
||||
.max(50, $t('user.auth.passwordSizeTip')),
|
||||
captcha: z.coerce.number({ required_error: $t('user.auth.captchaTip'), invalid_type_error: $t('user.auth.captchaIsNumberTip') })
|
||||
.optional()
|
||||
})
|
||||
.refine((data) => data.password === data.confirmPassword, {
|
||||
message: $t('user.auth.confirmPasswordTip'),
|
||||
path: ['confirmPassword']
|
||||
})
|
||||
|
||||
if (showCaptcha.value) {
|
||||
validator.extend({
|
||||
captcha: z.string({ required_error: $t('user.auth.captchaTip') })
|
||||
.min(1, $t('user.auth.captchaSizeTip'))
|
||||
.max(6, $t('user.auth.captchaSizeTip'))
|
||||
})
|
||||
}
|
||||
|
||||
const formSchema = toTypedSchema(validator)
|
||||
const formSchema = toTypedSchema(validationSchema)
|
||||
|
||||
const { handleSubmit } = useForm({
|
||||
validationSchema: formSchema
|
||||
|
Loading…
Reference in New Issue
Block a user