import { useState, useEffect, useMemo, useCallback } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { cn, getStaticImage } from "@/lib/utils"; import { Image, StudyGuideModal } from "@/components"; import { SuccessAlert, ErrorAlert } from "@/components/layout"; export interface ChoiceDialog1Props { /** 是否可见 */ visible?: boolean; /** 关闭回调 */ onClose?: () => void; /** 选择回调 */ onSelect?: (choice: "读书" | "没出息" | "女子不能上学") => void; } /** * 第一个选择弹窗:人物和三个选择 * - 使用蒙版遮罩作为背景 * - 显示人物10_004和三个选择选项 */ const ChoiceDialog1 = ({ visible = true, onClose, onSelect, }: ChoiceDialog1Props) => { const maskSrc = getStaticImage("components/蒙版遮罩"); const backSrc = getStaticImage("components/关闭"); const characterSrc = getStaticImage("huangyanpei/reflection/scene2/10_004"); const choice1Src = getStaticImage("huangyanpei/reflection/scene2/10_005"); const choice2Src = getStaticImage("huangyanpei/reflection/scene2/10_006"); const choice3Src = getStaticImage("huangyanpei/reflection/scene2/10_007"); const [mounted, setMounted] = useState(false); const [showGuide, setShowGuide] = useState(false); const [showSuccessAlert, setShowSuccessAlert] = useState(false); const [showErrorAlert, setShowErrorAlert] = useState(false); // SSR 兼容 useEffect(() => { setMounted(true); }, []); useEffect(() => { if (visible) { setShowGuide(true); setShowSuccessAlert(false); setShowErrorAlert(false); } else { setShowGuide(false); } }, [visible]); const handleClose = useCallback( (e: React.MouseEvent) => { e.stopPropagation(); onClose?.(); }, [onClose] ); const handleChoiceClick = useCallback( (choice: "读书" | "没出息" | "女子不能上学") => { if (choice === "读书") { setShowGuide(false); setShowSuccessAlert(true); onSelect?.(choice); } else { setShowErrorAlert(true); } }, [onSelect] ); // 样式 const overlayStyle = useMemo( () => ({ position: "fixed", inset: 0, zIndex: 9999, pointerEvents: "none", }), [] ); if (!mounted) return null; const content = ( {visible && (
{/* 背景蒙版 */} {maskSrc && ( )} setShowGuide(false)} verticalAlign="center" > 黄校长来考你啦!他设计这所学校,就是为了让学生摆脱旧观念,你知道是哪种吗? {/* 返回按钮 */} {onClose && ( 返回 )} {/* 内容区域 */}
{/* 人物 - 左侧 */}
人物
{/* 三个选择选项 - 右侧水平排列 */}
{/* 选择A:读书 */}
handleChoiceClick("读书")} > {/* 标签A */}
A
{/* 图标 */} 读书 {/* 文字说明 */}
读书只为
升官发财
{/* 选择B:没出息 */}
handleChoiceClick("没出息")} > {/* 标签B */}
B
{/* 图标 */} 没出息 {/* 文字说明 */}
手工劳作
没出息
{/* 选择C:女子不能上学 */}
handleChoiceClick("女子不能上学")} > {/* 标签C */}
C
{/* 图标 */} 女子不能上学 {/* 文字说明 */}
女子
不能上学
{ setShowSuccessAlert(false); onClose?.(); }} onClose={() => { setShowSuccessAlert(false); onClose?.(); }} /> setShowErrorAlert(false)} /> { setShowSuccessAlert(false); onClose?.(); }} onClose={() => { setShowSuccessAlert(false); onClose?.(); }} /> setShowErrorAlert(false)} />
)}
); return content; }; export default ChoiceDialog1;