feat: 全站 H5 响应式导航与可选 PWA 安装
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c258cb40af
commit
60ea916a4d
32
frontend/public/manifest.webmanifest
Normal file
32
frontend/public/manifest.webmanifest
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "直播监控中心",
|
||||
"short_name": "LiveRadar",
|
||||
"description": "抖音 + YouTube 直播监控 · Shorts / TikTok 分发",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"orientation": "any",
|
||||
"background_color": "#071018",
|
||||
"theme_color": "#071018",
|
||||
"lang": "zh-CN",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
46
frontend/public/sw.js
Normal file
46
frontend/public/sw.js
Normal file
@ -0,0 +1,46 @@
|
||||
/* Minimal service worker — enables installability; network-first for app/API. */
|
||||
const CACHE = "dylive-shell-v1";
|
||||
const PRECACHE = ["/", "/manifest.webmanifest", "/icon-192.png", "/icon-512.png", "/apple-touch-icon.png"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE).then((cache) => cache.addAll(PRECACHE)).then(() => self.skipWaiting()),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))),
|
||||
).then(() => self.clients.claim()),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const req = event.request;
|
||||
if (req.method !== "GET") return;
|
||||
const url = new URL(req.url);
|
||||
if (url.origin !== self.location.origin) return;
|
||||
// Never cache API / auth / SSE
|
||||
if (url.pathname.startsWith("/api/") || url.pathname.includes("event")) return;
|
||||
|
||||
event.respondWith(
|
||||
fetch(req)
|
||||
.then((res) => {
|
||||
const copy = res.clone();
|
||||
if (res.ok && (url.pathname.startsWith("/_next/static/") || PRECACHE.includes(url.pathname))) {
|
||||
caches.open(CACHE).then((cache) => cache.put(req, copy)).catch(() => {});
|
||||
}
|
||||
return res;
|
||||
})
|
||||
.catch(async () => {
|
||||
const hit = await caches.match(req);
|
||||
if (hit) return hit;
|
||||
if (req.mode === "navigate") {
|
||||
const home = await caches.match("/");
|
||||
if (home) return home;
|
||||
}
|
||||
throw new Error("offline");
|
||||
}),
|
||||
);
|
||||
});
|
||||
@ -307,7 +307,7 @@ export default function AnchorsPage() {
|
||||
</div>
|
||||
</div>
|
||||
{profile.schedule.slot_counts?.length === 6 ? (
|
||||
<div className="mt-3 grid grid-cols-6 gap-1">
|
||||
<div className="mt-3 grid grid-cols-3 gap-1 sm:grid-cols-6">
|
||||
{profile.schedule.slot_counts.map((n, i) => {
|
||||
const max = Math.max(1, ...profile.schedule!.slot_counts!);
|
||||
return (
|
||||
|
||||
@ -130,8 +130,8 @@ export default function BlacklistPage() {
|
||||
) : items.length === 0 ? (
|
||||
<EmptyState emoji="🚫" title="黑名单为空" desc="添加房间号、URL 或关键词后,命中项将自动停用并不再轮询。" />
|
||||
) : (
|
||||
<div className="overflow-hidden rounded-xl border border-white/10 bg-black/20">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<div className="table-scroll overflow-hidden rounded-xl border border-white/10 bg-black/20">
|
||||
<table className="min-w-[560px] w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
<th className="px-3 py-3">内容</th>
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
html,
|
||||
body {
|
||||
min-height: 100%;
|
||||
min-height: 100dvh;
|
||||
overflow-x: clip;
|
||||
}
|
||||
|
||||
body {
|
||||
@ -28,12 +30,84 @@ body {
|
||||
radial-gradient(700px 400px at 50% 100%, rgba(56, 189, 248, 0.06), transparent 60%),
|
||||
linear-gradient(160deg, #071018 0%, #0f1c2e 45%, #0a1422 100%);
|
||||
background-attachment: fixed;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
body {
|
||||
background-attachment: scroll;
|
||||
}
|
||||
.ambient-orb {
|
||||
opacity: 0.22;
|
||||
filter: blur(48px);
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ambient-orb,
|
||||
.animate-fade-up,
|
||||
.animate-fade-in,
|
||||
.stagger > *,
|
||||
.page-enter {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img,
|
||||
video,
|
||||
canvas,
|
||||
svg {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Edge-to-edge horizontal scroll for wide tables on phones */
|
||||
.table-scroll {
|
||||
margin-left: -0.75rem;
|
||||
margin-right: -0.75rem;
|
||||
padding-left: 0.75rem;
|
||||
padding-right: 0.75rem;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior-x: contain;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.table-scroll {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.touch-target {
|
||||
min-height: 2.75rem;
|
||||
min-width: 2.75rem;
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea,
|
||||
button {
|
||||
font-size: 16px; /* avoid iOS zoom on focus */
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
input,
|
||||
select,
|
||||
textarea,
|
||||
button {
|
||||
font-size: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: rgba(255, 45, 85, 0.35);
|
||||
color: #fff;
|
||||
|
||||
@ -496,7 +496,7 @@ export default function GroupsPage() {
|
||||
|
||||
<section className="overflow-hidden rounded-2xl border border-white/10 bg-black/25">
|
||||
<div className="border-b border-white/5 px-4 py-3 text-sm font-medium text-slate-100">频道排行</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
@ -546,7 +546,7 @@ export default function GroupsPage() {
|
||||
全部 →
|
||||
</Link>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
|
||||
@ -1,9 +1,20 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import "./globals.css";
|
||||
import { Providers } from "@/components/Providers";
|
||||
|
||||
export const metadata = {
|
||||
title: "抖音直播间监控",
|
||||
description: "开播/停播/时长/截图监控与可视化分析",
|
||||
export const metadata: Metadata = {
|
||||
title: "直播监控中心",
|
||||
description: "抖音 + YouTube 开播/停播/时长/截图监控与 Shorts、TikTok 分发",
|
||||
applicationName: "LiveRadar",
|
||||
manifest: "/manifest.webmanifest",
|
||||
appleWebApp: {
|
||||
capable: true,
|
||||
statusBarStyle: "black-translucent",
|
||||
title: "LiveRadar",
|
||||
},
|
||||
formatDetection: {
|
||||
telephone: false,
|
||||
},
|
||||
icons: {
|
||||
icon: [
|
||||
{ url: "/favicon.ico" },
|
||||
@ -14,6 +25,18 @@ export const metadata = {
|
||||
},
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
width: "device-width",
|
||||
initialScale: 1,
|
||||
maximumScale: 5,
|
||||
viewportFit: "cover",
|
||||
themeColor: [
|
||||
{ media: "(prefers-color-scheme: dark)", color: "#071018" },
|
||||
{ media: "(prefers-color-scheme: light)", color: "#071018" },
|
||||
],
|
||||
colorScheme: "dark",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="zh-CN">
|
||||
@ -24,8 +47,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;700&family=Space+Grotesk:wght@500;700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
</head>
|
||||
<body className="min-h-screen antialiased">
|
||||
<body className="min-h-[100dvh] antialiased">
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -45,10 +45,10 @@ function LoginForm() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative flex min-h-screen items-center justify-center px-4">
|
||||
<div className="relative flex min-h-[100dvh] items-center justify-center px-4 py-[max(1rem,env(safe-area-inset-top))] pb-[max(1rem,env(safe-area-inset-bottom))]">
|
||||
<div className="ambient-orb a" />
|
||||
<div className="ambient-orb b" />
|
||||
<div className="relative z-10 w-full max-w-md animate-fade-up rounded-2xl border border-white/10 bg-black/40 p-8 shadow-2xl backdrop-blur-md">
|
||||
<div className="relative z-10 w-full max-w-md animate-fade-up rounded-2xl border border-white/10 bg-black/40 p-6 shadow-2xl backdrop-blur-md sm:p-8">
|
||||
<div className="mb-6 flex flex-col items-center text-center">
|
||||
<BrandMark className="mb-4 h-14 w-14" />
|
||||
<p className="font-display text-xs uppercase tracking-[0.28em] text-teal-300/90">Live Radar</p>
|
||||
|
||||
@ -468,8 +468,8 @@ export default function RoomsPage() {
|
||||
{error ? <div className="mb-4 rounded-lg border border-rose-500/30 bg-rose-500/10 px-4 py-3 text-sm">{error}</div> : null}
|
||||
{msg ? <div className="mb-4 rounded-lg border border-teal-500/30 bg-teal-500/10 px-4 py-3 text-sm text-teal-50">{msg}</div> : null}
|
||||
|
||||
<div className="overflow-hidden rounded-xl border border-white/10 bg-black/20">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<div className="table-scroll overflow-hidden rounded-xl border border-white/10 bg-black/20">
|
||||
<table className="min-w-[640px] w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
<th className="px-3 py-3">
|
||||
|
||||
@ -310,7 +310,7 @@ export default function SessionsPage() {
|
||||
{tab === "list" ? (
|
||||
<>
|
||||
<div className="overflow-hidden rounded-xl border border-white/10 bg-black/20">
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase tracking-wide text-slate-400">
|
||||
<tr>
|
||||
|
||||
@ -1125,7 +1125,7 @@ function OpsPanel() {
|
||||
</div>
|
||||
</div>
|
||||
{pbHealth?.drift ? (
|
||||
<div className="overflow-x-auto rounded-lg border border-white/10 bg-black/20">
|
||||
<div className="table-scroll rounded-lg border border-white/10 bg-black/20">
|
||||
<table className="w-full text-left text-[11px]">
|
||||
<thead className="text-slate-500">
|
||||
<tr>
|
||||
|
||||
@ -722,7 +722,7 @@ export default function ShortsPage() {
|
||||
|
||||
<section className="overflow-hidden rounded-2xl border border-white/10 bg-black/25">
|
||||
<div className="border-b border-white/5 px-4 py-3 text-sm font-medium text-slate-100">频道开播排行</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
@ -773,7 +773,7 @@ export default function ShortsPage() {
|
||||
全部 →
|
||||
</Link>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="bg-white/5 text-xs uppercase text-slate-400">
|
||||
<tr>
|
||||
@ -1459,11 +1459,11 @@ export default function ShortsPage() {
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
{loading && jobs.length === 0 ? (
|
||||
<TableSkeleton rows={6} cols={5} />
|
||||
) : (
|
||||
<table className="w-full min-w-[920px] text-left text-sm">
|
||||
<table className="w-full min-w-[720px] text-left text-xs sm:text-sm md:min-w-[920px]">
|
||||
<thead className="text-xs text-slate-500">
|
||||
<tr>
|
||||
<th className="pb-2 pr-2">
|
||||
|
||||
@ -378,7 +378,7 @@ export default function SlotsPage() {
|
||||
{rangeMode === "7d" ? (
|
||||
<div className="mb-6 glass-panel rounded-2xl p-4">
|
||||
<h3 className="mb-3 font-display text-sm font-semibold text-slate-200">日 × 时段热力(开播次数)</h3>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="min-w-full text-center text-xs">
|
||||
<thead>
|
||||
<tr className="text-slate-500">
|
||||
|
||||
@ -507,7 +507,7 @@ export default function TikTokPage() {
|
||||
onConfirm={(channelPk) => uploadUx.confirmUpload(channelPk)}
|
||||
busy={uploadUx.busy}
|
||||
/>
|
||||
<div className="mx-auto max-w-7xl px-4 py-6 sm:px-6">
|
||||
<div className="py-4 sm:py-6">
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
@ -1140,7 +1140,7 @@ export default function TikTokPage() {
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<h3 className="text-sm font-medium text-slate-100">任务流水(今日 {jobTotal})</h3>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="table-scroll">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-white/10 text-xs text-slate-500">
|
||||
|
||||
@ -305,7 +305,7 @@ export default function YouTubePage() {
|
||||
<select
|
||||
value={channelPk}
|
||||
onChange={(e) => setChannelPk(e.target.value)}
|
||||
className="min-w-[220px] rounded-xl border border-white/10 bg-slate-900 px-3 py-2 text-sm"
|
||||
className="w-full min-w-0 rounded-xl border border-white/10 bg-slate-900 px-3 py-2 text-sm sm:min-w-[220px]"
|
||||
>
|
||||
{channels.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
@ -592,7 +592,7 @@ export default function YouTubePage() {
|
||||
<input
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
className="min-w-[240px] flex-1 rounded-xl border border-white/10 bg-slate-900 px-3 py-2 text-sm"
|
||||
className="w-full min-w-0 flex-1 rounded-xl border border-white/10 bg-slate-900 px-3 py-2 text-sm sm:min-w-[240px]"
|
||||
placeholder="@handle / URL / 关键词"
|
||||
/>
|
||||
<button
|
||||
|
||||
@ -20,7 +20,7 @@ export function Modal({
|
||||
open,
|
||||
onClose,
|
||||
children,
|
||||
panelClassName = "max-h-[90vh] w-full max-w-2xl overflow-y-auto rounded-2xl border border-white/10 bg-[#0b1626] p-5 shadow-2xl",
|
||||
panelClassName = "max-h-[min(90dvh,90vh)] w-full max-w-2xl overflow-y-auto rounded-2xl border border-white/10 bg-[#0b1626] p-4 shadow-2xl sm:p-5",
|
||||
zIndex = 80,
|
||||
}: ModalProps) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
@ -47,13 +47,16 @@ export function Modal({
|
||||
|
||||
return createPortal(
|
||||
<div
|
||||
className="fixed inset-0 flex items-center justify-center bg-black/70 p-4 backdrop-blur-[2px]"
|
||||
className="fixed inset-0 flex items-end justify-center bg-black/70 p-0 backdrop-blur-[2px] sm:items-center sm:p-4"
|
||||
style={{ zIndex, position: "fixed", top: 0, left: 0, right: 0, bottom: 0 }}
|
||||
onClick={onClose}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
>
|
||||
<div className={panelClassName} onClick={(e) => e.stopPropagation()}>
|
||||
<div
|
||||
className={`${panelClassName} max-sm:max-h-[92dvh] max-sm:rounded-b-none max-sm:pb-[max(1rem,env(safe-area-inset-bottom))]`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>,
|
||||
|
||||
@ -1,9 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { ConfirmProvider } from "@/components/ConfirmDialog";
|
||||
import { ToastProvider } from "@/components/Toast";
|
||||
|
||||
function registerServiceWorker() {
|
||||
if (typeof window === "undefined" || !("serviceWorker" in navigator)) return;
|
||||
// Avoid SW during local next dev HMR noise
|
||||
if (process.env.NODE_ENV !== "production") return;
|
||||
void navigator.serviceWorker.register("/sw.js").catch(() => {});
|
||||
}
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
useEffect(() => {
|
||||
registerServiceWorker();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ToastProvider>
|
||||
<ConfirmProvider>{children}</ConfirmProvider>
|
||||
|
||||
108
frontend/src/components/PwaInstallBanner.tsx
Normal file
108
frontend/src/components/PwaInstallBanner.tsx
Normal file
@ -0,0 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Download, X } from "lucide-react";
|
||||
|
||||
type BeforeInstallPromptEvent = Event & {
|
||||
prompt: () => Promise<void>;
|
||||
userChoice: Promise<{ outcome: "accepted" | "dismissed" }>;
|
||||
};
|
||||
|
||||
const DISMISS_KEY = "dylive_pwa_install_dismissed";
|
||||
|
||||
export function PwaInstallBanner() {
|
||||
const [deferred, setDeferred] = useState<BeforeInstallPromptEvent | null>(null);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [iosHint, setIosHint] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window.matchMedia("(display-mode: standalone)").matches) return;
|
||||
if (localStorage.getItem(DISMISS_KEY) === "1") return;
|
||||
|
||||
const ua = navigator.userAgent || "";
|
||||
const isIos = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
||||
const isSafari = /Safari/.test(ua) && !/CriOS|FxiOS|EdgiOS|Chrome/.test(ua);
|
||||
|
||||
const onBip = (e: Event) => {
|
||||
e.preventDefault();
|
||||
setDeferred(e as BeforeInstallPromptEvent);
|
||||
setVisible(true);
|
||||
setIosHint(false);
|
||||
};
|
||||
window.addEventListener("beforeinstallprompt", onBip);
|
||||
|
||||
if (isIos && isSafari) {
|
||||
setIosHint(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
return () => window.removeEventListener("beforeinstallprompt", onBip);
|
||||
}, []);
|
||||
|
||||
if (!visible) return null;
|
||||
|
||||
const dismiss = () => {
|
||||
localStorage.setItem(DISMISS_KEY, "1");
|
||||
setVisible(false);
|
||||
setDeferred(null);
|
||||
};
|
||||
|
||||
const install = async () => {
|
||||
if (!deferred) return;
|
||||
await deferred.prompt();
|
||||
try {
|
||||
await deferred.userChoice;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
setDeferred(null);
|
||||
setVisible(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="pointer-events-none fixed inset-x-0 bottom-[calc(4.25rem+env(safe-area-inset-bottom))] z-30 px-3 md:bottom-4 md:left-auto md:right-4 md:max-w-sm">
|
||||
<div className="pointer-events-auto rounded-2xl border border-teal-400/30 bg-[#0b1520]/95 p-3 shadow-xl backdrop-blur-md">
|
||||
<div className="flex items-start gap-2">
|
||||
<div className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-teal-500/15 text-teal-200">
|
||||
<Download className="h-4 w-4" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-slate-100">安装到主屏幕</p>
|
||||
<p className="mt-0.5 text-[11px] leading-relaxed text-slate-400">
|
||||
{iosHint
|
||||
? "Safari:点分享 →「添加到主屏幕」,可像 App 一样打开。"
|
||||
: "可选安装为 PWA,方便手机快速打开与操作。"}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{deferred ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void install()}
|
||||
className="rounded-lg bg-teal-500/20 px-3 py-1.5 text-xs text-teal-100 hover:bg-teal-500/30"
|
||||
>
|
||||
安装
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={dismiss}
|
||||
className="rounded-lg border border-white/10 px-3 py-1.5 text-xs text-slate-400"
|
||||
>
|
||||
以后再说
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={dismiss}
|
||||
className="rounded-lg p-1 text-slate-500 hover:text-slate-200"
|
||||
aria-label="关闭"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,13 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { Menu, X } from "lucide-react";
|
||||
|
||||
import { BrandMark, LivePulse } from "@/components/ui";
|
||||
import { GlobalEventAlerts } from "@/components/GlobalEventAlerts";
|
||||
import { PwaInstallBanner } from "@/components/PwaInstallBanner";
|
||||
import { fetchJson } from "@/lib/api";
|
||||
import { YouTubeLiveContextProvider, useYouTubeLiveCount, useYouTubeLiveMap, useYouTubeLiveProviderValue } from "@/lib/youtubeLive";
|
||||
import {
|
||||
YouTubeLiveContextProvider,
|
||||
useYouTubeLiveCount,
|
||||
useYouTubeLiveMap,
|
||||
useYouTubeLiveProviderValue,
|
||||
} from "@/lib/youtubeLive";
|
||||
|
||||
const NAV = [
|
||||
{ href: "/", label: "概览", emoji: "📡" },
|
||||
@ -25,7 +32,12 @@ const NAV = [
|
||||
{ href: "/settings", label: "设置", emoji: "⚙️" },
|
||||
];
|
||||
|
||||
const MOBILE_PRIMARY = ["/", "/groups", "/shorts", "/youtube", "/settings"];
|
||||
/** Bottom bar: keep 4 destinations + More */
|
||||
const MOBILE_PRIMARY = ["/", "/tiktok", "/shorts", "/youtube"];
|
||||
|
||||
function navActive(pathname: string, href: string) {
|
||||
return pathname === href || (href !== "/" && pathname.startsWith(href));
|
||||
}
|
||||
|
||||
export function Shell({ children }: { children: React.ReactNode }) {
|
||||
const liveCtx = useYouTubeLiveProviderValue();
|
||||
@ -42,6 +54,7 @@ function ShellFrame({ children }: { children: React.ReactNode }) {
|
||||
const ytLiveCount = useYouTubeLiveCount();
|
||||
const { map: ytLiveMap } = useYouTubeLiveMap();
|
||||
const [username, setUsername] = useState("");
|
||||
const [moreOpen, setMoreOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
void fetchJson("/api/auth/status")
|
||||
@ -49,6 +62,28 @@ function ShellFrame({ children }: { children: React.ReactNode }) {
|
||||
.catch(() => setUsername(""));
|
||||
}, [pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
setMoreOpen(false);
|
||||
}, [pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!moreOpen) return;
|
||||
const prev = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
document.body.style.overflow = prev;
|
||||
};
|
||||
}, [moreOpen]);
|
||||
|
||||
const primaryNav = useMemo(
|
||||
() => NAV.filter((n) => MOBILE_PRIMARY.includes(n.href)),
|
||||
[],
|
||||
);
|
||||
const moreActive = useMemo(
|
||||
() => NAV.some((n) => !MOBILE_PRIMARY.includes(n.href) && navActive(pathname, n.href)),
|
||||
[pathname],
|
||||
);
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await fetchJson("/api/auth/logout", { method: "POST" });
|
||||
@ -58,39 +93,42 @@ function ShellFrame({ children }: { children: React.ReactNode }) {
|
||||
router.replace("/login");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative min-h-screen">
|
||||
<div className="relative min-h-[100dvh] overflow-x-clip">
|
||||
<GlobalEventAlerts />
|
||||
<div className="ambient-orb a" />
|
||||
<div className="ambient-orb b" />
|
||||
<div className="ambient-orb c" />
|
||||
|
||||
<div className="relative z-10 mx-auto flex min-h-screen max-w-7xl flex-col px-4 py-5 sm:px-6">
|
||||
<header className="mb-6 animate-fade-up border-b border-white/10 pb-5">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<BrandMark className="mt-1 h-12 w-12" />
|
||||
<div>
|
||||
<p className="font-display text-xs uppercase tracking-[0.28em] text-teal-300/90">Live Radar</p>
|
||||
<h1 className="font-display text-3xl font-bold tracking-tight text-white sm:text-4xl">
|
||||
<div className="relative z-10 mx-auto flex min-h-[100dvh] max-w-7xl flex-col px-3 pb-[calc(4.5rem+env(safe-area-inset-bottom))] pt-[max(0.75rem,env(safe-area-inset-top))] sm:px-6 md:pb-10 md:pt-5">
|
||||
<header className="mb-4 animate-fade-up border-b border-white/10 pb-4 sm:mb-6 sm:pb-5">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 items-start gap-2.5 sm:gap-3">
|
||||
<BrandMark className="mt-0.5 h-9 w-9 shrink-0 sm:mt-1 sm:h-12 sm:w-12" />
|
||||
<div className="min-w-0">
|
||||
<p className="font-display text-[10px] uppercase tracking-[0.24em] text-teal-300/90 sm:text-xs sm:tracking-[0.28em]">
|
||||
Live Radar
|
||||
</p>
|
||||
<h1 className="font-display text-xl font-bold tracking-tight text-white sm:text-3xl md:text-4xl">
|
||||
直播监控中心
|
||||
</h1>
|
||||
<p className="mt-1 max-w-2xl text-sm text-slate-400">
|
||||
<p className="mt-0.5 hidden max-w-2xl text-sm text-slate-400 sm:mt-1 sm:block">
|
||||
抖音 + YouTube · 开播捕捉 · 停播结场 · 时长统计 · 截图存证
|
||||
</p>
|
||||
{ytLiveCount > 0 ? (
|
||||
<div className="mt-2 flex flex-wrap items-center gap-2">
|
||||
<div className="mt-1.5 flex flex-wrap items-center gap-2 sm:mt-2">
|
||||
<Link href="/groups">
|
||||
<LivePulse label={`YouTube ${ytLiveCount} 路在播`} />
|
||||
</Link>
|
||||
{ytLiveMap?.checked_at ? (
|
||||
<span className="text-[10px] text-slate-500">
|
||||
<span className="hidden text-[10px] text-slate-500 sm:inline">
|
||||
轮询 {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<div className="mt-2 flex flex-wrap items-center gap-2 text-[11px] text-slate-500">
|
||||
<div className="mt-1.5 hidden flex-wrap items-center gap-2 text-[11px] text-slate-500 sm:mt-2 sm:flex">
|
||||
{ytLiveMap?.svc_error ? (
|
||||
<span className="text-amber-300" title={ytLiveMap.svc_error}>
|
||||
⚠ YouTube 探测异常(轮询兜底中)
|
||||
@ -98,86 +136,73 @@ function ShellFrame({ children }: { children: React.ReactNode }) {
|
||||
) : (
|
||||
<span>YouTube 直播轮询中</span>
|
||||
)}
|
||||
{ytLiveMap?.checked_at ? (
|
||||
<span className="text-[10px]">
|
||||
· {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前刷新
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="flex shrink-0 flex-wrap items-center justify-end gap-1.5 sm:gap-2">
|
||||
{username ? (
|
||||
<span className="rounded-xl border border-white/10 bg-white/5 px-3 py-1.5 text-xs text-slate-300">
|
||||
<span className="hidden rounded-xl border border-white/10 bg-white/5 px-3 py-1.5 text-xs text-slate-300 sm:inline">
|
||||
{username}
|
||||
</span>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMoreOpen(true)}
|
||||
className="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-white/10 bg-white/5 text-slate-300 hover:bg-white/10 md:hidden"
|
||||
aria-label="打开菜单"
|
||||
>
|
||||
<Menu className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void logout()}
|
||||
className="rounded-xl border border-white/10 bg-white/5 px-3 py-1.5 text-xs text-slate-400 hover:bg-white/10 hover:text-white"
|
||||
className="rounded-xl border border-white/10 bg-white/5 px-2.5 py-1.5 text-[11px] text-slate-400 hover:bg-white/10 hover:text-white sm:px-3 sm:text-xs"
|
||||
>
|
||||
退出
|
||||
</button>
|
||||
</div>
|
||||
<nav className="hidden max-w-full flex-wrap gap-2 md:flex">
|
||||
{NAV.map((item) => {
|
||||
const active = pathname === item.href || (item.href !== "/" && pathname.startsWith(item.href));
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={`nav-chip rounded-xl px-3 py-1.5 text-sm ${
|
||||
active
|
||||
? "active bg-white/15 text-white ring-1 ring-teal-400/30"
|
||||
: "bg-white/5 text-slate-400 hover:bg-white/10 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
<span className="mr-1.5">{item.emoji}</span>
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
{/* 手机:顶部横向可滑导航 */}
|
||||
<nav className="mt-4 flex gap-2 overflow-x-auto pb-1 md:hidden [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
|
||||
<nav className="mt-4 hidden max-w-full flex-wrap gap-2 md:flex">
|
||||
{NAV.map((item) => {
|
||||
const active = pathname === item.href || (item.href !== "/" && pathname.startsWith(item.href));
|
||||
const active = navActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={`nav-chip shrink-0 rounded-xl px-3 py-1.5 text-sm ${
|
||||
className={`nav-chip rounded-xl px-3 py-1.5 text-sm ${
|
||||
active
|
||||
? "active bg-white/15 text-white ring-1 ring-teal-400/30"
|
||||
: "bg-white/5 text-slate-400"
|
||||
: "bg-white/5 text-slate-400 hover:bg-white/10 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
<span className="mr-1">{item.emoji}</span>
|
||||
<span className="mr-1.5">{item.emoji}</span>
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</header>
|
||||
<main className="page-enter flex-1 pb-24 md:pb-10">{children}</main>
|
||||
|
||||
<main className="page-enter flex-1">{children}</main>
|
||||
<footer className="hidden border-t border-white/5 py-4 text-center text-[11px] text-slate-600 md:block">
|
||||
Douyin + YouTube Monitor · realtime radar
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
{/* 手机底部快捷栏 */}
|
||||
<nav className="fixed inset-x-0 bottom-0 z-40 border-t border-white/10 bg-[#071018]/95 px-2 pb-[env(safe-area-inset-bottom)] pt-1 backdrop-blur-md md:hidden">
|
||||
<div className="mx-auto flex max-w-lg items-stretch justify-between gap-1">
|
||||
{NAV.filter((n) => MOBILE_PRIMARY.includes(n.href)).map((item) => {
|
||||
const active = pathname === item.href || (item.href !== "/" && pathname.startsWith(item.href));
|
||||
<PwaInstallBanner />
|
||||
|
||||
{/* Mobile bottom tab bar */}
|
||||
<nav className="fixed inset-x-0 bottom-0 z-40 border-t border-white/10 bg-[#071018]/95 px-1 pt-1 backdrop-blur-md md:hidden pb-[env(safe-area-inset-bottom)]">
|
||||
<div className="mx-auto flex max-w-lg items-stretch justify-between gap-0.5">
|
||||
{primaryNav.map((item) => {
|
||||
const active = navActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={`flex min-w-0 flex-1 flex-col items-center gap-0.5 rounded-lg px-1 py-2 text-[10px] ${
|
||||
className={`flex min-h-[3rem] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg px-1 py-1.5 text-[10px] ${
|
||||
active ? "text-teal-200" : "text-slate-500"
|
||||
}`}
|
||||
>
|
||||
@ -186,8 +211,68 @@ function ShellFrame({ children }: { children: React.ReactNode }) {
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMoreOpen(true)}
|
||||
className={`flex min-h-[3rem] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg px-1 py-1.5 text-[10px] ${
|
||||
moreActive || moreOpen ? "text-teal-200" : "text-slate-500"
|
||||
}`}
|
||||
>
|
||||
<span className="text-base leading-none">⋯</span>
|
||||
<span className="truncate">更多</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* Mobile more sheet */}
|
||||
{moreOpen ? (
|
||||
<div className="fixed inset-0 z-50 md:hidden" role="dialog" aria-modal="true">
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-0 bg-black/60"
|
||||
aria-label="关闭菜单"
|
||||
onClick={() => setMoreOpen(false)}
|
||||
/>
|
||||
<div className="absolute inset-x-0 bottom-0 max-h-[85dvh] overflow-y-auto rounded-t-2xl border border-white/10 bg-[#0b1520] px-4 pb-[calc(1rem+env(safe-area-inset-bottom))] pt-3 shadow-2xl">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-slate-100">全部功能</p>
|
||||
<p className="text-[11px] text-slate-500">点选页面 · 支持手机操作</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMoreOpen(false)}
|
||||
className="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-white/10 bg-white/5 text-slate-300"
|
||||
aria-label="关闭"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
{username ? (
|
||||
<p className="mb-3 text-xs text-slate-400">当前账号:{username}</p>
|
||||
) : null}
|
||||
<div className="grid grid-cols-3 gap-2 sm:grid-cols-4">
|
||||
{NAV.map((item) => {
|
||||
const active = navActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={`flex min-h-[4.5rem] flex-col items-center justify-center gap-1 rounded-xl border px-2 py-3 text-center text-xs ${
|
||||
active
|
||||
? "border-teal-400/40 bg-teal-500/10 text-teal-100"
|
||||
: "border-white/10 bg-white/[0.03] text-slate-300"
|
||||
}`}
|
||||
>
|
||||
<span className="text-xl leading-none">{item.emoji}</span>
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ export function ToastProvider({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<ToastCtx.Provider value={value}>
|
||||
{children}
|
||||
<div className="pointer-events-none fixed inset-x-4 bottom-20 z-[80] flex flex-col gap-2 md:inset-x-auto md:bottom-4 md:right-4 md:w-[min(92vw,22rem)] md:pb-[env(safe-area-inset-bottom)]">
|
||||
<div className="pointer-events-none fixed inset-x-3 bottom-[calc(4.75rem+env(safe-area-inset-bottom))] z-[80] flex flex-col gap-2 md:inset-x-auto md:bottom-4 md:right-4 md:w-[min(92vw,22rem)]">
|
||||
{items.map((t) => {
|
||||
const clickable = Boolean(t.onClick || t.href);
|
||||
const body = (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user