优化获取昵称修改状态的时机

This commit is contained in:
2025-12-03 15:44:41 +08:00
parent 7c1a1fafc1
commit b77b4b0536
9 changed files with 160 additions and 128 deletions

View File

@@ -11,7 +11,7 @@ interface EditModalProps {
placeholder: string;
initialValue: string;
maxLength: number;
invalidCharacters: string;
invalidCharacters: RegExp | null;
onSave: (value: string) => void;
onCancel: () => void;
validationMessage?: string;
@@ -24,7 +24,7 @@ const EditModal: React.FC<EditModalProps> = ({
placeholder,
initialValue,
maxLength,
invalidCharacters = "",
invalidCharacters = null,
onSave,
onCancel,
validationMessage,
@@ -63,18 +63,13 @@ const EditModal: React.FC<EditModalProps> = ({
}
}, [visible, initialValue]);
const createExcludeRegex = (chars: string) => {
const escapedChars = chars.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const pattern = `[${escapedChars}]`;
return new RegExp(pattern);
};
const handle_input_change = (e: any) => {
const new_value = e.detail.value;
setValue(new_value);
let ishasIllegal = false;
if (type === "nickname") {
ishasIllegal = createExcludeRegex(invalidCharacters).test(new_value);
setHasIllegal(ishasIllegal);
if (type === "nickname" && invalidCharacters) {
ishasIllegal = invalidCharacters.test(new_value);
setHasIllegal(!ishasIllegal);
}
const illegal =
/\b(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|ALTER|CREATE|EXEC|DECLARE)\b|('|--|\/\*|\*\/|;|#)|(=|'|"|`|\\|\|\|&&)|\bOR\s+['"]?[\w]+['"]?\s*=\s*['"]?[\w]+['"]?|\bUNION\s+SELECT\b|\bDROP\s+TABLE\b|\bINSERT\s+INTO\b|\bUPDATE\s+[\w]+\s+SET\b|\bDELETE\s+FROM\b/i.test(