fix: refine home animation embed layout
This commit is contained in:
parent
5568325a0d
commit
e5a07fa022
@ -1,3 +1,6 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
type HomeAnimationEmbedProps = {
|
type HomeAnimationEmbedProps = {
|
||||||
@ -15,6 +18,23 @@ export function HomeAnimationEmbed({
|
|||||||
className,
|
className,
|
||||||
frameClassName,
|
frameClassName,
|
||||||
}: HomeAnimationEmbedProps) {
|
}: HomeAnimationEmbedProps) {
|
||||||
|
const [interactive, setInteractive] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!interactive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
setInteractive(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
}, [interactive]);
|
||||||
|
|
||||||
if (!htmlContent.trim()) {
|
if (!htmlContent.trim()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -25,6 +45,7 @@ export function HomeAnimationEmbed({
|
|||||||
"overflow-hidden rounded-[24px] border border-black/10 bg-white shadow-[0_10px_24px_rgba(0,0,0,0.05)]",
|
"overflow-hidden rounded-[24px] border border-black/10 bg-white shadow-[0_10px_24px_rgba(0,0,0,0.05)]",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
|
onMouseLeave={() => setInteractive(false)}
|
||||||
>
|
>
|
||||||
{title || description ? (
|
{title || description ? (
|
||||||
<div className="flex items-start justify-between gap-4 border-b border-black/8 px-4 py-3">
|
<div className="flex items-start justify-between gap-4 border-b border-black/8 px-4 py-3">
|
||||||
@ -36,17 +57,56 @@ export function HomeAnimationEmbed({
|
|||||||
<div className="mt-1 text-[12px] text-black/45">{description}</div>
|
<div className="mt-1 text-[12px] text-black/45">{description}</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={cn(
|
||||||
|
"inline-flex h-8 items-center rounded-full px-3 text-[12px] font-medium transition-colors",
|
||||||
|
interactive
|
||||||
|
? "bg-black text-white hover:bg-black/85"
|
||||||
|
: "border border-black/10 bg-white text-black/65 hover:bg-black/5",
|
||||||
|
)}
|
||||||
|
onClick={() => setInteractive((value) => !value)}
|
||||||
|
>
|
||||||
|
{interactive ? "退出互动" : "进入互动"}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div className={cn("h-[360px] w-full bg-[#f6f6f6] md:h-[420px]", frameClassName)}>
|
<div
|
||||||
|
className={cn(
|
||||||
|
"relative h-[360px] w-full bg-[#f6f6f6] md:h-[420px]",
|
||||||
|
frameClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<iframe
|
<iframe
|
||||||
title={title || "首页互动动画"}
|
title={title || "首页互动动画"}
|
||||||
srcDoc={htmlContent}
|
srcDoc={htmlContent}
|
||||||
sandbox="allow-scripts allow-forms allow-pointer-lock"
|
sandbox="allow-scripts allow-forms allow-pointer-lock"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
className="h-full w-full border-0"
|
className={cn(
|
||||||
|
"h-full w-full border-0 transition-opacity",
|
||||||
|
interactive ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-95",
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{!interactive ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-white/12 backdrop-blur-[1px]"
|
||||||
|
onClick={() => setInteractive(true)}
|
||||||
|
>
|
||||||
|
<span className="rounded-full bg-white/92 px-4 py-2 text-[13px] font-medium text-black shadow-sm">
|
||||||
|
点击进入互动
|
||||||
|
</span>
|
||||||
|
<span className="text-[12px] text-black/55">
|
||||||
|
默认保留页面滚动,进入互动后可拖拽和滚轮操作,按 `Esc` 或移出模块退出
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div className="pointer-events-none absolute bottom-3 right-3 rounded-full bg-black/70 px-3 py-1 text-[11px] text-white">
|
||||||
|
互动中
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1752,12 +1752,8 @@ export function LovartHome({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{homeAnimationData?.enabled && homeAnimationData?.htmlContent ? (
|
{homeAnimationData?.enabled && homeAnimationData?.htmlContent ? (
|
||||||
<div className="mx-auto mt-6 w-full max-w-[780px]">
|
<div className="mt-8 w-full">
|
||||||
<HomeAnimationEmbed
|
<HomeAnimationEmbed htmlContent={homeAnimationData.htmlContent} />
|
||||||
htmlContent={homeAnimationData.htmlContent}
|
|
||||||
title="互动演示"
|
|
||||||
description="支持拖拽、滚轮与实时交互,模块内容可在系统设置中替换 HTML 更新。"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user