diff --git a/src/components/EditModal/EditModal.scss b/src/components/EditModal/EditModal.scss index 3c42797..978fcb3 100644 --- a/src/components/EditModal/EditModal.scss +++ b/src/components/EditModal/EditModal.scss @@ -140,6 +140,9 @@ font-size: 14px; line-height: 1.71em; color: rgba(60, 60, 67, 0.3); + &.un-valid { + color: #FF3B30; + } } } } @@ -153,6 +156,9 @@ font-size: 12px; line-height: 1.5em; color: rgba(60, 60, 67, 0.6); + &.illegal { + color: #FF3B30; + } } } } diff --git a/src/components/EditModal/index.tsx b/src/components/EditModal/index.tsx index eefd0c4..99086d0 100644 --- a/src/components/EditModal/index.tsx +++ b/src/components/EditModal/index.tsx @@ -29,6 +29,7 @@ const EditModal: React.FC = ({ }) => { const [value, setValue] = useState(initialValue); const [isValid, setIsValid] = useState(true); + const [isIllegal, setIsIllegal] = useState(false); // 使用全局键盘状态 const { keyboardHeight, isKeyboardVisible, addListener, initializeKeyboardListener } = useKeyboardHeight() @@ -58,6 +59,8 @@ const EditModal: React.FC = ({ const new_value = e.detail.value; setValue(new_value); + 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(new_value) + setIsIllegal(illegal) // 验证输入 const valid = new_value.length >= 2 && new_value.length <= maxLength; setIsValid(valid); @@ -72,6 +75,14 @@ const EditModal: React.FC = ({ }); return; } + if (isIllegal) { + Taro.showToast({ + title: "输入的字符非法", + icon: 'none', + duration: 2000 + }); + return; + } onSave(value); }; @@ -104,48 +115,61 @@ const EditModal: React.FC = ({ {type === 'nickname' ? ( - + <> + + + maxLength && "un-valid"}`}>{value.length}/{maxLength} + + ) : ( <>