更新验证器:为必填项和数字输入添加国际化支持,提升用户体验

This commit is contained in:
jxxghp
2025-04-30 10:57:35 +08:00
parent 9b620a760d
commit f1835dd46c
4 changed files with 21 additions and 2 deletions

View File

@@ -1,7 +1,14 @@
import type { ValidationRule } from 'vuetify/types/services/validation'
import { useI18n } from 'vue-i18n'
// 必输校验
export const requiredValidator: ValidationRule = (value: any) => !!value || '此项为必填项'
export const requiredValidator: ValidationRule = (value: any) => {
const { t } = useI18n()
return !!value || t('validators.required')
}
// 数字校验
export const numberValidator: ValidationRule = (value: any) => !isNaN(value) || '请输入数字'
export const numberValidator: ValidationRule = (value: any) => {
const { t } = useI18n()
return !isNaN(value) || t('validators.number')
}

View File

@@ -2320,4 +2320,8 @@ export default {
byFileSize: 'By File Size',
keepLatestOnly: 'Keep Latest Only',
},
validators: {
required: 'This field is required',
number: 'Please enter a number',
},
}

View File

@@ -2296,4 +2296,8 @@ export default {
byFileSize: '按文件大小',
keepLatestOnly: '仅保留最新',
},
validators: {
required: '此项为必填项',
number: '请输入数字',
},
}

View File

@@ -2298,4 +2298,8 @@ export default {
byFileSize: '按文件大小',
keepLatestOnly: '僅保留最新',
},
validators: {
required: '此項為必填項',
number: '請輸入數字',
},
}