import { useEffect, useMemo, useState, useRef } from 'react' import { useNavigate, useParams } from 'react-router-dom' import { Image, Video, type VideoAnchor, type VideoRef, type DragFillResult, SingleChoiceQuizPanel, 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' import { setCourseTimeProgress } from '@/lib/utils/api-common' type QuizOption = { value: string label: string isCorrect?: boolean explanation?: string } type QuizAnchor = { id: string time: number title: string prompt?: string promptSuffix?: string type: 'single' | 'multiple' | 'drag' options: QuizOption[] blanks?: { id: string; label: string }[] blankPrefixes?: string[] blankSeparators?: string[] explanation?: string } const starName = 'huangyanpei' // 锚点数据:根据视频时长调整 time const QUIZ_ANCHORS: QuizAnchor[] = [ { id: 'quiz-1', time: 96, // 1:36 title: '', prompt: '【单选】黄炎培先生提出“双手万能、手脑并用”的职业教育的学习方式、教学原则的主要原因是:', type: 'single', options: [ { value: 'A', label: '解决旧教育脱离生产劳动、人才供需错配的问题', isCorrect: true }, { value: 'B', label: '鼓励学生只专注于动手劳动,放弃文化学习', explanation: '黄炎培的主张是“要使动的读书,读书的动手”,强调动手与读书相结合,并非让学生放弃文化学习。请你再想想吧!', }, { value: 'C', label: '为了完全照搬西方职业教育模式', explanation: '这一原则是针对中国旧教育的弊端和当时民族工业的实际需求提出的本土化理念。请你再想想吧!', }, { value: 'D', label: '迎合传统旧式教育的理念', explanation: '这一原则是为了解决旧教育严重脱离生产劳动的弊端。请你再想想吧!', }, ], explanation: '黄炎培提出“双手万能、手脑并用”是为了让学生既具备文化知识,又掌握实践技能,解决人才供需错配的矛盾。', }, { id: 'quiz-2b', time: 177, // 2:56 title: '', prompt: '【拖拽】黄炎培先生认为,职业学校的办学宗旨是“', promptSuffix: '”。', type: 'drag', options: [ { value: '有业', label: '有业' }, { value: '乐业', label: '乐业' }, { value: '就业', label: '就业' }, ], blanks: [ { id: 'blank-1', label: '___' }, { id: 'blank-2', label: '___' }, ], blankPrefixes: ['使无业者', '使有业者'], blankSeparators: [','], explanation: '正确答案为“使无业者有业,使有业者乐业”。', }, { id: 'quiz-4', time: 261, // 4:20 title: '', prompt: '【多选】黄炎培先生认为职业教育的目的是___,简称“四个准备”。', type: 'multiple', options: [ { value: 'A', label: '谋个性之发展,为个人谋生之准备', isCorrect: true, }, { value: 'B', label: '为个人服务社会之准备', isCorrect: true, }, { value: 'C', label: '为国家及世界增进生产力之准备', isCorrect: true, }, ], explanation: '你的选择还不够全面哦~请你再想想吧!', }, { id: 'quiz-2', time: 221, // 3:41 title: '', 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: 369, // 6:09 title: '', 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' }, ], }, ] 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>({}) 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 [showStudyGuide, setShowStudyGuide] = useState(false) const videoRef = useRef(null) useEffect(() => { setNarrationVisible(true) }, []) const handleVideoCanPlay = () => { if (showVideo && videoRef.current) { videoRef.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]: '' })) // 第 2 题:必须按顺序填入“有业”“乐业” if (item.id === 'quiz-2b') { const orderedAnswers = ['有业', '乐业'] const isCorrect = val.length === orderedAnswers.length && orderedAnswers.every((answer, index) => val[index]?.optionValue === answer) if (isCorrect) { setActiveSuccess(item.id) setSuccessContent('') setResumeCallback(() => resume) } else { setDragQuizErrors((prev) => ({ ...prev, [item.id]: item.explanation || '请你再想想吧!', })) } return } // 特斯拉标签无法拖入答案框 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 || []} blankPrefixes={item.blankPrefixes} 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 }) if (item.id === 'quiz-3') { triggerPuzzleAnimation(16) } const cb = resumeCallback setResumeCallback(null) cb?.() }} /> ) }, } } // 单选题处理 if (item.type === 'single') { return { id: item.id, time: item.time, once: true, afterResume: 'remove', render: ({ resume }) => ( <> ({ value: opt.value, label: `${opt.value}. ${opt.label}`, }))} correctAnswer={correctAnswers[0] || ''} onWrongSelect={(value) => { const selected = item.options.find((opt) => opt.value === value) return selected?.explanation || item.explanation || '请再想想吧!' }} onSubmit={(_value, isCorrect) => { if (isCorrect) { setActiveSuccess(item.id) setSuccessContent('') setResumeCallback(() => resume) } }} /> { setActiveSuccess(null) setSuccessContent('') const cb = resumeCallback setResumeCallback(null) cb?.() }} /> ), } } // 多选题处理 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} /> {showVideo && (
) } export default HuangyanpeiInternalization