nomadro/components/sections/hero.tsx
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 23:52:00 -05:00

435 lines
12 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import Link from "next/link";
import { useEffect, useRef } from "react";
import { ThemeToggle } from "~/components/theme-toggle";
import { useRemoteConfig } from "~/lib/use-remote-config";
/**
* External jump targets — kept for later re-enable, currently shielded.
* Flip EXTERNAL_JUMP_ENABLED to true to restore off-site links.
*/
const EXTERNAL_JUMP_ENABLED = false;
const EXTERNAL_PORTALS = {
nav: "https://nav.hackrobot.cn/",
book: "https://nomadweb.nomadro.com/book",
community: "https://nomadweb.nomadro.com",
vip: "https://vip.hackrobot.cn/",
} as const;
const INTERNAL_PORTALS = {
nav: "/nav",
book: "/book",
community: "/community",
vip: "/vip",
} as const;
/** 公开入口:不含收费会员页(深链 / 开发快捷另开) */
const PORTALS = [
{
id: "nav" as const,
moduleKey: "nav" as const,
emoji: "🧭",
name: "出海导航",
main: false,
},
{
id: "book" as const,
moduleKey: "book" as const,
emoji: "📖",
name: "数字游民小册",
main: false,
},
{
id: "community" as const,
moduleKey: "community" as const,
emoji: "🌏",
name: "旅居社群",
main: true,
},
];
function LogoIcon() {
return (
<svg className="hub-logo-icon" viewBox="0 0 40 40" fill="none" aria-hidden>
<circle cx="20" cy="20" r="18" stroke="url(#hubLogoGrad)" strokeWidth="2.5" />
<path
d="M12 22c4-8 12-8 16 0"
stroke="url(#hubLogoGrad)"
strokeWidth="2"
strokeLinecap="round"
/>
<circle cx="28" cy="14" r="3" fill="url(#hubLogoGrad)" />
<defs>
<linearGradient id="hubLogoGrad" x1="0" y1="0" x2="40" y2="40">
<stop offset="0%" stopColor="#FF6B6B" />
<stop offset="50%" stopColor="#FFE66D" />
<stop offset="100%" stopColor="#4ECDC4" />
</linearGradient>
</defs>
</svg>
);
}
function GlobeVisual() {
return (
<div className="hub-globe-container">
<svg
className="hub-globe-svg"
viewBox="0 0 400 400"
xmlns="http://www.w3.org/2000/svg"
aria-hidden
>
<defs>
<radialGradient id="hubGlobeGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" stopColor="#4ECDC4" stopOpacity="0.3" />
<stop offset="100%" stopColor="#4ECDC4" stopOpacity="0" />
</radialGradient>
<linearGradient id="hubOrbitGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stopColor="#FF6B6B" />
<stop offset="100%" stopColor="#4ECDC4" />
</linearGradient>
</defs>
<circle cx="200" cy="200" r="160" fill="url(#hubGlobeGlow)" />
<circle
cx="200"
cy="200"
r="120"
fill="none"
stroke="rgba(78,205,196,0.2)"
strokeWidth="1"
/>
<circle
cx="200"
cy="200"
r="90"
fill="none"
stroke="rgba(78,205,196,0.15)"
strokeWidth="1"
/>
<ellipse
cx="200"
cy="200"
rx="120"
ry="40"
fill="none"
stroke="rgba(78,205,196,0.3)"
strokeWidth="1.5"
className="hub-orbit-ring"
/>
<ellipse
cx="200"
cy="200"
rx="40"
ry="120"
fill="none"
stroke="rgba(255,107,107,0.3)"
strokeWidth="1.5"
className="hub-orbit-ring hub-orbit-ring-2"
/>
<path
d="M160 140 Q180 130 200 135 Q220 128 240 140 Q250 155 245 170 Q235 185 220 190 Q200 195 185 188 Q165 180 160 165 Z"
fill="rgba(78,205,196,0.4)"
className="hub-continent"
/>
<path
d="M130 210 Q145 200 160 215 Q155 235 140 240 Q125 235 130 210 Z"
fill="rgba(78,205,196,0.3)"
className="hub-continent"
/>
<path
d="M250 200 Q270 195 280 210 Q275 230 260 235 Q245 228 250 200 Z"
fill="rgba(78,205,196,0.35)"
className="hub-continent"
/>
<circle cx="180" cy="155" r="5" fill="#FF6B6B" className="hub-pulse-dot" />
<circle cx="260" cy="215" r="5" fill="#FFE66D" className="hub-pulse-dot" />
<circle cx="145" cy="225" r="5" fill="#4ECDC4" className="hub-pulse-dot" />
<path
d="M180 155 Q220 140 260 215"
fill="none"
stroke="url(#hubOrbitGrad)"
strokeWidth="2"
strokeDasharray="6 4"
className="hub-flight-path"
/>
</svg>
<div className="hub-floating-cards" aria-hidden>
<div className="hub-float-card hub-fc-1">🏝️ 巴厘岛</div>
<div className="hub-float-card hub-fc-2">☕ 里斯本</div>
<div className="hub-float-card hub-fc-3">🏔️ 清迈</div>
</div>
</div>
);
}
function ParticleCanvas() {
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext("2d");
if (!ctx) return;
let particles: {
x: number;
y: number;
r: number;
vx: number;
vy: number;
a: number;
}[] = [];
let w = 0;
let h = 0;
let raf = 0;
let running = true;
const resize = () => {
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
const n = Math.min(60, Math.floor((w * h) / 22000));
particles = Array.from({ length: n }, () => ({
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.6 + 0.4,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
a: Math.random() * 0.4 + 0.15,
}));
};
const draw = () => {
if (!running) return;
ctx.clearRect(0, 0, w, h);
particles.forEach((p, i) => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > w) p.vx *= -1;
if (p.y < 0 || p.y > h) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255,255,255,${p.a})`;
ctx.fill();
for (let j = i + 1; j < particles.length; j++) {
const q = particles[j]!;
const d = Math.hypot(p.x - q.x, p.y - q.y);
if (d < 110) {
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(q.x, q.y);
ctx.strokeStyle = `rgba(78,205,196,${0.16 * (1 - d / 110)})`;
ctx.stroke();
}
}
});
raf = requestAnimationFrame(draw);
};
resize();
draw();
window.addEventListener("resize", resize);
return () => {
running = false;
cancelAnimationFrame(raf);
window.removeEventListener("resize", resize);
};
}, []);
return (
<canvas
ref={canvasRef}
id="particle-canvas"
className="hub-particle-canvas"
aria-hidden
/>
);
}
function HubLoader() {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const hide = () => ref.current?.classList.add("hidden");
const onLoad = () => setTimeout(hide, 1200);
const fallback = setTimeout(hide, 2200);
if (document.readyState === "complete") {
onLoad();
} else {
window.addEventListener("load", onLoad);
}
return () => {
clearTimeout(fallback);
window.removeEventListener("load", onLoad);
};
}, []);
return (
<div className="hub-loader" ref={ref} id="loader">
<div className="hub-loader-inner">
<svg className="hub-loader-globe" viewBox="0 0 80 80" fill="none" aria-hidden>
<circle
cx="40"
cy="40"
r="35"
stroke="url(#hubLoaderGrad)"
strokeWidth="3"
strokeDasharray="60 160"
className="hub-loader-ring"
/>
<defs>
<linearGradient id="hubLoaderGrad" x1="0" y1="0" x2="80" y2="80">
<stop offset="0%" stopColor="#FF6B6B" />
<stop offset="100%" stopColor="#4ECDC4" />
</linearGradient>
</defs>
</svg>
<p className="hub-loader-text">nomadro</p>
</div>
</div>
);
}
export function Hero() {
const navRef = useRef<HTMLElement>(null);
const { config } = useRemoteConfig();
useEffect(() => {
const nav = navRef.current;
const onScroll = () =>
nav?.classList.toggle("scrolled", window.scrollY > 24);
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
const reveals = document.querySelectorAll(".hub-reveal");
let io: IntersectionObserver | null = null;
if ("IntersectionObserver" in window) {
io = new IntersectionObserver(
(entries) => {
entries.forEach((e) => {
if (e.isIntersecting) {
e.target.classList.add("visible");
io?.unobserve(e.target);
}
});
},
{ threshold: 0.12 },
);
reveals.forEach((el) => io!.observe(el));
} else {
reveals.forEach((el) => el.classList.add("visible"));
}
return () => {
window.removeEventListener("scroll", onScroll);
io?.disconnect();
};
}, []);
const portals = PORTALS.filter((p) => {
const mod = config.modules[p.moduleKey];
return mod?.enabled !== false;
});
return (
<div className="hub-root">
<HubLoader />
<ParticleCanvas />
<header className="hub-navbar" id="navbar" ref={navRef}>
<div className="hub-nav-container">
<a href="/" className="hub-logo">
<LogoIcon />
<span>{config.copy.homeBrand || "nomadro"}</span>
</a>
<div className="hub-nav-actions">
{process.env.NODE_ENV === "development" ? (
<nav className="hub-dev-nav" aria-label="本地开发快捷入口">
<Link className="hub-dev-link" href="/vip">
VIP
</Link>
<Link className="hub-dev-link" href="/admin">
Admin
</Link>
<Link className="hub-dev-link" href="/admin/config">
Config
</Link>
</nav>
) : null}
<ThemeToggle />
</div>
</div>
</header>
<main>
<section className="hub-hero">
<div className="hub-hero-bg-shapes" aria-hidden>
<div className="hub-shape hub-shape-1" />
<div className="hub-shape hub-shape-2" />
<div className="hub-shape hub-shape-3" />
</div>
<div className="hub-hero-inner">
<h1 className="hub-hero-title hub-reveal">
随处工作
<br />
<span className="hub-gradient-text">自由生活</span>
</h1>
<div className="hub-hero-visual hub-reveal">
<GlobeVisual />
</div>
<div className="hub-portal-grid hub-reveal">
{portals.map((portal) => {
const href = EXTERNAL_JUMP_ENABLED
? EXTERNAL_PORTALS[portal.id]
: INTERNAL_PORTALS[portal.id];
const className = `hub-portal-card${portal.main ? " hub-portal-card--main" : ""}`;
const name =
config.modules[portal.moduleKey]?.title || portal.name;
const body = (
<>
<span className="hub-portal-ico" aria-hidden>
{portal.emoji}
</span>
<span className="hub-portal-name">{name}</span>
</>
);
if (EXTERNAL_JUMP_ENABLED) {
return (
<a
key={portal.id}
className={className}
href={href}
target="_blank"
rel="noopener noreferrer"
>
{body}
</a>
);
}
return (
<Link key={portal.id} className={className} href={href}>
{body}
</Link>
);
})}
</div>
</div>
</section>
</main>
</div>
);
}