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';
disabled?: boolean;
noTooltip?: boolean;
inputValidator?: (value: string) => boolean;
}>(),
{
retainInputValue: true,
@ -153,11 +154,16 @@
validateTagsCountBlur() &&
(innerInputValue.value || '').trim().length <= props.maxLength
) {
innerModelValue.value.push(innerInputValue.value.trim());
innerInputValue.value = '';
tagsLength.value += 1;
emit('update:modelValue', innerModelValue.value);
emit('change', innerModelValue.value);
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());
innerInputValue.value = '';
tagsLength.value += 1;
emit('update:modelValue', innerModelValue.value);
emit('change', innerModelValue.value);
}
}
emit('blur');
}
@ -169,8 +175,13 @@
innerInputValue.value &&
innerInputValue.value.trim().length <= props.maxLength
) {
innerInputValue.value = '';
tagsLength.value += 1;
if (props.inputValidator && !props.inputValidator(innerInputValue.value.trim())) {
innerModelValue.value.splice(-1, 1);
emit('update:modelValue', innerModelValue.value);
} else {
innerInputValue.value = '';
tagsLength.value += 1;
}
} else {
innerModelValue.value = innerModelValue.value.filter((item: any) => item.length <= props.maxLength);
innerInputValue.value = '';

View File

@ -19,6 +19,7 @@
v-model:model-value="emailForm.emails"
placeholder="system.user.inviteEmailPlaceholder"
tags-duplicate-text="system.user.inviteEmailRepeat"
:input-validator="validateInputEmailTag"
allow-clear
unique-value
retain-input-value
@ -61,6 +62,7 @@
import { inviteUser } from '@/api/modules/setting/user';
import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app';
import { validateEmail } from '@/utils/validate';
import { ProjectUserOption } from '@/models/projectManagement/projectAndPermission';
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() {
inviteVisible.value = false;
inviteFormRef.value?.resetFields();