From 38fef3d2aff0ae1159f1237858aa2d6d476ef618 Mon Sep 17 00:00:00 2001 From: stu2not Date: Wed, 27 May 2026 17:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AF=A6=E6=83=85=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E5=90=8E=E6=BB=9A=E5=8A=A8=E5=88=B0=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- banban-mini/src/pages/chat/detail/index.tsx | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/banban-mini/src/pages/chat/detail/index.tsx b/banban-mini/src/pages/chat/detail/index.tsx index c4bf853..3b0f28f 100644 --- a/banban-mini/src/pages/chat/detail/index.tsx +++ b/banban-mini/src/pages/chat/detail/index.tsx @@ -104,6 +104,8 @@ const FALLBACK_RUNTIME_INFO: VoiceRuntimeInfo = { supportsMp3Record: true, } +const CHAT_BOTTOM_ANCHOR_ID = 'chat-bottom' + function compareVersion(left: string, right: string): number { const leftParts = left.split('.').map((item) => Number(item) || 0) const rightParts = right.split('.').map((item) => Number(item) || 0) @@ -224,6 +226,7 @@ export default function ChatDetail() { const [recording, setRecording] = useState(false) const [playingMessageId, setPlayingMessageId] = useState(null) const [recordHint, setRecordHint] = useState('长按开始留言') + const [scrollTarget, setScrollTarget] = useState('') const audioContextRef = useRef(null) const recorderManagerRef = useRef(null) const activeConversationIdRef = useRef(initialConversationId) @@ -233,6 +236,18 @@ export default function ChatDetail() { const runtimeInfoRef = useRef(FALLBACK_RUNTIME_INFO) const recordStartedAtRef = useRef(0) const playingMessageIdRef = useRef(null) + const scrollTimerRef = useRef | null>(null) + + const scrollToBottom = () => { + if (scrollTimerRef.current) { + clearTimeout(scrollTimerRef.current) + } + setScrollTarget('') + scrollTimerRef.current = setTimeout(() => { + setScrollTarget(CHAT_BOTTOM_ANCHOR_ID) + scrollTimerRef.current = null + }, 80) + } useEffect(() => { runtimeInfoRef.current = readVoiceRuntimeInfo() @@ -290,6 +305,15 @@ export default function ChatDetail() { } }, []) + useEffect(() => { + return () => { + if (scrollTimerRef.current) { + clearTimeout(scrollTimerRef.current) + scrollTimerRef.current = null + } + } + }, []) + useEffect(() => { activeConversationIdRef.current = activeConversationId }, [activeConversationId]) @@ -325,6 +349,9 @@ export default function ChatDetail() { } const msgs = await getMessages(conversationId, conversationSource, decodedConversationTypeName) setMessages(msgs) + if (msgs.length > 0) { + scrollToBottom() + } } catch (error: any) { console.error('[chat-detail] load failed:', error) Taro.showToast({ @@ -621,7 +648,7 @@ export default function ChatDetail() { - + {loading ? ( 加载中... @@ -669,6 +696,7 @@ export default function ChatDetail() { )) )} + {character.canSend && character.childId && (