Files
shanghai-residences/src/pages/sunzhongshan/place/place4.tsx
T
2025-12-29 19:19:10 +08:00

102 lines
2.9 KiB
TypeScript

import { useState } from "react";
import { ExhibitOverlay, Title, Image, Cursor } from "@/components";
import { getBackgroundImage, getStaticImage } from "@/lib/utils";
import { useNavigate, useParams } from "react-router-dom";
const starName = "sunzhongshan";
const exhibitSrcMap: Record<1 | 2, string> = {
1: "sunzhongshan/place4/国事遗嘱",
2: "sunzhongshan/place4/上海各界人士在外滩码头欢迎孙中山",
};
const SunzhongshanPlace4 = () => {
const navigate = useNavigate();
const { moduleName } = useParams<{
moduleName: string;
}>();
const [activeExhibitId, setActiveExhibitId] = useState<1 | 2 | null>(null);
const [visited, setVisited] = useState<Set<number>>(new Set());
const handleOpenExhibit = (index: 1 | 2) => {
setActiveExhibitId(index);
};
const progressCount = visited.size;
const total = 2;
const completed = progressCount >= total;
const subtitle = completed
? "探索孙中山故居老宅堂屋(已完成)"
: `探索孙中山故居老宅堂屋(${progressCount}/${total})`;
const subtitleClassName = completed
? "text-[#fff998] [text-shadow:_0_8px_8px_rgba(0,0,0,0.35),_0_0_16px_rgba(0,0,0,0.25)]"
: undefined;
return (
<div
className="w-full h-full bg-cover bg-center bg-no-repeat"
style={{
backgroundImage: getBackgroundImage(`sunzhongshan/place4/背景`),
}}
>
<Title
title="抱病北上·鞠躬尽瘁"
subtitle={subtitle}
subtitleClassName={subtitleClassName}
className="absolute top-10 left-1/2 -translate-x-1/2"
/>
<Image
className="absolute right-5 top-5"
src={getStaticImage("components/离开")}
button
onClick={() => {
if (moduleName && starName) {
navigate(`/${moduleName}/${starName}/place3`);
}
}}
/>
<Cursor
className="absolute right-209 top-128"
onClick={() => handleOpenExhibit(1)}
read={visited.has(1)}
/>
<Cursor
className="absolute right-150 top-88"
onClick={() => handleOpenExhibit(2)}
read={visited.has(2)}
/>
{completed && (
<Image
className="absolute bottom-0 right-140"
src={getStaticImage("components/place/l-前进")}
button
onClick={() => {
navigate(`/${moduleName}/${starName}`);
}}
/>
)}
<ExhibitOverlay
visible={activeExhibitId !== null}
src={activeExhibitId ? exhibitSrcMap[activeExhibitId] : ""}
onClose={() => {
if (activeExhibitId !== null) {
setVisited((prev) => {
const next = new Set(prev);
next.add(activeExhibitId);
return next;
});
}
setActiveExhibitId(null);
}}
/>
</div>
);
};
export default SunzhongshanPlace4;