fix: 标签输入增加输入校验&邮箱邀请校验邮箱格式

This commit is contained in:
baiqi 2024-07-16 18:21:30 +08:00 committed by 刘瑞斌
parent 676f3ce4eb
commit d9d3485370
2 changed files with 28 additions and 7 deletions

View File

@ -64,6 +64,7 @@
size?: 'small' | 'large' | 'medium' | 'mini'; size?: 'small' | 'large' | 'medium' | 'mini';
disabled?: boolean; disabled?: boolean;
noTooltip?: boolean; noTooltip?: boolean;
inputValidator?: (value: string) => boolean;
}>(), }>(),
{ {
retainInputValue: true, retainInputValue: true,
@ -153,12 +154,17 @@
validateTagsCountBlur() && validateTagsCountBlur() &&
(innerInputValue.value || '').trim().length <= props.maxLength (innerInputValue.value || '').trim().length <= props.maxLength
) { ) {
if (props.inputValidator && !props.inputValidator(innerInputValue.value.trim())) {
innerModelValue.value.splice(-1, 1);
emit('update:modelValue', innerModelValue.value);
} else {
innerModelValue.value.push(innerInputValue.value.trim()); innerModelValue.value.push(innerInputValue.value.trim());
innerInputValue.value = ''; innerInputValue.value = '';
tagsLength.value += 1; tagsLength.value += 1;
emit('update:modelValue', innerModelValue.value); emit('update:modelValue', innerModelValue.value);
emit('change', innerModelValue.value); emit('change', innerModelValue.value);
} }
}
emit('blur'); emit('blur');
} }
@ -169,8 +175,13 @@
innerInputValue.value && innerInputValue.value &&
innerInputValue.value.trim().length <= props.maxLength innerInputValue.value.trim().length <= props.maxLength
) { ) {
if (props.inputValidator && !props.inputValidator(innerInputValue.value.trim())) {
innerModelValue.value.splice(-1, 1);
emit('update:modelValue', innerModelValue.value);
} else {
innerInputValue.value = ''; innerInputValue.value = '';
tagsLength.value += 1; tagsLength.value += 1;
}
} else { } else {
innerModelValue.value = innerModelValue.value.filter((item: any) => item.length <= props.maxLength); innerModelValue.value = innerModelValue.value.filter((item: any) => item.length <= props.maxLength);
innerInputValue.value = ''; innerInputValue.value = '';

View File

@ -19,6 +19,7 @@
v-model:model-value="emailForm.emails" v-model:model-value="emailForm.emails"
placeholder="system.user.inviteEmailPlaceholder" placeholder="system.user.inviteEmailPlaceholder"
tags-duplicate-text="system.user.inviteEmailRepeat" tags-duplicate-text="system.user.inviteEmailRepeat"
:input-validator="validateInputEmailTag"
allow-clear allow-clear
unique-value unique-value
retain-input-value retain-input-value
@ -61,6 +62,7 @@
import { inviteUser } from '@/api/modules/setting/user'; import { inviteUser } from '@/api/modules/setting/user';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import { validateEmail } from '@/utils/validate';
import { ProjectUserOption } from '@/models/projectManagement/projectAndPermission'; import { ProjectUserOption } from '@/models/projectManagement/projectAndPermission';
import type { SystemRole } from '@/models/setting/user'; import type { SystemRole } from '@/models/setting/user';
@ -119,6 +121,14 @@
} }
); );
function validateInputEmailTag(value: string) {
if (validateEmail(value)) {
return true;
}
Message.warning(t('system.config.email.emailErrTip'));
return false;
}
function cancelInvite() { function cancelInvite() {
inviteVisible.value = false; inviteVisible.value = false;
inviteFormRef.value?.resetFields(); inviteFormRef.value?.resetFields();