From 05b89a4aeb9a8f59e0597841b717c8bf8f22ab82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Fri, 6 Mar 2026 10:30:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E7=AE=A1=E7=90=86=E5=BC=B9=E7=AA=97=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E8=81=9A=E7=84=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/GameManagePopup/index.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/GameManagePopup/index.tsx b/src/components/GameManagePopup/index.tsx index bf7abcb..bb64427 100644 --- a/src/components/GameManagePopup/index.tsx +++ b/src/components/GameManagePopup/index.tsx @@ -16,8 +16,8 @@ const CancelPopup = forwardRef((props, ref) => { const { detail } = props; const [visible, setVisible] = useState(false); const [cancelReason, setCancelReason] = useState(""); + const [inputFocus, setInputFocus] = useState(false); const onFinish = useRef(null); - const inputRef = useRef(null); const { current_players, participants = [], publisher_id } = detail; const realParticipants = participants @@ -32,16 +32,15 @@ const CancelPopup = forwardRef((props, ref) => { show: (onAct) => { onFinish.current = onAct; setVisible(true); - // 使用 requestAnimationFrame 替代 setTimeout(0),性能更好 - requestAnimationFrame(() => { - requestAnimationFrame(() => { - inputRef.current && inputRef.current.focus(); - }); + // 使用 Taro.nextTick 确保在下一个渲染周期后聚焦 + Taro.nextTick(() => { + setInputFocus(true); }); }, })); function onClose() { + setInputFocus(false); setVisible(false); setCancelReason(""); } @@ -85,13 +84,13 @@ const CancelPopup = forwardRef((props, ref) => { {hasOtherJoin && ( setCancelReason(e.detail.value)} maxlength={100} + onBlur={() => setInputFocus(false)} /> )}