From 60ea916a4d0b8ea735be23d1deee0574e0755725 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 14 Aug 2026 22:19:06 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=A8=E7=AB=99=20H5=20=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=BC=8F=E5=AF=BC=E8=88=AA=E4=B8=8E=E5=8F=AF=E9=80=89?= =?UTF-8?q?=20PWA=20=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- frontend/public/manifest.webmanifest | 32 +++ frontend/public/sw.js | 46 +++++ frontend/src/app/anchors/page.tsx | 2 +- frontend/src/app/blacklist/page.tsx | 4 +- frontend/src/app/globals.css | 74 +++++++ frontend/src/app/groups/page.tsx | 4 +- frontend/src/app/layout.tsx | 32 ++- frontend/src/app/login/page.tsx | 4 +- frontend/src/app/rooms/page.tsx | 4 +- frontend/src/app/sessions/page.tsx | 2 +- frontend/src/app/settings/page.tsx | 2 +- frontend/src/app/shorts/page.tsx | 8 +- frontend/src/app/slots/page.tsx | 2 +- frontend/src/app/tiktok/page.tsx | 4 +- frontend/src/app/youtube/page.tsx | 4 +- frontend/src/components/Modal.tsx | 9 +- frontend/src/components/Providers.tsx | 13 ++ frontend/src/components/PwaInstallBanner.tsx | 108 ++++++++++ frontend/src/components/Shell.tsx | 197 +++++++++++++------ frontend/src/components/Toast.tsx | 2 +- 20 files changed, 469 insertions(+), 84 deletions(-) create mode 100644 frontend/public/manifest.webmanifest create mode 100644 frontend/public/sw.js create mode 100644 frontend/src/components/PwaInstallBanner.tsx diff --git a/frontend/public/manifest.webmanifest b/frontend/public/manifest.webmanifest new file mode 100644 index 0000000..15442ac --- /dev/null +++ b/frontend/public/manifest.webmanifest @@ -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" + } + ] +} diff --git a/frontend/public/sw.js b/frontend/public/sw.js new file mode 100644 index 0000000..1e16a40 --- /dev/null +++ b/frontend/public/sw.js @@ -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"); + }), + ); +}); diff --git a/frontend/src/app/anchors/page.tsx b/frontend/src/app/anchors/page.tsx index cfaef60..be35bc9 100644 --- a/frontend/src/app/anchors/page.tsx +++ b/frontend/src/app/anchors/page.tsx @@ -307,7 +307,7 @@ export default function AnchorsPage() { {profile.schedule.slot_counts?.length === 6 ? ( -
+
{profile.schedule.slot_counts.map((n, i) => { const max = Math.max(1, ...profile.schedule!.slot_counts!); return ( diff --git a/frontend/src/app/blacklist/page.tsx b/frontend/src/app/blacklist/page.tsx index d7b91e4..7c6f4a5 100644 --- a/frontend/src/app/blacklist/page.tsx +++ b/frontend/src/app/blacklist/page.tsx @@ -130,8 +130,8 @@ export default function BlacklistPage() { ) : items.length === 0 ? ( ) : ( -
- +
+
diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index ed774b4..cacdf4b 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -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; diff --git a/frontend/src/app/groups/page.tsx b/frontend/src/app/groups/page.tsx index 6077dde..9f772e5 100644 --- a/frontend/src/app/groups/page.tsx +++ b/frontend/src/app/groups/page.tsx @@ -496,7 +496,7 @@ export default function GroupsPage() {
频道排行
-
+
内容
@@ -546,7 +546,7 @@ export default function GroupsPage() { 全部 → -
+
diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index c6fedcb..d6bf6cd 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -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 ( @@ -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" /> + - + {children} diff --git a/frontend/src/app/login/page.tsx b/frontend/src/app/login/page.tsx index 0415ff0..cac23b1 100644 --- a/frontend/src/app/login/page.tsx +++ b/frontend/src/app/login/page.tsx @@ -45,10 +45,10 @@ function LoginForm() { } return ( -
+
-
+

Live Radar

diff --git a/frontend/src/app/rooms/page.tsx b/frontend/src/app/rooms/page.tsx index 1ebf81d..3dda3b8 100644 --- a/frontend/src/app/rooms/page.tsx +++ b/frontend/src/app/rooms/page.tsx @@ -468,8 +468,8 @@ export default function RoomsPage() { {error ?
{error}
: null} {msg ?
{msg}
: null} -
-
+
+
diff --git a/frontend/src/app/sessions/page.tsx b/frontend/src/app/sessions/page.tsx index a0b8cd2..6a1d112 100644 --- a/frontend/src/app/sessions/page.tsx +++ b/frontend/src/app/sessions/page.tsx @@ -310,7 +310,7 @@ export default function SessionsPage() { {tab === "list" ? ( <>
-
+
diff --git a/frontend/src/app/settings/page.tsx b/frontend/src/app/settings/page.tsx index 792899c..9919e69 100644 --- a/frontend/src/app/settings/page.tsx +++ b/frontend/src/app/settings/page.tsx @@ -1125,7 +1125,7 @@ function OpsPanel() { {pbHealth?.drift ? ( -
+
diff --git a/frontend/src/app/shorts/page.tsx b/frontend/src/app/shorts/page.tsx index 487f756..a49433a 100644 --- a/frontend/src/app/shorts/page.tsx +++ b/frontend/src/app/shorts/page.tsx @@ -722,7 +722,7 @@ export default function ShortsPage() {
频道开播排行
-
+
@@ -773,7 +773,7 @@ export default function ShortsPage() { 全部 → -
+
@@ -1459,11 +1459,11 @@ export default function ShortsPage() { ) : null} -
+
{loading && jobs.length === 0 ? ( ) : ( -
+
diff --git a/frontend/src/app/slots/page.tsx b/frontend/src/app/slots/page.tsx index bcfee2b..72e31eb 100644 --- a/frontend/src/app/slots/page.tsx +++ b/frontend/src/app/slots/page.tsx @@ -378,7 +378,7 @@ export default function SlotsPage() { {rangeMode === "7d" ? (

日 × 时段热力(开播次数)

-
+
diff --git a/frontend/src/app/tiktok/page.tsx b/frontend/src/app/tiktok/page.tsx index 3842721..fee2a67 100644 --- a/frontend/src/app/tiktok/page.tsx +++ b/frontend/src/app/tiktok/page.tsx @@ -507,7 +507,7 @@ export default function TikTokPage() { onConfirm={(channelPk) => uploadUx.confirmUpload(channelPk)} busy={uploadUx.busy} /> -
+
{/* Header */}
@@ -1140,7 +1140,7 @@ export default function TikTokPage() {

任务流水(今日 {jobTotal})

-
+
diff --git a/frontend/src/app/youtube/page.tsx b/frontend/src/app/youtube/page.tsx index 199f4e8..8b31cc7 100644 --- a/frontend/src/app/youtube/page.tsx +++ b/frontend/src/app/youtube/page.tsx @@ -305,7 +305,7 @@ export default function YouTubePage() { 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 / 关键词" /> + ) : null} + + + + + + + + ); +} diff --git a/frontend/src/components/Shell.tsx b/frontend/src/components/Shell.tsx index 1295e40..972dfdf 100644 --- a/frontend/src/components/Shell.tsx +++ b/frontend/src/components/Shell.tsx @@ -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 ( -
+
-
-
-
-
- -
-

Live Radar

-

+
+
+
+
+ +
+

+ Live Radar +

+

直播监控中心

-

+

抖音 + YouTube · 开播捕捉 · 停播结场 · 时长统计 · 截图存证

{ytLiveCount > 0 ? ( -
+
{ytLiveMap?.checked_at ? ( - + 轮询 {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前 ) : null}
) : ( -
+
{ytLiveMap?.svc_error ? ( ⚠ YouTube 探测异常(轮询兜底中) @@ -98,86 +136,73 @@ function ShellFrame({ children }: { children: React.ReactNode }) { ) : ( YouTube 直播轮询中 )} - {ytLiveMap?.checked_at ? ( - - · {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前刷新 - - ) : null}
)}
-
+
{username ? ( - + {username} ) : null} +
-
- {/* 手机:顶部横向可滑导航 */} -
-
{children}
+ +
{children}
Douyin + YouTube Monitor · realtime radar
- {/* 手机底部快捷栏 */} -

+ ) : null}
); } diff --git a/frontend/src/components/Toast.tsx b/frontend/src/components/Toast.tsx index 0d3abce..4ecced5 100644 --- a/frontend/src/components/Toast.tsx +++ b/frontend/src/components/Toast.tsx @@ -50,7 +50,7 @@ export function ToastProvider({ children }: { children: ReactNode }) { return ( {children} -
+
{items.map((t) => { const clickable = Boolean(t.onClick || t.href); const body = (