import { useEffect, useMemo, useState, useRef } from "react"; import { useNavigate, useParams } from "react-router-dom"; import { Image, Video, type VideoAnchor, type VideoRef, type DragFillResult, LetterToHuangyanpei, EndingOverlay, Narration, } from "@/components"; import { getBackgroundImage, getPublicPath, getStaticImage } from "@/lib/utils"; import { SuccessAlert, DragQuizPanel } from "@/components/layout"; import { MultipleChoiceQuizPanel } from "@/components/layout/quiz"; import { GuideSteps, GuideStepsItem } from "@/components"; import { usePuzzleAnimation } from "@/contexts/PuzzleAnimationContext"; type QuizOption = { value: string; label: string; isCorrect?: boolean; explanation?: string; }; type QuizAnchor = { id: string; time: number; title: string; prompt: string; type: "single" | "multiple" | "drag"; options: QuizOption[]; blanks?: { id: string; label: string }[]; explanation?: string; }; const starName = "huangyanpei"; // 锚点数据:根据视频时长调整 time const QUIZ_ANCHORS: QuizAnchor[] = [ // { // id: "quiz-1", // time: 96, // 1:36 // title: "题目1", // prompt: // "当年黄炎培先生创办中华职业学校,开设的专业都是当时中国最需要的实业领域,分别是( )。", // type: "multiple", // options: [ // { value: "A", label: "铁工", isCorrect: true }, // { // value: "B", // label: "自动控制", // }, // { value: "C", label: "木工", isCorrect: true }, // { value: "D", label: "纽扣科", isCorrect: true }, // ], // explanation: // "自动控制”这一工程理论框架成形于20世纪中叶,70年代实现集中控制,在民国时期,没有相关学科基础、设备与技术条件", // }, { id: "quiz-2", time: 221, // 3:41 title: "题目2", prompt: "黄炎培先生主导设计的课程与现在中职学校强调的理实一体这一理念相通是:", type: "multiple", options: [ { value: "A", label: "上午学机械原理,下午就去车间打铁、造台钳", isCorrect: true, }, { value: "B", label: "课堂上学记账、推销,课后就去街头卖国货", isCorrect: true, }, { value: "C", label: "学习四书五经、八股文", }, { value: "D", label: '在川沙小学堂采取"半天读书、半天做手工"的学习模式', isCorrect: true, }, ], explanation: "黄炎培认为教育不能只谈书本、脱离实际", }, { id: "quiz-3", time: 360, // 6:10 title: "题目3", prompt: '当年黄炎培先生有推广国货的爱国情怀,如今我们的"国货"已经自强自立,请将其中的国产企业/品牌放置到空格处', type: "drag", options: [ { value: "特斯拉", label: "特斯拉" }, { value: "比亚迪", label: "比亚迪" }, { value: "华为", label: "华为" }, { value: "江南造船", label: "江南造船" }, { value: "光明食品", label: "光明食品" }, { value: "C919飞机", label: "C919飞机" }, ], blanks: [ { id: "blank-1", label: "国产企业1" }, { id: "blank-2", label: "国产企业2" }, { id: "blank-3", label: "国产企业3" }, { id: "blank-4", label: "国产企业4" }, { id: "blank-5", label: "国产企业5" }, ], }, // { // id: "quiz-4", // time: 467, // 7:47 // title: "题目4", // prompt: // '当年现在的中职教育一直在"因时求变",许多专业的新增和关联正确的是( )。', // type: "multiple", // options: [ // { value: "A", label: "汽修专业→学新能源汽车检测与维修", isCorrect: true }, // { // value: "B", // label: "会计专业→要掌握大数据财务和智能记账", // isCorrect: true, // }, // { value: "C", label: "国货推销→跨境电商、直播带货", isCorrect: true }, // { // value: "D", // label: "美术设计与制作→影像与影视技术", // }, // ], // explanation: // "美术设计与制作专业侧重于平面设计,而影像与影视技术专业侧重于影视特效后期,两者的专业核心课程涉及的软硬件也有差异", // }, ]; const HuangyanpeiInternalization = () => { const navigate = useNavigate(); const { moduleName } = useParams<{ moduleName: string }>(); const { triggerPuzzleAnimation } = usePuzzleAnimation(); const [narrationVisible, setNarrationVisible] = useState(false); const [activeSuccess, setActiveSuccess] = useState(null); const [successContent, setSuccessContent] = useState(""); const [resumeCallback, setResumeCallback] = useState<(() => void) | null>( null ); const [dragQuizValues, setDragQuizValues] = useState< Record >({}); const [dragQuizErrors, setDragQuizErrors] = useState>( {} ); const [visible, setVisible] = useState(false); const [showVideo, setShowVideo] = useState(false); const [postGuideVisible, setPostGuideVisible] = useState(false); const [showLetter, setShowLetter] = useState(false); const [showLetterVideo, setShowLetterVideo] = useState(false); const [showStudyGuide, setShowStudyGuide] = useState(false); const videoRef = useRef(null); const letterVideoRef = useRef(null); const audioRef = useRef(null); useEffect(() => { setNarrationVisible(true); }, []); // 组件卸载时清理背景音乐 useEffect(() => { return () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current.currentTime = 0; } }; }, []); const handleVideoCanPlay = () => { if (showVideo && videoRef.current) { videoRef.current.play().catch((error) => { console.warn("视频播放失败:", error); }); } }; // 信件视频加载完成后自动播放 const handleLetterVideoCanPlay = () => { if (showLetterVideo && letterVideoRef.current) { letterVideoRef.current.play().catch((error) => { console.warn("信件视频播放失败:", error); }); } }; const anchors: VideoAnchor[] = useMemo( () => QUIZ_ANCHORS.map((item) => { const correctAnswers = item.options .filter((opt) => opt.isCorrect) .map((opt) => opt.value); // 拖拽题处理 if (item.type === "drag" && item.blanks) { return { id: item.id, time: item.time, once: true, afterResume: "remove", render: ({ resume }) => { const handleDragChange = (val: DragFillResult[]) => { setDragQuizValues((prev) => ({ ...prev, [item.id]: val })); setDragQuizErrors((prev) => ({ ...prev, [item.id]: "" })); // 特斯拉标签无法拖入答案框 const hasInvalidOption = val.some( (v) => v.optionValue === "特斯拉" ); if (hasInvalidOption) { setDragQuizErrors((prev) => ({ ...prev, [item.id]: "特斯拉为外资企业哦~", })); return; } if (val.length < item.blanks!.length) return; // 检查是否都是正确答案(排除特斯拉) const validAnswers = [ "比亚迪", "华为", "江南造船", "光明食品", "C919飞机", ]; const filledAnswers = val.map((v) => v.optionValue); const isCorrect = filledAnswers.every((answer) => validAnswers.includes(answer) ); if (isCorrect) { setActiveSuccess(item.id); setSuccessContent("回答正确,请继续探索。"); setResumeCallback(() => resume); } else { setDragQuizErrors((prev) => ({ ...prev, [item.id]: "再想一想,确保选择的都是中国国产企业/品牌~", })); } }; return ( <> ({ value: opt.value, label: opt.label, }))} blanks={item.blanks || []} value={dragQuizValues[item.id] || []} error={dragQuizErrors[item.id]} onChange={handleDragChange} /> { setActiveSuccess(null); setSuccessContent(""); setDragQuizValues((prev) => { const next = { ...prev }; delete next[item.id]; return next; }); setDragQuizErrors((prev) => { const next = { ...prev }; delete next[item.id]; return next; }); const cb = resumeCallback; setResumeCallback(null); cb?.(); triggerPuzzleAnimation(16); }} /> ); }, }; } // 多选题处理 if (item.type === "multiple") { return { id: item.id, time: item.time, once: true, afterResume: "remove", render: ({ resume }) => ( <> ({ value: opt.value, label: `${opt.value}. ${opt.label}`, }))} correctAnswer={correctAnswers} errorMessage={ item.explanation || "再思考一下,注意选择所有正确答案。" } onSubmit={(values: string[], isCorrect: boolean) => { if (isCorrect) { setActiveSuccess(item.id); setSuccessContent("回答正确,请继续探索。"); setResumeCallback(() => resume); } }} /> { setActiveSuccess(null); setSuccessContent(""); const cb = resumeCallback; setResumeCallback(null); cb?.(); }} /> ), }; } return { id: item.id, time: item.time, once: true, afterResume: "remove", render: () => null, }; }), [ activeSuccess, resumeCallback, successContent, dragQuizValues, dragQuizErrors, triggerPuzzleAnimation, ] ); if (!moduleName) return null; return (
{/* 离开按钮 */} navigate(`/${moduleName}/${starName}/home`)} /> { setNarrationVisible(false); setVisible(true); }} audioSrc={getPublicPath("audio/huangyanpei/mp3_huangyanpei_27.mp3")} text={`从川沙内史第的少年求学路,到中华职业教育社的拓荒征程,黄炎培先生用一生践行“教育救国”的初心,以“手脑并用”的理念为中国职业教育埋下火种。百年后的今天,这颗火种已长成燎原之势,照亮无数中职学子的成才之路。站在新时代的门槛上,我们回望先生的足迹,不仅是缅怀一段历史,更是要让“职教兴国”的精神,成为当代青年成长的指引。`} animationSpeed={200} /> {/* 内化结束后的背景音乐 */}
); }; export default HuangyanpeiInternalization;