"use client"; import { useState, useEffect } from "react"; import { BookOpen } from "lucide-react"; import { courseContentAPI } from "@/lib/api"; interface Subsection { id: number; subsection_number: number; title: string; display_order: number; } interface Section { id: number; section_number: number; title: string; display_order: number; subsections: Subsection[]; } interface Chapter { id: number; chapter_number: number; title: string; display_order: number; sections: Section[]; } export default function CourseAdminPage() { const [chapters, setChapters] = useState([]); const [expanded, setExpanded] = useState>(new Set()); const [loading, setLoading] = useState(true); useEffect(() => { courseContentAPI.getCourseContent() .then((data) => setChapters(data.chapters || [])) .catch(console.error) .finally(() => setLoading(false)); }, []); const toggle = (key: string) => { setExpanded((prev) => { const next = new Set(prev); if (next.has(key)) next.delete(key); else next.add(key); return next; }); }; if (loading) { return
加载中...
; } const totalSections = chapters.reduce((a, c) => a + c.sections.length, 0); const totalSubsections = chapters.reduce( (a, c) => a + c.sections.reduce((b, s) => b + s.subsections.length, 0), 0 ); return (

课程内容管理

{chapters.length}
{totalSections}
{totalSubsections}
知识点
{chapters.length === 0 ? (
暂无课程内容数据
) : (
{chapters.map((chapter) => { const chKey = `ch-${chapter.id}`; return (
{expanded.has(chKey) && (
{chapter.sections.map((section) => { const secKey = `sec-${section.id}`; return (
{expanded.has(secKey) && section.subsections.length > 0 && (
{section.subsections.map((sub) => (
{sub.subsection_number} {sub.title}
))}
)}
); })}
)}
); })}
)}
); }