diff --git a/projects/translate-h5/src/view/home/translate/component/message/index.tsx b/projects/translate-h5/src/view/home/translate/component/message/index.tsx index 05a66b0..1507105 100644 --- a/projects/translate-h5/src/view/home/translate/component/message/index.tsx +++ b/projects/translate-h5/src/view/home/translate/component/message/index.tsx @@ -17,11 +17,13 @@ function Index(props: DefinedProps) { const [isPlaying, setIsPlating] = useState(false); const [currentPlayingId, setCurrentPlayingId] = useState(); - // useEffect(() => { - // if (isRecording) { - // stopAllAudio(); - // } - // }, [isRecording]); + useEffect(() => { + if (isRecording && currentPlayingId) { + audioRefs.current[currentPlayingId].pause(); + audioRefs.current[currentPlayingId].currentTime = 0; + setCurrentPlayingId(undefined); + } + }, [isRecording, currentPlayingId]); const playAudio = (id: number, audioUrl: string) => { if (isRecording) { @@ -45,22 +47,7 @@ function Index(props: DefinedProps) { setCurrentPlayingId(undefined); } }; - // const stopAllAudio = () => { - // if (currentPlayingId && audioRefs.current[currentPlayingId]) { - // audioRefs.current[currentPlayingId].pause(); - // audioRefs.current[currentPlayingId].currentTime = 0; - // setIsPlating(false); - // setCurrentPlayingId(undefined); - // return; - // } - // Object.values(audioRefs.current).forEach((audio) => { - // if (!audio.paused) { - // audio.pause(); - // audio.currentTime = 0; - // } - // }); - // }; const renderAvatar = (item: Message) => { return ; }; @@ -132,32 +119,6 @@ function Index(props: DefinedProps) {
{item.contentDuration}''
{renderTranslateResult(item)} - {/* {item.isTranslating ? ( -
- - 翻译中... -
- ) : item.transStatus === 1 ? ( -
- {item.transResult?.length ? ( - item.transResult - ) : ( - - 未知语句 - refreshMessage(item.id, e)} size="12" fill="#333" /> - - )} -
- ) : ( - - 翻译失败,请重试 - refreshMessage(item.id, e)} size="12" fill="#333" /> - - //
- // 翻译失败,请重试 - // refreshMessage(item.id, e)} size="12" fill="#333" /> - //
- )} */} ))}