{
// 如果图片加载失败,显示原始文本
e.currentTarget.style.display = "none";
const textNode = document.createTextNode(`[${part.name}]`);
e.currentTarget.parentNode?.insertBefore(textNode, e.currentTarget);
}}
/>
);
})}
>
);
}
type VideoData = {
type: "video";
aweme_id: string;
desc: string;
created_at: string | Date;
duration_ms?: number | null;
video_url: string;
width?: number | null;
height?: number | null;
author: User;
comments: Comment[];
};
type ImageData = {
type: "image";
aweme_id: string;
desc: string;
created_at: string | Date;
images: { id: string; url: string; width?: number; height?: number }[];
music_url?: string | null;
author: User;
comments: Comment[];
};
const SEGMENT_MS = 5000; // 图文每段 5s
type Neighbors = { prev: { aweme_id: string } | null; next: { aweme_id: string } | null };
export default function AwemeDetailClient(props: { data: VideoData | ImageData; neighbors?: Neighbors }) {
const { data, neighbors } = props;
const isVideo = data.type === "video";
const router = useRouter();
// ====== 布局 & 评论 ======
const [open, setOpen] = useState(() => {
// 从 localStorage 读取评论区状态,默认 false
if (typeof window === "undefined") return false;
const saved = localStorage.getItem("aweme_player_comments_open");
if (!saved) return false;
return saved === "true";
}); // 评论是否展开(竖屏为 bottom sheet;横屏为并排分栏)
const comments = useMemo(() => data.comments ?? [], [data]);
// ====== 媒体引用 ======
const mediaContainerRef = useRef{data.desc}