From b09943773875c50aea3ff784d765efac3b167655 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 27 Mar 2026 19:35:39 -0500 Subject: [PATCH] 's' --- app/HomeClient.tsx | 3 +- app/HomeClientLoader.tsx | 5 +-- app/components/HomePageSkeleton.tsx | 63 +++++++++++++++++++++++++++++ app/https-upgrade.ts | 12 ++++++ app/layout.tsx | 2 + app/page.tsx | 13 +++++- middleware.ts | 32 +++++++++++++++ 7 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 app/components/HomePageSkeleton.tsx create mode 100644 app/https-upgrade.ts create mode 100644 middleware.ts diff --git a/app/HomeClient.tsx b/app/HomeClient.tsx index e845f42..b5658a3 100644 --- a/app/HomeClient.tsx +++ b/app/HomeClient.tsx @@ -1,6 +1,7 @@ "use client"; import { useCallback, useEffect, useState } from "react"; +import { HomePageSkeleton } from "@/app/components/HomePageSkeleton"; import { triggerPay } from "@/app/lib/triggerPay"; import { getPayEnv, getDeviceFromEnv } from "@/app/lib/payEnv"; import { usePayStatusPoll } from "@/app/lib/usePayStatusPoll"; @@ -753,7 +754,7 @@ export default function HomeClient() { /> ) : ( -
+ )} diff --git a/app/HomeClientLoader.tsx b/app/HomeClientLoader.tsx index 408e1a2..3d7f80d 100644 --- a/app/HomeClientLoader.tsx +++ b/app/HomeClientLoader.tsx @@ -1,12 +1,11 @@ "use client"; import dynamic from "next/dynamic"; +import { HomePageSkeleton } from "./components/HomePageSkeleton"; const HomeClient = dynamic(() => import("./HomeClient"), { ssr: false, - loading: () => ( -
- ), + loading: () => , }); export function HomeClientLoader() { diff --git a/app/components/HomePageSkeleton.tsx b/app/components/HomePageSkeleton.tsx new file mode 100644 index 0000000..f6c17b8 --- /dev/null +++ b/app/components/HomePageSkeleton.tsx @@ -0,0 +1,63 @@ +function SkeletonBlocks() { + return ( +
+
+
+
+
+
+
+
+
+
+
+
+
+ ); +} + +type HomePageSkeletonProps = { + className?: string; + /** full:整页含顶栏;main:仅主内容区(已包在 VipLayout 内时用) */ + variant?: "full" | "main"; +}; + +/** + * 首页骨架(Server/Client 均可引用),保证首屏 HTML 即有可见结构,避免白屏。 + */ +export function HomePageSkeleton({ + className = "", + variant = "full", +}: HomePageSkeletonProps) { + const main = ( +
+ +
+ ); + + if (variant === "main") { + return ( +
+ {main} +
+ ); + } + + return ( +
+
+
+
+
+ {main} +
+ ); +} diff --git a/app/https-upgrade.ts b/app/https-upgrade.ts new file mode 100644 index 0000000..9d1180a --- /dev/null +++ b/app/https-upgrade.ts @@ -0,0 +1,12 @@ +/** + * 微信等环境可能以 http 打开 vip 域名,导致 Cookie/支付与 https 不一致。 + * 在任意 JS 执行前立即跳转到 https(middleware 之外的兜底)。 + */ +export const httpsUpgradeScript = ` +(function(){ + var h=location.hostname; + if(h!=="vip.hackrobot.cn"&&h!=="www.vip.hackrobot.cn")return; + if(location.protocol!=="http:")return; + location.replace("https://"+h+location.pathname+location.search+location.hash); +})(); +`; diff --git a/app/layout.tsx b/app/layout.tsx index 657dd82..b5b9ee4 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import "./globals.css"; import { ThemeProvider } from "./providers/ThemeProvider"; +import { httpsUpgradeScript } from "./https-upgrade"; import { themeInitScript } from "./theme-init"; export const metadata: Metadata = { @@ -16,6 +17,7 @@ export default function RootLayout({ return ( +