下拉隐藏简介等信息,优化超出文本长度交互
This commit is contained in:
@@ -29,6 +29,7 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
}) => {
|
||||
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<EditModalProps> = ({
|
||||
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<EditModalProps> = ({
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (isIllegal) {
|
||||
Taro.showToast({
|
||||
title: "输入的字符非法",
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
onSave(value);
|
||||
};
|
||||
|
||||
@@ -104,48 +115,61 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
<View className="input_container">
|
||||
|
||||
{type === 'nickname' ? (
|
||||
<Input
|
||||
className="text_input nickname_input"
|
||||
value={value}
|
||||
type="nickname"
|
||||
placeholder={placeholder}
|
||||
maxlength={maxLength}
|
||||
onInput={handle_input_change}
|
||||
adjustPosition={false}
|
||||
confirmType="done"
|
||||
autoFocus={true}
|
||||
/>
|
||||
<>
|
||||
<Input
|
||||
className="text_input nickname_input"
|
||||
value={value}
|
||||
type="nickname"
|
||||
placeholder={placeholder}
|
||||
// maxlength={maxLength}
|
||||
onInput={handle_input_change}
|
||||
adjustPosition={false}
|
||||
confirmType="done"
|
||||
autoFocus={true}
|
||||
/>
|
||||
<View className="char_count">
|
||||
<Text className={`count_text ${value.length > maxLength && "un-valid"}`}>{value.length}/{maxLength}</Text>
|
||||
</View>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Textarea
|
||||
className="text_input"
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
maxlength={maxLength}
|
||||
// maxlength={maxLength}
|
||||
onInput={handle_input_change}
|
||||
autoFocus={true}
|
||||
adjustPosition={false}
|
||||
/>
|
||||
<View className="char_count">
|
||||
<Text className="count_text">{value.length}/{maxLength}</Text>
|
||||
<Text className={`count_text ${value.length > maxLength && "un-valid"}`}>{value.length}/{maxLength}</Text>
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 验证提示 */}
|
||||
{!isValid && (
|
||||
<View className="validation_message">
|
||||
<Text className="validation_text">
|
||||
{validationMessage || `请填写 2-${maxLength} 个字符`}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
{
|
||||
isIllegal ?
|
||||
<View className="validation_message">
|
||||
<Text className="validation_text illegal">
|
||||
输入的字符非法
|
||||
</Text>
|
||||
</View> :
|
||||
!isValid && (
|
||||
<View className="validation_message">
|
||||
<Text className="validation_text">
|
||||
{validationMessage || `请填写 2-${maxLength} 个字符`}
|
||||
</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
</View>
|
||||
|
||||
{/* 底部按钮 */}
|
||||
<View className="modal_footer">
|
||||
<View className={`save_button ${!isValid ? "disabled" : ""}`} onClick={handle_save}>
|
||||
<View className={`save_button ${!isValid || isIllegal ? "disabled" : ""}`} onClick={handle_save}>
|
||||
<Text className="save_text">保存</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user