's'
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { HomePageSkeleton } from "@/app/components/HomePageSkeleton";
|
|
||||||
import { triggerPay } from "@/app/lib/triggerPay";
|
import { triggerPay } from "@/app/lib/triggerPay";
|
||||||
import { getPayEnv, getDeviceFromEnv } from "@/app/lib/payEnv";
|
import { getPayEnv, getDeviceFromEnv } from "@/app/lib/payEnv";
|
||||||
import { usePayStatusPoll } from "@/app/lib/usePayStatusPoll";
|
import { usePayStatusPoll } from "@/app/lib/usePayStatusPoll";
|
||||||
@@ -166,7 +165,10 @@ function readVipBootstrapState(): {
|
|||||||
return { paidType: null, userName: null, userEmail: null };
|
return { paidType: null, userName: null, userEmail: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 首页:init 完成前若尚未从本地恢复 VIP,不渲染落地页(避免 H5 reload 后先闪未解锁) */
|
/**
|
||||||
|
* 首页:首帧以 localStorage 为准展示 VIP 控制台或访客落地页;init 仅后台同步/校验,
|
||||||
|
* 仅在服务端明确「非 VIP」等异常时更新状态(见 verifyInBackground / probe)。
|
||||||
|
*/
|
||||||
export default function HomeClient() {
|
export default function HomeClient() {
|
||||||
const [paidType, setPaidType] = useState<string | null>(
|
const [paidType, setPaidType] = useState<string | null>(
|
||||||
() => readVipBootstrapState().paidType
|
() => readVipBootstrapState().paidType
|
||||||
@@ -178,7 +180,6 @@ export default function HomeClient() {
|
|||||||
() => readVipBootstrapState().userEmail
|
() => readVipBootstrapState().userEmail
|
||||||
);
|
);
|
||||||
const [payPendingOrderId, setPayPendingOrderId] = useState<string | null>(null);
|
const [payPendingOrderId, setPayPendingOrderId] = useState<string | null>(null);
|
||||||
const [initDone, setInitDone] = useState(false);
|
|
||||||
|
|
||||||
const savePaidType = useCallback((type: string | null) => {
|
const savePaidType = useCallback((type: string | null) => {
|
||||||
if (type) setStorage("paidType", type);
|
if (type) setStorage("paidType", type);
|
||||||
@@ -526,7 +527,6 @@ export default function HomeClient() {
|
|||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
if (urlParams.get("type")?.trim() === "clean") {
|
if (urlParams.get("type")?.trim() === "clean") {
|
||||||
clearAllStorage();
|
clearAllStorage();
|
||||||
setInitDone(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* paid=1 来自 URL 时不再无条件设置,需通过 confirm 或 PB 校验 */
|
/* paid=1 来自 URL 时不再无条件设置,需通过 confirm 或 PB 校验 */
|
||||||
@@ -661,13 +661,7 @@ export default function HomeClient() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void (async () => {
|
void init();
|
||||||
try {
|
|
||||||
await init();
|
|
||||||
} finally {
|
|
||||||
setInitDone(true);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}, [
|
}, [
|
||||||
clearAllStorage,
|
clearAllStorage,
|
||||||
getOrCreateUserId,
|
getOrCreateUserId,
|
||||||
@@ -737,24 +731,19 @@ export default function HomeClient() {
|
|||||||
}, [clearAllStorage]);
|
}, [clearAllStorage]);
|
||||||
|
|
||||||
const isLoggedIn = paidType === "vip";
|
const isLoggedIn = paidType === "vip";
|
||||||
const showGuestLanding = initDone && !isLoggedIn;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<VipLayout isLoggedIn={isLoggedIn} userName={userName} userEmail={userEmail} onLogout={handleLogout}>
|
<VipLayout isLoggedIn={isLoggedIn} userName={userName} userEmail={userEmail} onLogout={handleLogout}>
|
||||||
{isLoggedIn ? (
|
{isLoggedIn ? (
|
||||||
<DashboardPage userName={userName} userEmail={userEmail} />
|
<DashboardPage userName={userName} userEmail={userEmail} />
|
||||||
) : showGuestLanding ? (
|
|
||||||
<>
|
|
||||||
<LandingPage
|
|
||||||
onJoin={handlePay}
|
|
||||||
onVerify={checkPaymentFromPB}
|
|
||||||
onVerifyByEmail={checkVerifyByEmail}
|
|
||||||
onVerifySuccess={handleVerifySuccess}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<HomePageSkeleton variant="main" />
|
<LandingPage
|
||||||
|
onJoin={handlePay}
|
||||||
|
onVerify={checkPaymentFromPB}
|
||||||
|
onVerifyByEmail={checkVerifyByEmail}
|
||||||
|
onVerifySuccess={handleVerifySuccess}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</VipLayout>
|
</VipLayout>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { HomePageSkeleton } from "./components/HomePageSkeleton";
|
|
||||||
|
|
||||||
const HomeClient = dynamic(() => import("./HomeClient"), {
|
const HomeClient = dynamic(() => import("./HomeClient"), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
loading: () => <HomePageSkeleton />,
|
/** 仅纯色底,避免分包加载前白屏;真正 VIP/非 VIP 界面由 HomeClient 首帧同步读 localStorage 渲染 */
|
||||||
|
loading: () => (
|
||||||
|
<div className="min-h-screen bg-[var(--background)]" aria-hidden />
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function HomeClientLoader() {
|
export function HomeClientLoader() {
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
function SkeletonBlocks() {
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div className="mx-auto h-9 max-w-lg rounded-lg bg-[var(--muted)] animate-pulse" />
|
|
||||||
<div className="mx-auto h-[min(40vh,280px)] w-full max-w-3xl rounded-2xl bg-[var(--muted)]/70 animate-pulse" />
|
|
||||||
<div className="flex flex-wrap justify-center gap-3">
|
|
||||||
<div className="h-12 w-40 rounded-xl bg-[var(--muted)] animate-pulse" />
|
|
||||||
<div className="h-12 w-40 rounded-xl bg-[var(--muted)] animate-pulse" />
|
|
||||||
</div>
|
|
||||||
<div className="mx-auto mt-8 max-w-2xl space-y-3">
|
|
||||||
<div className="h-4 w-full rounded bg-[var(--muted)] animate-pulse" />
|
|
||||||
<div className="h-4 w-[90%] rounded bg-[var(--muted)] animate-pulse" />
|
|
||||||
<div className="h-4 w-[75%] rounded bg-[var(--muted)] animate-pulse" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type HomePageSkeletonProps = {
|
|
||||||
className?: string;
|
|
||||||
/** full:整页含顶栏;main:仅主内容区(已包在 VipLayout 内时用) */
|
|
||||||
variant?: "full" | "main";
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 首页骨架(Server/Client 均可引用),保证首屏 HTML 即有可见结构,避免白屏。
|
|
||||||
*/
|
|
||||||
export function HomePageSkeleton({
|
|
||||||
className = "",
|
|
||||||
variant = "full",
|
|
||||||
}: HomePageSkeletonProps) {
|
|
||||||
const main = (
|
|
||||||
<main className="mx-auto w-full max-w-[1200px] flex-1 px-4 py-8 sm:px-6">
|
|
||||||
<SkeletonBlocks />
|
|
||||||
</main>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (variant === "main") {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={`min-h-[50vh] bg-[var(--background)] text-[var(--foreground)] ${className}`}
|
|
||||||
aria-busy="true"
|
|
||||||
aria-label="页面加载中"
|
|
||||||
>
|
|
||||||
{main}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={`flex min-h-screen flex-col bg-[var(--background)] text-[var(--foreground)] ${className}`}
|
|
||||||
aria-busy="true"
|
|
||||||
aria-label="页面加载中"
|
|
||||||
>
|
|
||||||
<header className="flex items-center justify-between border-b border-[var(--border)] px-4 py-3 sm:px-6">
|
|
||||||
<div className="h-7 w-28 rounded-md bg-[var(--muted)] animate-pulse" />
|
|
||||||
<div className="h-9 w-24 rounded-lg bg-[var(--muted)] animate-pulse" />
|
|
||||||
</header>
|
|
||||||
{main}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
11
app/page.tsx
11
app/page.tsx
@@ -1,16 +1,9 @@
|
|||||||
import { HomePageSkeleton } from "./components/HomePageSkeleton";
|
|
||||||
import { HomeClientLoader } from "./HomeClientLoader";
|
import { HomeClientLoader } from "./HomeClientLoader";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen bg-[var(--background)]">
|
<div className="min-h-screen bg-[var(--background)]">
|
||||||
{/* SSR 即输出骨架,JS 未执行前也不白屏 */}
|
<HomeClientLoader />
|
||||||
<div className="pointer-events-none absolute inset-0 z-0 overflow-hidden">
|
|
||||||
<HomePageSkeleton />
|
|
||||||
</div>
|
|
||||||
<div className="relative z-[1] min-h-screen">
|
|
||||||
<HomeClientLoader />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user