From eb485c92b3a8d5df958348bcda20e432dd3686b2 Mon Sep 17 00:00:00 2001 From: Ultrame <1019265060@qq.com> Date: Tue, 2 Dec 2025 20:16:26 +0800 Subject: [PATCH] =?UTF-8?q?EditModal=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/EditModal/index.tsx | 47 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/components/EditModal/index.tsx b/src/components/EditModal/index.tsx index 4f5d7d6..abe1087 100644 --- a/src/components/EditModal/index.tsx +++ b/src/components/EditModal/index.tsx @@ -82,17 +82,22 @@ const EditModal: React.FC = ({ new_value ); 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 = () => { + console.log("savexxxxxxx", isIllegal, hasIllegal, !isValid) if (isIllegal) { Taro.showToast({ title: "输入的字符非法", @@ -100,18 +105,17 @@ const EditModal: React.FC = ({ duration: 2000, }); return; - } - if (hasIllegal) { + } else if (hasIllegal) { + console.log("hasIllegal") Taro.showToast({ title: "内容不能包含@<>/等无效字符", icon: "none", - duration: 2000, + duration: 4000, }); return; - } - if (!isValid) { + } else if (!isValid) { Taro.showToast({ - title: validationMessage || `请填写 2-${maxLength} 个字符`, + title: `请填写 2-${maxLength} 个字符`, icon: "none", duration: 2000, }); @@ -122,6 +126,9 @@ const EditModal: React.FC = ({ const handle_cancel = () => { setValue(initialValue); + setHasIllegal(false); + setIsIllegal(false); + setCanEdit(true); onCancel(); }; @@ -169,13 +176,12 @@ const EditModal: React.FC = ({ confirmType="done" // autoFocus={true} onConfirm={handle_save} - onBlur={() => {}} + onBlur={(e) => { e.preventDefault() }} /> maxLength && "un-valid" - }`} + className={`count_text ${value.length > maxLength && "un-valid" + }`} > {value.length}/{maxLength} @@ -202,9 +208,8 @@ const EditModal: React.FC = ({ /> maxLength && "un-valid" - }`} + className={`count_text ${value.length > maxLength && "un-valid" + }`} > {value.length}/{maxLength}