import { getStaticImage, getBackgroundImage } from "@/lib/utils"; import type { MouseEvent } from "react"; import { useEffect } from "react"; import { useAudioManager } from "@/hooks/useAudioManager"; export interface SuccessAlertProps { /** 标题 */ title?: string; /** 内容文本 */ content?: string; /** 是否可见 */ visible?: boolean; /** 成功提示音频地址(可选) */ audioSrc?: string; /** 弹窗出现时是否自动播放音频(默认 true) */ autoPlayAudio?: boolean; /** 音频分组 id,相同 channel 内互斥,不同 channel 可同时播放;不传则全局互斥 */ audioChannelId?: string; /** 点击遮罩层回调 */ onMaskClick?: () => void; /** 继续按钮回调 */ onContinue?: () => void; /** 关闭回调 */ onClose?: () => void; } /** * SuccessAlert 组件 - 成功提示弹窗 * 使用 components/正确版 作为背景 */ const SuccessAlert = ({ title = "恭喜你, 选择正确!", content, visible = true, audioSrc, autoPlayAudio = true, audioChannelId, onMaskClick, onContinue, onClose, }: SuccessAlertProps) => { const { currentSrc, play, stop } = useAudioManager( audioChannelId ? { mode: "channel", channelId: audioChannelId } : { mode: "global" } ); // 弹窗显示时自动播放音频 useEffect(() => { if (!visible) return; if (!autoPlayAudio) return; if (!audioSrc) return; play(audioSrc); }, [visible, autoPlayAudio, audioSrc, play]); // 弹窗关闭时停止音频(仅当当前播放的是该弹窗的 audioSrc) useEffect(() => { if (visible) return; if (audioSrc && currentSrc === audioSrc) { stop(); } }, [visible, audioSrc, currentSrc, stop]); if (!visible) return null; const handleContinue = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); // 点击继续时停止音频 if (audioSrc && currentSrc === audioSrc) { stop(); } // 只调用 onContinue,它会处理关闭逻辑 if (onContinue) { onContinue(); } else if (onClose) { onClose(); } }; return (