1
This commit is contained in:
parent
f6e969f15c
commit
b5f277500f
@ -26,6 +26,8 @@ export default function DashboardPage() {
|
|||||||
const [selectedAnnouncement, setSelectedAnnouncement] = useState<Announcement | null>(null);
|
const [selectedAnnouncement, setSelectedAnnouncement] = useState<Announcement | null>(null);
|
||||||
const [selectedSchedule, setSelectedSchedule] = useState<ScheduleItem | null>(null);
|
const [selectedSchedule, setSelectedSchedule] = useState<ScheduleItem | null>(null);
|
||||||
const [now, setNow] = useState(() => Date.now());
|
const [now, setNow] = useState(() => Date.now());
|
||||||
|
const getScheduleDisplayTime = (item: ScheduleItem) =>
|
||||||
|
item.type === "deadline" && item.end_time ? item.end_time : item.start_time;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeClassId) return;
|
if (!activeClassId) return;
|
||||||
@ -63,10 +65,10 @@ export default function DashboardPage() {
|
|||||||
const countdownByScheduleId = useMemo(() => {
|
const countdownByScheduleId = useMemo(() => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
upcoming.map((item) => {
|
upcoming.map((item) => {
|
||||||
const diff = new Date(item.start_time).getTime() - now;
|
const diff = new Date(getScheduleDisplayTime(item)).getTime() - now;
|
||||||
const days = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
const days = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
||||||
const label =
|
const label =
|
||||||
days <= 0 ? "已开始" : days === 1 ? "明天" : `${days}天后`;
|
days <= 0 ? "已截止" : days === 1 ? "明天" : `${days}天后`;
|
||||||
return [item.id, label];
|
return [item.id, label];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -190,7 +192,7 @@ export default function DashboardPage() {
|
|||||||
<div>
|
<div>
|
||||||
<p className="text-sm font-medium text-[#4a1f1a]">{item.title}</p>
|
<p className="text-sm font-medium text-[#4a1f1a]">{item.title}</p>
|
||||||
<p className="text-xs text-[#866556]">
|
<p className="text-xs text-[#866556]">
|
||||||
{new Date(item.start_time).toLocaleDateString("zh-CN")}
|
{new Date(getScheduleDisplayTime(item)).toLocaleDateString("zh-CN")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -280,11 +282,44 @@ export default function DashboardPage() {
|
|||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1 text-sm text-[#7f6352]">
|
<div className="space-y-1 text-sm text-[#7f6352]">
|
||||||
<p>开始:{new Date(selectedSchedule.start_time).toLocaleString("zh-CN", { year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" })}</p>
|
{selectedSchedule.type === "deadline" ? (
|
||||||
{selectedSchedule.end_time && (
|
<p>
|
||||||
<p>结束:{new Date(selectedSchedule.end_time).toLocaleString("zh-CN", { year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" })}</p>
|
截止时间:
|
||||||
|
{new Date(getScheduleDisplayTime(selectedSchedule)).toLocaleString("zh-CN", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
开始:
|
||||||
|
{new Date(selectedSchedule.start_time).toLocaleString("zh-CN", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
{selectedSchedule.end_time && (
|
||||||
|
<p>
|
||||||
|
结束:
|
||||||
|
{new Date(selectedSchedule.end_time).toLocaleString("zh-CN", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{selectedSchedule.location && (
|
{selectedSchedule.type !== "deadline" && selectedSchedule.location && (
|
||||||
<p>地点:{selectedSchedule.location}</p>
|
<p>地点:{selectedSchedule.location}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user