- 修复6月17日单元小结归属问题,正确归入商业设计基础单元 - 添加单元海报功能,非直播状态显示单元海报图片 - 更新首页Dashboard开始上课和当日事项板块数据 - 实现课程数据与Dashboard数据自动同步 - 优化课程列表显示,包含完整100门课程数据 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
94 lines
2.9 KiB
JavaScript
94 lines
2.9 KiB
JavaScript
import { useState, useEffect } from "react";
|
|
import StartClass from "./components/StartClass";
|
|
import QuickAccess from "./components/QuickAccess";
|
|
import CalendarTaskModule from "./components/CalendarTaskModule";
|
|
import StudyStatus from "./components/StudyStatus";
|
|
import ClassRank from "@/components/ClassRank";
|
|
import StageProgress from "@/components/StageProgress";
|
|
import TaskList from "./components/TaskList";
|
|
import { getDashboardStatistics } from "@/services";
|
|
import "./index.css";
|
|
|
|
const Dashboard = () => {
|
|
const [dashboardData, setDashboardData] = useState(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [selectedDate, setSelectedDate] = useState(new Date());
|
|
|
|
useEffect(() => {
|
|
fetchDashboardData();
|
|
}, []);
|
|
|
|
// 获取仪表板完整数据
|
|
const fetchDashboardData = async () => {
|
|
try {
|
|
setLoading(true);
|
|
const response = await getDashboardStatistics();
|
|
if (response && response.success) {
|
|
setDashboardData(response.data);
|
|
} else if (response) {
|
|
// 兼容直接返回数据的情况
|
|
setDashboardData(response);
|
|
}
|
|
} catch (error) {
|
|
console.error("Failed to fetch dashboard data:", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
// 根据选中日期筛选任务
|
|
const getTasksForDate = (date) => {
|
|
if (!dashboardData?.tasks?.allTasks) return [];
|
|
// Check if date is valid before calling toISOString
|
|
if (!date || isNaN(date.getTime())) {
|
|
console.warn("Invalid date provided to getTasksForDate:", date);
|
|
return [];
|
|
}
|
|
const dateStr = date.toISOString().split("T")[0];
|
|
return dashboardData.tasks.allTasks.filter((task) => task.date === dateStr);
|
|
};
|
|
|
|
return (
|
|
<div className="dashboard">
|
|
<StageProgress showBlockageAlert={true} />
|
|
|
|
<div className="dashboard-wrapper">
|
|
<div className="dashboard-left-content">
|
|
<StartClass
|
|
courses={dashboardData?.courses}
|
|
tasks={dashboardData?.tasks}
|
|
loading={loading}
|
|
/>
|
|
<QuickAccess />
|
|
<div className="status-rank-wrapper">
|
|
<StudyStatus
|
|
progress={dashboardData?.overview?.overallProgress}
|
|
loading={loading}
|
|
/>
|
|
<ClassRank
|
|
className="class-rank-wrapper"
|
|
data={
|
|
dashboardData?.ranking
|
|
? {
|
|
rankings: dashboardData.ranking.topStudents,
|
|
}
|
|
: null
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="dashboard-right-content">
|
|
<CalendarTaskModule
|
|
tasks={dashboardData?.tasks?.allTasks}
|
|
selectedDate={selectedDate}
|
|
onDateChange={setSelectedDate}
|
|
/>
|
|
<TaskList tasks={getTasksForDate(selectedDate)} loading={loading} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Dashboard;
|