EditModal优化
This commit is contained in:
@@ -82,17 +82,22 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
new_value
|
new_value
|
||||||
);
|
);
|
||||||
setIsIllegal(illegal);
|
setIsIllegal(illegal);
|
||||||
// 验证输入
|
|
||||||
const valid =
|
|
||||||
new_value.length >= 2 &&
|
|
||||||
new_value.length <= maxLength &&
|
|
||||||
!ishasIllegal &&
|
|
||||||
!illegal &&
|
|
||||||
canEdit;
|
|
||||||
setIsValid(valid);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const valid =
|
||||||
|
value.length >= 2 &&
|
||||||
|
value.length <= maxLength &&
|
||||||
|
!hasIllegal &&
|
||||||
|
!isIllegal &&
|
||||||
|
canEdit;
|
||||||
|
setIsValid(valid);
|
||||||
|
}, [
|
||||||
|
value, hasIllegal, isIllegal, canEdit
|
||||||
|
])
|
||||||
|
|
||||||
const handle_save = () => {
|
const handle_save = () => {
|
||||||
|
console.log("savexxxxxxx", isIllegal, hasIllegal, !isValid)
|
||||||
if (isIllegal) {
|
if (isIllegal) {
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: "输入的字符非法",
|
title: "输入的字符非法",
|
||||||
@@ -100,18 +105,17 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
} else if (hasIllegal) {
|
||||||
if (hasIllegal) {
|
console.log("hasIllegal")
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: "内容不能包含@<>/等无效字符",
|
title: "内容不能包含@<>/等无效字符",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
duration: 2000,
|
duration: 4000,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!isValid) {
|
||||||
if (!isValid) {
|
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: validationMessage || `请填写 2-${maxLength} 个字符`,
|
title: `请填写 2-${maxLength} 个字符`,
|
||||||
icon: "none",
|
icon: "none",
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
@@ -122,6 +126,9 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
|
|
||||||
const handle_cancel = () => {
|
const handle_cancel = () => {
|
||||||
setValue(initialValue);
|
setValue(initialValue);
|
||||||
|
setHasIllegal(false);
|
||||||
|
setIsIllegal(false);
|
||||||
|
setCanEdit(true);
|
||||||
onCancel();
|
onCancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,12 +176,11 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
confirmType="done"
|
confirmType="done"
|
||||||
// autoFocus={true}
|
// autoFocus={true}
|
||||||
onConfirm={handle_save}
|
onConfirm={handle_save}
|
||||||
onBlur={() => {}}
|
onBlur={(e) => { e.preventDefault() }}
|
||||||
/>
|
/>
|
||||||
<View className="char_count">
|
<View className="char_count">
|
||||||
<Text
|
<Text
|
||||||
className={`count_text ${
|
className={`count_text ${value.length > maxLength && "un-valid"
|
||||||
value.length > maxLength && "un-valid"
|
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{value.length}/{maxLength}
|
{value.length}/{maxLength}
|
||||||
@@ -202,8 +208,7 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
<View className="char_count">
|
<View className="char_count">
|
||||||
<Text
|
<Text
|
||||||
className={`count_text ${
|
className={`count_text ${value.length > maxLength && "un-valid"
|
||||||
value.length > maxLength && "un-valid"
|
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{value.length}/{maxLength}
|
{value.length}/{maxLength}
|
||||||
|
|||||||
Reference in New Issue
Block a user