性能与用户体验全面优化

    前端性能:
    - 移除 Three.js 依赖(~600KB),天气粒子改为纯 CSS 动画 + Canvas 2D
    - Google Fonts 切换为 next/font 自托管,消除跨域字体请求
    - 合并 ScanTerminalLightTheme.module.css (37KB) 到主 CSS,亮/暗主题统一用 CSS 变量
    - 新增 /api/dashboard/init 聚合端点,首次加载 4 次往返 → 1 次
    - 添加 Service Worker 静态资源缓存,修复 PWA manifest 配置

    用户体验:
    - 新增全局错误边界 error.tsx / global-error.tsx,崩溃不再白屏
    - 决策卡和城市详情的更新时间改为相对时间("15秒前"),每秒自动刷新
    - 数据陈旧时状态标签从青色切换为琥珀色提示

    DEB 算法增强:
    - 市场扫描路径接入 Open-Meteo 多模型数据(ECMWF/GFS/ICON/JMA/HRDPS 等)
    - MAE 计算加入时间衰减(decay_factor=0.85),近期模型误差权重更高

    Scope-risk: MEDIUM — 全量 170 测试通过,前端 TypeScript/build 通过,ruff 零告警
    Tested: python -m pytest -q (170 passed), npx tsc --noEmit (0 errors), npm run build (success), ruff check .
@
This commit is contained in:
2569718930@qq.com
2026-05-14 21:31:05 +08:00
parent 37494a7192
commit 6c08a68413
21 changed files with 2062 additions and 1705 deletions
+101
View File
@@ -0,0 +1,101 @@
"use client";
import { RefreshCw } from "lucide-react";
import { useEffect } from "react";
export default function ErrorPage({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error("Unhandled page error:", error);
}, [error]);
return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: "100vh",
padding: "2rem",
gap: "1rem",
backgroundColor: "var(--color-bg-base, #0B1220)",
color: "var(--color-text-primary, #E6EDF3)",
fontFamily: "var(--font-data, Inter, sans-serif)",
textAlign: "center",
}}
>
<div
style={{
width: 64,
height: 64,
borderRadius: "var(--radius-xl, 20px)",
backgroundColor: "var(--color-bg-raised, #111A2E)",
display: "flex",
alignItems: "center",
justifyContent: "center",
marginBottom: "0.5rem",
}}
>
<span style={{ fontSize: "1.8rem" }}></span>
</div>
<h1
style={{
fontSize: "1.25rem",
fontWeight: 600,
margin: 0,
}}
>
</h1>
<p
style={{
color: "var(--color-text-secondary, #9FB2C7)",
fontSize: "0.875rem",
margin: 0,
maxWidth: 400,
lineHeight: 1.6,
}}
>
</p>
{error.digest ? (
<code
style={{
fontSize: "0.75rem",
color: "var(--color-text-muted, #7D8FA3)",
fontFamily: "var(--font-mono, monospace)",
}}
>
{error.digest}
</code>
) : null}
<button
type="button"
onClick={reset}
style={{
marginTop: "0.5rem",
display: "inline-flex",
alignItems: "center",
gap: "0.5rem",
padding: "0.5rem 1.25rem",
borderRadius: "var(--radius-md, 10px)",
border: "1px solid var(--color-border-default, rgba(159,178,199,0.16))",
backgroundColor: "var(--color-bg-raised, #111A2E)",
color: "var(--color-accent-primary, #4DA3FF)",
cursor: "pointer",
fontSize: "0.875rem",
fontWeight: 500,
}}
>
<RefreshCw size={14} />
</button>
</div>
);
}
+115
View File
@@ -0,0 +1,115 @@
"use client";
import { RefreshCw } from "lucide-react";
import { useEffect } from "react";
export default function GlobalError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error("Unhandled root error:", error);
}, [error]);
return (
<html lang="zh-CN" className="dark">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PolyWeather </title>
</head>
<body
style={{
margin: 0,
padding: 0,
backgroundColor: "var(--color-bg-base, #0B1220)",
minHeight: "100vh",
}}
>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: "100vh",
padding: "2rem",
gap: "1rem",
color: "var(--color-text-primary, #E6EDF3)",
fontFamily: "var(--font-data, Inter, sans-serif)",
textAlign: "center",
}}
>
<div
style={{
width: 64,
height: 64,
borderRadius: "var(--radius-xl, 20px)",
backgroundColor: "var(--color-bg-raised, #111A2E)",
display: "flex",
alignItems: "center",
justifyContent: "center",
marginBottom: "0.5rem",
}}
>
<span style={{ fontSize: "1.8rem" }}></span>
</div>
<h1
style={{
fontSize: "1.25rem",
fontWeight: 600,
margin: 0,
}}
>
</h1>
<p
style={{
color: "var(--color-text-secondary, #9FB2C7)",
fontSize: "0.875rem",
margin: 0,
maxWidth: 400,
lineHeight: 1.6,
}}
>
PolyWeather
</p>
{error.digest ? (
<code
style={{
fontSize: "0.75rem",
color: "var(--color-text-muted, #7D8FA3)",
fontFamily: "var(--font-mono, monospace)",
}}
>
{error.digest}
</code>
) : null}
<button
type="button"
onClick={reset}
style={{
marginTop: "0.5rem",
display: "inline-flex",
alignItems: "center",
gap: "0.5rem",
padding: "0.5rem 1.25rem",
borderRadius: "var(--radius-md, 10px)",
border: "1px solid var(--color-border-default, rgba(159,178,199,0.16))",
backgroundColor: "var(--color-bg-raised, #111A2E)",
color: "var(--color-accent-primary, #4DA3FF)",
cursor: "pointer",
fontSize: "0.875rem",
fontWeight: 500,
}}
>
<RefreshCw size={14} />
</button>
</div>
</body>
</html>
);
}
+3 -4
View File
@@ -50,10 +50,9 @@
--shadow-glow-secondary: 0 0 20px rgba(111, 183, 255, 0.22);
/* ── Typography ── */
--font-data:
"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--font-display: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--font-mono: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
--font-data: var(--font-inter), -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--font-display: var(--font-inter), -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--font-mono: var(--font-jetbrains-mono), "Fira Code", "SF Mono", monospace;
/* ── Spacing (4px grid) ── */
--space-1: 4px;
+21 -11
View File
@@ -1,6 +1,22 @@
import type { Metadata } from "next";
import { Inter, JetBrains_Mono } from "next/font/google";
import { RegisterSW } from "@/components/dashboard/RegisterSW";
import "./globals.css";
const inter = Inter({
subsets: ["latin"],
display: "swap",
variable: "--font-inter",
weight: ["300", "400", "500", "600", "700", "800"],
});
const jetbrainsMono = JetBrains_Mono({
subsets: ["latin"],
display: "swap",
variable: "--font-jetbrains-mono",
weight: ["400", "500", "600", "700"],
});
export const metadata: Metadata = {
title: "PolyWeather | Weather Intelligence",
description:
@@ -23,25 +39,19 @@ export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="zh-CN" className="dark">
<html
lang="zh-CN"
className={`${inter.variable} ${jetbrainsMono.variable} dark`}
>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin=""
/>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
</head>
<body className="min-h-screen font-sans antialiased">
<a href="#main-content" className="skip-to-content">
Skip to content
</a>
<main id="main-content">{children}</main>
<RegisterSW />
</body>
</html>
);
@@ -12,6 +12,7 @@ import {
useProAccess,
} from "@/hooks/useDashboardStore";
import { useI18n } from "@/hooks/useI18n";
import { useRelativeTime } from "@/hooks/useRelativeTime";
import { getOfficialSourceLinks } from "@/lib/dashboard-official-sources";
import { trackAppEvent } from "@/lib/app-analytics";
import { getTodayPolymarketUrl } from "@/lib/polymarket-market-links";
@@ -60,6 +61,19 @@ export function DetailPanel({
const isPro = proAccess.subscriptionActive;
const isAuthenticated = proAccess.authenticated;
const panelRef = useRef<HTMLElement | null>(null);
const lastDetailFetchedAtRef = useRef<number>(0);
useEffect(() => {
if (detail?.name) {
lastDetailFetchedAtRef.current = Date.now();
}
}, [detail?.name]);
const detailAgeText = useRelativeTime(
lastDetailFetchedAtRef.current
? new Date(lastDetailFetchedAtRef.current).toISOString()
: null,
);
const [heavyContentReady, setHeavyContentReady] = useState(false);
const isOverlayOpen =
Boolean(modal.futureModalDate) || history.historyState.isOpen;
@@ -298,6 +312,19 @@ export function DetailPanel({
<span className={clsx("risk-badge", panelRiskLevel)}>
{getRiskBadgeLabel(panelRiskLevel, locale)}
</span>
{detailAgeText ? (
<span
className="panel-meta-chip panel-meta-chip-muted"
title={
locale === "en-US"
? "Time since last data refresh"
: "上次数据更新时间"
}
>
{locale === "en-US" ? "Updated " : "更新于 "}
{detailAgeText}
</span>
) : null}
<span className="panel-meta-chip panel-meta-chip-strong">
{heroSettlementLabel}
</span>
@@ -1,7 +1,6 @@
"use client";
import { useEffect, useRef } from "react";
import * as THREE from "three";
import { CSSProperties, useEffect, useRef } from "react";
import { usePrefersReducedMotion } from "@/hooks/usePrefersReducedMotion";
export interface IntradaySignalMetric {
@@ -24,6 +23,42 @@ function getToneColor(tone: string) {
return "#9FB2C7";
}
function hexToRgba(hex: string, alpha: number) {
const sanitized = hex.replace("#", "");
const numeric = Number.parseInt(sanitized.padEnd(6, "0"), 16);
const r = (numeric >> 16) & 255;
const g = (numeric >> 8) & 255;
const b = numeric & 255;
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
/* ── Draw a rounded-rect path (polyfill-safe) ── */
function roundRect(
ctx: CanvasRenderingContext2D,
x: number,
y: number,
w: number,
h: number,
r: number | [number, number, number, number],
) {
const corners = typeof r === "number" ? [r, r, r, r] : r;
const [tl, tr, br, bl] = corners;
ctx.beginPath();
ctx.moveTo(x + tl, y);
ctx.lineTo(x + w - tr, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + tr);
ctx.lineTo(x + w, y + h - br);
ctx.quadraticCurveTo(x + w, y + h, x + w - br, y + h);
ctx.lineTo(x + bl, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - bl);
ctx.lineTo(x, y + tl);
ctx.quadraticCurveTo(x, y, x + tl, y);
ctx.closePath();
}
/* ── Component ── */
export function IntradaySignalScene({
metrics,
score,
@@ -38,163 +73,173 @@ export function IntradaySignalScene({
const host = containerRef.current;
if (!host) return;
const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
powerPreference: "low-power",
});
renderer.setClearColor(0x000000, 0);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
const canvas = document.createElement("canvas");
canvas.style.cssText = "width:100%;height:100%;display:block;";
host.appendChild(canvas);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 100);
camera.position.set(0, 2.8, 7.2);
camera.lookAt(0, 1.2, 0);
const ambient = new THREE.AmbientLight(0xbfe8ff, 1.25);
const keyLight = new THREE.PointLight(0x67e8f9, 22, 18, 2);
keyLight.position.set(-3.8, 5.6, 4.8);
const warmLight = new THREE.PointLight(0xf59e0b, 12, 16, 2);
warmLight.position.set(4.2, 2.8, 4);
scene.add(ambient, keyLight, warmLight);
const stage = new THREE.Group();
scene.add(stage);
const floor = new THREE.Mesh(
new THREE.CylinderGeometry(3.3, 3.8, 0.12, 48),
new THREE.MeshStandardMaterial({
color: new THREE.Color(score >= 0 ? "#10263b" : "#2c1d12"),
emissive: new THREE.Color(score >= 0 ? "#0e7490" : "#b45309"),
emissiveIntensity: 0.18 + clamp(Math.abs(score) / 8, 0, 0.24),
metalness: 0.2,
roughness: 0.78,
}),
);
floor.position.y = -0.12;
stage.add(floor);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(2.8, 0.03, 18, 100),
new THREE.MeshBasicMaterial({
color: new THREE.Color(score >= 0 ? "#4DA3FF" : "#F59E0B"),
transparent: true,
opacity: 0.5,
}),
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.03;
stage.add(ring);
const barGeometry = new THREE.BoxGeometry(0.8, 1, 0.8);
const capGeometry = new THREE.SphereGeometry(0.16, 16, 16);
const bars: Array<{
mesh: THREE.Mesh;
cap: THREE.Mesh;
glow: THREE.Mesh;
baseY: number;
targetHeight: number;
}> = [];
const xPositions = [-1.8, -0.6, 0.6, 1.8];
metrics.slice(0, 4).forEach((metric, index) => {
const height = 0.5 + ((metric.fill ?? 20) / 100) * 2.8;
const color = new THREE.Color(getToneColor(metric.tone));
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
metalness: 0.14,
roughness: 0.38,
});
const mesh = new THREE.Mesh(barGeometry, material);
mesh.position.set(xPositions[index] || 0, height / 2, 0);
mesh.scale.y = height;
stage.add(mesh);
const cap = new THREE.Mesh(
capGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
}),
);
cap.position.set(mesh.position.x, height + 0.2, 0);
stage.add(cap);
const glow = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.58, 0.08, 32),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.22,
}),
);
glow.position.set(mesh.position.x, 0.06, 0);
stage.add(glow);
bars.push({
mesh,
cap,
glow,
baseY: cap.position.y,
targetHeight: height,
});
});
const ctx = canvas.getContext("2d")!;
let animationId = 0;
const resize = () => {
const width = Math.max(host.clientWidth, 1);
const height = Math.max(host.clientHeight, 1);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const rect = host.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 1.5);
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
resize();
host.appendChild(renderer.domElement);
const clock = new THREE.Clock();
let frameId = 0;
const renderFrame = () => {
frameId = window.requestAnimationFrame(renderFrame);
const elapsed = clock.getElapsedTime();
stage.rotation.y = Math.sin(elapsed * 0.35) * 0.16;
ring.material.opacity = 0.38 + Math.sin(elapsed * 0.8) * 0.08;
bars.forEach((bar, index) => {
const pulse = prefersReducedMotion
? 0
: Math.sin(elapsed * 1.5 + index * 0.8) * 0.08;
bar.cap.position.y = bar.baseY + pulse;
bar.glow.scale.x = 1 + Math.sin(elapsed * 1.2 + index) * 0.06;
bar.glow.scale.z = 1 + Math.sin(elapsed * 1.2 + index) * 0.06;
});
renderer.render(scene, camera);
};
const observer = new ResizeObserver(resize);
observer.observe(host);
frameId = window.requestAnimationFrame(renderFrame);
let startTime = performance.now();
const render = (now: number) => {
animationId = requestAnimationFrame(render);
const W = host.clientWidth;
const H = host.clientHeight;
if (W < 1 || H < 1) return;
ctx.clearRect(0, 0, W, H);
const elapsed = prefersReducedMotion ? 0 : (now - startTime) / 1000;
/* ── Layout ── */
const cx = W / 2;
const floorY = Math.max(H - 28, H * 0.78);
const rx = clamp(Math.min(W / 2 - 24, 160), 60, 160);
const ry = clamp(rx * 0.28, 12, 26);
const isPositive = score >= 0;
const accentColor = isPositive ? "#4DA3FF" : "#F59E0B";
const floorGlowColor = isPositive ? "#0e7490" : "#b45309";
const floorBaseColor = isPositive ? "#10263b" : "#2c1d12";
/* ── Floor ── */
const floorGrad = ctx.createRadialGradient(cx, floorY, 0, cx, floorY, rx);
floorGrad.addColorStop(0, hexToRgba(floorGlowColor, 0.55));
floorGrad.addColorStop(0.5, floorBaseColor);
floorGrad.addColorStop(1, "#060e1a");
ctx.beginPath();
ctx.ellipse(cx, floorY, rx, ry, 0, 0, Math.PI * 2);
ctx.fillStyle = floorGrad;
ctx.fill();
/* Floor glow overlay */
const floorGlow = ctx.createRadialGradient(cx, floorY, 0, cx, floorY, rx * 0.6);
floorGlow.addColorStop(0, hexToRgba(accentColor, 0.08));
floorGlow.addColorStop(1, "transparent");
ctx.beginPath();
ctx.ellipse(cx, floorY, rx * 0.6, ry * 0.6, 0, 0, Math.PI * 2);
ctx.fillStyle = floorGlow;
ctx.fill();
/* ── Ring (oscillating opacity) ── */
const ringOpacity = 0.38 + Math.sin(elapsed * 0.8) * 0.1;
ctx.beginPath();
ctx.ellipse(cx, floorY, rx - 10, Math.max(ry - 3, 8), 0, 0, Math.PI * 2);
ctx.strokeStyle = hexToRgba(accentColor, ringOpacity);
ctx.lineWidth = 2.5;
ctx.stroke();
/* ── Bar positions ── */
const barSpacing = rx * 0.48;
const xPositions = [
cx - barSpacing,
cx - barSpacing / 3,
cx + barSpacing / 3,
cx + barSpacing,
];
const barWidth = Math.min(26, rx * 0.16);
const limitedMetrics = metrics.slice(0, 4);
/* ── Draw bars ── */
limitedMetrics.forEach((metric, i) => {
const fill = metric.fill ?? 20;
const height = Math.max(12, 14 + (fill / 100) * (floorY - 55));
const bx = xPositions[i];
const by = floorY - height;
const color = getToneColor(metric.tone);
const baseGlow = prefersReducedMotion
? 1
: 1 + Math.sin(elapsed * 1.2 + i) * 0.06;
/* Base glow ellipse */
const glowGrad = ctx.createRadialGradient(bx, floorY, 0, bx, floorY, barWidth * 1.2);
glowGrad.addColorStop(0, hexToRgba(color, 0.35));
glowGrad.addColorStop(1, "transparent");
ctx.beginPath();
ctx.ellipse(bx, floorY, barWidth * baseGlow, 7 * baseGlow, 0, 0, Math.PI * 2);
ctx.fillStyle = glowGrad;
ctx.fill();
/* Bar body (rounded top) */
const barGrad = ctx.createLinearGradient(bx, by, bx, floorY);
barGrad.addColorStop(0, color);
barGrad.addColorStop(0.55, color);
barGrad.addColorStop(1, hexToRgba(color, 0.3));
roundRect(ctx, bx - barWidth / 2, by, barWidth, height, [4, 4, 0, 0]);
ctx.fillStyle = barGrad;
ctx.fill();
/* Bar glow outline */
ctx.strokeStyle = hexToRgba(color, 0.15);
ctx.lineWidth = 1;
roundRect(ctx, bx - barWidth / 2 - 1, by - 1, barWidth + 2, height + 2, [5, 5, 0, 0]);
ctx.stroke();
/* Cap (pulse offset per bar) */
const pulse = prefersReducedMotion
? 0
: Math.sin(elapsed * 1.5 + i * 0.8) * 3;
const capY = by + pulse;
const capR = Math.max(5, barWidth * 0.22);
/* Cap outer glow */
const capGlow = ctx.createRadialGradient(bx, capY, 0, bx, capY, capR * 3);
capGlow.addColorStop(0, hexToRgba(color, 0.2));
capGlow.addColorStop(1, "transparent");
ctx.beginPath();
ctx.arc(bx, capY, capR * 3, 0, Math.PI * 2);
ctx.fillStyle = capGlow;
ctx.fill();
/* Cap body */
ctx.beginPath();
ctx.arc(bx, capY, capR, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.shadowColor = color;
ctx.shadowBlur = capR * 2;
ctx.fill();
ctx.shadowBlur = 0;
});
/* ── Ambient sparkle dots (only when not reduced motion) ── */
if (!prefersReducedMotion) {
for (let i = 0; i < 6; i++) {
const angle = elapsed * 0.25 + i * 1.05;
const dist = rx * 0.7 + Math.sin(elapsed * 0.15 + i * 2.3) * 10;
const sx = cx + Math.cos(angle) * dist;
const sy = floorY - ry * 0.4 + Math.sin(angle) * dist * 0.35;
const sparkleSize = 1.5 + Math.sin(elapsed * 2 + i * 1.7) * 0.8;
ctx.beginPath();
ctx.arc(sx, sy, Math.max(0.5, sparkleSize), 0, Math.PI * 2);
ctx.fillStyle = hexToRgba(accentColor, 0.12 + Math.sin(elapsed * 1.3 + i) * 0.06);
ctx.fill();
}
}
}
animationId = requestAnimationFrame(render);
return () => {
observer.disconnect();
window.cancelAnimationFrame(frameId);
stage.traverse((child) => {
if (child instanceof THREE.Mesh) {
child.geometry.dispose();
if (Array.isArray(child.material)) {
child.material.forEach((material) => material.dispose());
} else {
child.material.dispose();
}
}
});
renderer.dispose();
if (renderer.domElement.parentNode === host) {
host.removeChild(renderer.domElement);
cancelAnimationFrame(animationId);
if (canvas.parentNode === host) {
host.removeChild(canvas);
}
};
}, [metrics, prefersReducedMotion, score]);
@@ -211,7 +256,7 @@ export function IntradaySignalScene({
<div key={metric.key} className="intraday-scene-chip">
<span
className="intraday-scene-chip-dot"
style={{ backgroundColor: getToneColor(metric.tone) }}
style={{ backgroundColor: getToneColor(metric.tone) } as CSSProperties}
/>
<div className="intraday-scene-chip-copy">
<strong>{metric.label}</strong>
@@ -0,0 +1,12 @@
"use client";
import { useEffect } from "react";
export function RegisterSW() {
useEffect(() => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js").catch(() => {});
}
}, []);
return null;
}
@@ -554,3 +554,983 @@
min-height: calc(100vh - 32px);
max-height: calc(100vh - 32px);
}
/* ══════════════════════════════════════════════════════════════
LIGHT THEME OVERRIDES — merged from ScanTerminalLightTheme.module.css
Uses CSS custom properties so colors switch automatically when
html.light is toggled via useScanTerminalTheme().
══════════════════════════════════════════════════════════════ */
.root :global(.scan-terminal.light) {
background:
radial-gradient(circle at top, rgba(59, 130, 246, 0.1), transparent 34%),
linear-gradient(180deg, #F7F9FC 0%, #EEF2F7 100%);
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-filter-panel),
.root :global(.scan-terminal.light .scan-data-grid),
.root :global(.scan-terminal.light .scan-detail-panel),
.root :global(.scan-terminal.light > .detail-panel.scan-city-detail-rail) {
border-color: var(--border-glass);
background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.96));
box-shadow: 0 16px 34px rgba(40, 70, 110, 0.12);
}
.root :global(.scan-terminal.light .scan-sidebar-brand-name),
.root :global(.scan-terminal.light .scan-topbar-tab.active),
.root :global(.scan-terminal.light .scan-hero h1),
.root :global(.scan-terminal.light .scan-topbar-title strong),
.root :global(.scan-terminal.light .scan-city-name),
.root :global(.scan-terminal.light .scan-opportunity-city strong),
.root :global(.scan-terminal.light .panel-title-area h2),
.root :global(.scan-terminal.light .detail-summary-temp),
.root :global(.scan-terminal.light .scan-detail-city-name),
.root :global(.scan-terminal.light .scan-empty-title),
.root :global(.scan-terminal.light .scan-detail-section-title),
.root :global(.scan-terminal.light .scan-detail-volume-big),
.root :global(.scan-terminal.light .scan-kv strong),
.root :global(.scan-terminal.light .scan-time-main),
.root :global(.scan-terminal.light .scan-summary-value),
.root :global(.scan-terminal.light .scan-distribution-card strong),
.root :global(.scan-terminal.light .scan-table-header),
.root :global(.scan-terminal.light .scan-list-tabs button.active) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-filter-heading),
.root :global(.scan-terminal.light .scan-topbar-actions),
.root :global(.scan-terminal.light .scan-topbar-time),
.root :global(.scan-terminal.light .scan-hero p),
.root :global(.scan-terminal.light .scan-topbar-title span),
.root :global(.scan-terminal.light .scan-city-sub),
.root :global(.scan-terminal.light .scan-opportunity-phase),
.root :global(.scan-terminal.light .scan-opportunity-phase em),
.root :global(.scan-terminal.light .panel-overline),
.root :global(.scan-terminal.light .detail-summary-supporting),
.root :global(.scan-terminal.light .detail-value-muted),
.root :global(.scan-terminal.light .detail-empty-state),
.root :global(.scan-terminal.light .scan-time-remaining),
.root :global(.scan-terminal.light .scan-detail-city-sub),
.root :global(.scan-terminal.light .scan-detail-volume-caption),
.root :global(.scan-terminal.light .scan-empty-copy),
.root :global(.scan-terminal.light .scan-loading-copy-block span),
.root :global(.scan-terminal.light .scan-kv span:first-child),
.root :global(.scan-terminal.light .scan-chart-label),
.root :global(.scan-terminal.light .scan-trade-sub),
.root :global(.scan-terminal.light .scan-trade-note) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-loading-copy-block strong) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-loading-signal) {
border-color: #dbeafe;
background:
radial-gradient(circle at 18% 18%, rgba(59, 130, 246, 0.12), transparent 34%),
linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(241, 245, 249, 0.9));
box-shadow: 0 16px 34px rgba(40, 70, 110, 0.1);
}
.root :global(.scan-terminal.light .scan-loading-signal.compact) {
background:
radial-gradient(circle at 18% 18%, rgba(59, 130, 246, 0.1), transparent 34%),
rgba(255, 255, 255, 0.78);
}
.root :global(.scan-terminal.light .scan-empty-icon),
.root :global(.scan-terminal.light .scan-error-icon) {
background: rgba(37, 99, 235, 0.08);
border-color: rgba(37, 99, 235, 0.16);
}
.root :global(.scan-terminal.light .scan-error-icon) {
background: rgba(239, 68, 68, 0.06);
border-color: rgba(239, 68, 68, 0.14);
}
.root :global(.scan-terminal.light .scan-retry-button) {
background: rgba(37, 99, 235, 0.08);
border-color: rgba(37, 99, 235, 0.22);
color: #2563EB;
}
.root :global(.scan-terminal.light .scan-retry-button:hover) {
background: rgba(37, 99, 235, 0.14);
border-color: rgba(37, 99, 235, 0.38);
}
.root :global(.scan-terminal.light .scan-loading-node) {
background: var(--bg-card);
border-color: rgba(148, 163, 184, 0.22);
}
.root :global(.scan-terminal.light .scan-loading-node.hot) {
background: linear-gradient(135deg, #f97316, #fde047);
}
.root :global(.scan-terminal.light .scan-loading-node.market) {
background: linear-gradient(135deg, #38bdf8, #2563eb);
}
.root :global(.scan-terminal.light .scan-loading-node.action) {
background: linear-gradient(135deg, #16a34a, #22c55e);
}
.root :global(.scan-terminal.light .scan-list-tabs button),
.root :global(.scan-terminal.light .scan-mode-tab-sub),
.root :global(.scan-terminal.light .scan-opportunity-models em),
.root :global(.scan-terminal.light .scan-opportunity-stat small),
.root :global(.scan-terminal.light .panel-meta-chip),
.root :global(.scan-terminal.light .panel-weather-chip),
.root :global(.scan-terminal.light .scan-distribution-card),
.root :global(.scan-terminal.light .scan-chart-legend) {
color: #94A3B8;
}
.root :global(.scan-terminal.light .scan-distribution-line em) {
color: #243b5a;
}
.root :global(.scan-terminal.light .scan-distribution-line b) {
color: #6f86a4;
}
.root :global(.scan-terminal.light .scan-mode-tab),
.root :global(.scan-terminal.light .scan-table-shell),
.root :global(.scan-terminal.light .scan-table-header),
.root :global(.scan-terminal.light .scan-summary-card),
.root :global(.scan-terminal.light .scan-settings-card),
.root :global(.scan-terminal.light .scan-distribution-card),
.root :global(.scan-terminal.light .scan-opportunity-group),
.root :global(.scan-terminal.light .detail-summary-shell),
.root :global(.scan-terminal.light .detail-structured-section),
.root :global(.scan-terminal.light .detail-card),
.root :global(.scan-terminal.light .scan-trade-card) {
border-color: var(--border-glass);
background: var(--bg-card);
}
.root :global(.scan-terminal.light .scan-mode-tab.active) {
color: #1D4ED8;
background: #DBEAFE;
border-color: rgba(59, 130, 246, 0.34);
box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.16);
}
.root :global(.scan-terminal.light .scan-mode-tab.active .scan-mode-tab-label) {
color: #1D4ED8;
}
.root :global(.scan-terminal.light .scan-mode-tab.active .scan-mode-tab-sub) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-mode-tab.active .scan-mode-icon) {
background: rgba(16, 185, 129, 0.16);
color: #069668;
}
.root :global(.scan-terminal.light .scan-table-row.selected) {
background: linear-gradient(180deg, rgba(228, 252, 242, 0.92), rgba(241, 250, 247, 0.96));
border-color: rgba(10, 160, 100, 0.34);
box-shadow: inset 0 0 0 1px rgba(10, 160, 100, 0.18);
}
.root :global(.scan-terminal.light .scan-table-row) {
background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(247, 250, 254, 0.9));
border-bottom-color: rgba(35, 72, 118, 0.08);
}
.root :global(.scan-terminal.light .scan-table-row:hover) {
background: linear-gradient(180deg, rgba(248, 252, 255, 0.96), rgba(238, 247, 255, 0.96));
}
.root :global(.scan-terminal.light .scan-opportunity-phase > span) {
color: #14253a;
}
.root :global(.scan-terminal.light .scan-opportunity-group-head) {
background: rgba(246, 250, 255, 0.78);
border-bottom-color: rgba(35, 72, 118, 0.1);
}
.root :global(.scan-terminal.light .scan-opportunity-item) {
background: rgba(255, 255, 255, 0.62);
color: #405977;
border-bottom-color: rgba(35, 72, 118, 0.08);
border-color: rgba(35, 72, 118, 0.1);
}
.root :global(.scan-terminal.light .scan-opportunity-item:hover) {
background: rgba(230, 242, 255, 0.76);
}
.root :global(.scan-terminal.light .scan-opportunity-item.selected) {
background: linear-gradient(180deg, rgba(222, 250, 238, 0.9), rgba(241, 250, 247, 0.96));
border-color: rgba(10, 160, 100, 0.34);
}
.root :global(.scan-terminal.light .scan-opportunity-group.selected) {
border-color: rgba(10, 160, 100, 0.34);
box-shadow: inset 0 0 0 1px rgba(10, 160, 100, 0.18);
}
.root :global(.scan-terminal.light .scan-opportunity-models span) {
border-color: rgba(35, 72, 118, 0.1);
background: rgba(255, 255, 255, 0.68);
}
.root :global(.scan-terminal.light .scan-opportunity-stat) {
border-color: rgba(35, 72, 118, 0.1);
background: rgba(248, 252, 255, 0.76);
}
.root :global(.scan-terminal.light .scan-opportunity-models b),
.root :global(.scan-terminal.light .scan-opportunity-stat b) {
color: #14253a;
}
.root :global(.scan-terminal.light .scan-opportunity-branch::before),
.root :global(.scan-terminal.light .scan-opportunity-branch i) {
background: rgba(56, 86, 126, 0.24);
}
.root :global(.scan-terminal.light .panel-header),
.root :global(.scan-terminal.light .panel-body section) {
border-color: rgba(35, 72, 118, 0.1);
}
.root :global(.scan-terminal.light .panel-action-button-secondary),
.root :global(.scan-terminal.light .panel-action-button-ghost) {
border-color: rgba(35, 72, 118, 0.14);
background: rgba(255, 255, 255, 0.76);
}
.root :global(.scan-terminal.light .detail-summary-shell-live) {
background: linear-gradient(180deg, rgba(224, 247, 255, 0.82), rgba(241, 248, 255, 0.92));
}
.root :global(.scan-terminal.light .scan-locale-switch),
.root :global(.scan-terminal.light .scan-ghost-button),
.root :global(.scan-terminal.light .scan-theme-button),
.root :global(.scan-terminal.light .scan-sort-pill),
.root :global(.scan-terminal.light .scan-icon-pill),
.root :global(.scan-terminal.light .scan-account-button),
.root :global(.scan-terminal.light .scan-detail-action-button) {
border-color: rgba(35, 72, 118, 0.14);
background: rgba(255, 255, 255, 0.78);
color: #1f3654;
}
.root :global(.scan-terminal.light .scan-primary-button) {
color: #FFFFFF;
border-color: rgba(59, 130, 246, 0.34);
background: linear-gradient(180deg, #3B82F6, #2563EB);
}
.root :global(.scan-terminal.light .scan-ai-button) {
color: #1D4ED8;
border-color: rgba(59, 130, 246, 0.28);
background: #DBEAFE;
}
.root :global(.scan-terminal.light .scan-opportunity-ai) {
border-color: rgba(35, 72, 118, 0.1);
background: rgba(248, 252, 255, 0.76);
}
.root :global(.scan-terminal.light .scan-opportunity-ai small) {
color: #647a98;
}
.root :global(.scan-terminal.light .scan-opportunity-strength) {
border-color: rgba(35, 72, 118, 0.12);
background: rgba(248, 252, 255, 0.78);
}
.root :global(.scan-terminal.light .scan-opportunity-expand) {
color: #1d4ed8;
border-color: rgba(37, 99, 235, 0.18);
background: rgba(239, 246, 255, 0.84);
}
.root :global(.scan-terminal.light .scan-v4-analysis),
.root :global(.scan-terminal.light .scan-v4-analysis section),
.root :global(.scan-terminal.light .scan-v4-evidence > div > span),
.root :global(.scan-terminal.light .scan-v4-model-sources span) {
border-color: rgba(35, 72, 118, 0.12);
background: rgba(255, 255, 255, 0.76);
}
.root :global(.scan-terminal.light .scan-v4-analysis strong) {
color: #057a6b;
}
.root :global(.scan-terminal.light .scan-v4-analysis p),
.root :global(.scan-terminal.light .scan-v4-analysis ul),
.root :global(.scan-terminal.light .scan-v4-evidence > div > span),
.root :global(.scan-terminal.light .scan-v4-model-sources em) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-v4-model-sources b) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-forecast-city-card),
.root :global(.scan-terminal.light .scan-forecast-row),
.root :global(.scan-terminal.light .scan-ai-analysis) {
border-color: var(--border-glass);
background: var(--bg-card);
}
.root :global(.scan-terminal.light .scan-forecast-city-head) {
background: var(--bg-secondary);
}
.root :global(.scan-terminal.light .scan-forecast-city-card.selected),
.root :global(.scan-terminal.light .scan-forecast-city-card:has(.scan-forecast-row.selected)) {
border-color: rgba(59, 130, 246, 0.38);
box-shadow:
inset 0 0 0 1px rgba(59, 130, 246, 0.12),
0 16px 34px rgba(40, 70, 110, 0.12);
}
.root :global(.scan-terminal.light .scan-forecast-row.selected),
.root :global(.scan-terminal.light .scan-forecast-row.expanded) {
border-color: rgba(59, 130, 246, 0.38);
background:
linear-gradient(180deg, rgba(219, 234, 254, 0.62), rgba(255, 255, 255, 0.98)),
var(--bg-card);
box-shadow: inset 4px 0 0 #3B82F6;
}
.root :global(.scan-terminal.light .scan-forecast-city-title strong),
.root :global(.scan-terminal.light .scan-forecast-city-read > b:not(.scan-phase-badge)),
.root :global(.scan-terminal.light .scan-forecast-bucket strong),
.root :global(.scan-terminal.light .scan-forecast-signals b),
.root :global(.scan-terminal.light .scan-ai-temperature-line b) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-forecast-city-chips span),
.root :global(.scan-terminal.light .scan-forecast-signals span),
.root :global(.scan-terminal.light .scan-ai-evidence-line span) {
border-color: var(--border-glass);
background: var(--bg-secondary);
}
.root :global(.scan-terminal.light .scan-forecast-city-chips span),
.root :global(.scan-terminal.light .scan-forecast-city-read span),
.root :global(.scan-terminal.light .scan-forecast-bucket small),
.root :global(.scan-terminal.light .scan-forecast-ai-line small),
.root :global(.scan-terminal.light .scan-ai-brief-grid li),
.root :global(.scan-terminal.light .scan-ai-airport-read p) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-ai-analysis-head p) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-ai-analysis-head small),
.root :global(.scan-terminal.light .scan-ai-evidence-line b) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-ai-workspace) {
background: #f7f9fc;
border-color: #e2e8f0;
}
.root :global(.scan-terminal.light .scan-opportunity-overview) {
background: #f7f9fc;
border-color: #e2e8f0;
}
.root :global(.scan-terminal.light .scan-opportunity-hero > div:first-child),
.root :global(.scan-terminal.light .scan-opportunity-summary span),
.root :global(.scan-terminal.light .scan-opportunity-lane),
.root :global(.scan-terminal.light .scan-opportunity-decision-card),
.root :global(.scan-terminal.light .scan-opportunity-decision-primary span) {
background: var(--bg-card);
border-color: var(--border-glass);
}
.root :global(.scan-terminal.light .scan-opportunity-hero strong),
.root :global(.scan-terminal.light .scan-opportunity-summary b),
.root :global(.scan-terminal.light .scan-opportunity-lane-head strong),
.root :global(.scan-terminal.light .scan-opportunity-decision-head strong),
.root :global(.scan-terminal.light .scan-opportunity-decision-primary b) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-opportunity-hero p),
.root :global(.scan-terminal.light .scan-opportunity-summary span),
.root :global(.scan-terminal.light .scan-opportunity-lane-head p),
.root :global(.scan-terminal.light .scan-opportunity-decision-card p),
.root :global(.scan-terminal.light .scan-opportunity-decision-head span),
.root :global(.scan-terminal.light .scan-opportunity-decision-primary span),
.root :global(.scan-terminal.light .scan-opportunity-decision-foot small) {
color: #64748b;
}
.root :global(.scan-terminal.light .scan-ai-city-card),
.root :global(.scan-terminal.light .scan-ai-city-hero) {
background: var(--bg-card);
border-color: var(--border-glass);
}
.root :global(.scan-terminal.light .scan-ai-city-section),
.root :global(.scan-terminal.light .scan-ai-decision-band),
.root :global(.scan-terminal.light .scan-ai-market-decision),
.root :global(.scan-terminal.light .scan-ai-market-decision-stats small),
.root :global(.scan-terminal.light .scan-ai-decision-metrics span),
.root :global(.scan-terminal.light .scan-ai-market-bucket),
.root :global(.scan-terminal.light .scan-ai-city-pills span),
.root :global(.scan-terminal.light .scan-ai-city-freshness span),
.root :global(.scan-terminal.light .scan-ai-city-metrics > span) {
background: var(--bg-secondary);
border-color: var(--border-glass);
}
.root :global(.scan-terminal.light .scan-ai-city-metrics > span.primary) {
background: #dbeafe;
border-color: rgba(59, 130, 246, 0.28);
}
.root :global(.scan-terminal.light .scan-ai-city-metrics > span.primary b) {
color: #1d4ed8;
}
.root :global(.scan-terminal.light .scan-ai-city-metrics small) {
color: #64748b;
}
.root :global(.scan-terminal.light .scan-ai-workspace-head strong),
.root :global(.scan-terminal.light .scan-ai-city-hero h3),
.root :global(.scan-terminal.light .scan-ai-city-metrics b),
.root :global(.scan-terminal.light .scan-ai-decision-band strong),
.root :global(.scan-terminal.light .scan-ai-decision-metrics b),
.root :global(.scan-terminal.light .scan-ai-market-bucket strong),
.root :global(.scan-terminal.light .scan-ai-weather-summary),
.root :global(.scan-terminal.light .scan-ai-market-decision strong),
.root :global(.scan-terminal.light .scan-ai-market-decision-stats b) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-ai-workspace-head p),
.root :global(.scan-terminal.light .scan-ai-city-section p),
.root :global(.scan-terminal.light .scan-ai-decision-band p),
.root :global(.scan-terminal.light .scan-ai-city-pills span),
.root :global(.scan-terminal.light .scan-ai-city-freshness),
.root :global(.scan-terminal.light .scan-ai-decision-metrics span),
.root :global(.scan-terminal.light .scan-ai-market-bucket span),
.root :global(.scan-terminal.light .scan-ai-market-decision span),
.root :global(.scan-terminal.light .scan-ai-market-decision p),
.root :global(.scan-terminal.light .scan-ai-market-decision-stats small),
.root :global(.scan-terminal.light .scan-ai-city-muted),
.root :global(.scan-terminal.light .scan-ai-city-loading),
.root :global(.scan-terminal.light .scan-ai-city-chart-legend),
.root :global(.scan-terminal.light .scan-ai-weather-bullets) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-ai-raw-metar) {
border-top-color: var(--border-glass);
color: #64748b;
}
.root :global(.scan-terminal.light .scan-ai-city-chart-placeholder) {
border-color: #cbd5e1;
background: #f8fafc;
color: #64748b;
}
.root :global(.scan-terminal.light .scan-ai-log-panel) {
border-color: rgba(35, 72, 118, 0.12);
background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(246, 250, 255, 0.9));
}
.root :global(.scan-terminal.light .scan-ai-log-panel.compact) {
background: rgba(255, 255, 255, 0.82);
}
.root :global(.scan-terminal.light .scan-ai-log-panel.compact .scan-ai-log-summary span) {
color: var(--text-secondary);
}
.root :global(.scan-terminal.light .scan-ai-log-panel.compact .scan-ai-log-summary strong) {
color: #2563eb;
}
.root :global(.scan-terminal.light .scan-ai-log-head strong),
.root :global(.scan-terminal.light .scan-ai-log-item b) {
color: #122033;
}
.root :global(.scan-terminal.light .scan-ai-log-head span),
.root :global(.scan-terminal.light .scan-ai-log-time),
.root :global(.scan-terminal.light .scan-ai-log-empty) {
color: #647a98;
}
.root :global(.scan-terminal.light .scan-ai-log-item) {
border-color: rgba(35, 72, 118, 0.12);
background: rgba(255, 255, 255, 0.72);
}
.root :global(.scan-terminal.light .scan-ai-log-item small) {
color: #58708f;
}
.root :global(.scan-terminal.light .scan-ai-log-item.info) {
border-color: rgba(14, 165, 233, 0.24);
}
.root :global(.scan-terminal.light .scan-ai-log-item.success) {
border-color: rgba(10, 160, 100, 0.28);
}
.root :global(.scan-terminal.light .scan-ai-log-item.warning) {
border-color: rgba(217, 119, 6, 0.28);
}
.root :global(.scan-terminal.light .scan-ai-log-item.error) {
border-color: rgba(220, 38, 38, 0.28);
}
.root :global(.scan-terminal.light .scan-ai-summary-card),
.root :global(.scan-terminal.light .scan-ai-city-card) {
background: rgba(255, 255, 255, 0.92);
border-color: rgba(148, 163, 184, 0.28);
}
.root :global(.scan-terminal.light .scan-ai-summary-card strong),
.root :global(.scan-terminal.light .scan-ai-city-head strong),
.root :global(.scan-terminal.light .scan-ai-contract b) {
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-ai-summary-card p),
.root :global(.scan-terminal.light .scan-ai-city-head p),
.root :global(.scan-terminal.light .scan-ai-contract p),
.root :global(.scan-terminal.light .scan-ai-contract small) {
color: var(--text-muted);
}
.root :global(.scan-terminal.light .scan-ai-city-head) {
background: #f8fafc;
}
.root :global(.scan-terminal.light .scan-ai-cluster-note) {
color: var(--text-secondary);
background: #f8fafc;
border-color: rgba(148, 163, 184, 0.26);
}
.root :global(.scan-terminal.light .scan-ai-contract) {
border-top-color: rgba(148, 163, 184, 0.2);
}
.root :global(.scan-terminal.light .scan-ai-inline-button) {
color: #064e3b;
background: #d1fae5;
border-color: rgba(16, 185, 129, 0.28);
}
.root :global(.scan-terminal.light .scan-cta-ghost),
.root :global(.scan-terminal.light .scan-detail-analysis-button) {
border-color: rgba(7, 160, 100, 0.24);
background: rgba(11, 188, 116, 0.12);
color: #057a4d;
}
.root :global(.scan-terminal.light .scan-score-ring::after) {
background: #f5f9fe;
}
.root :global(.scan-terminal.light .scan-score-ring span) {
color: #122033;
}
.root :global(.scan-terminal.light .scan-trade-card p) {
color: #405977;
}
.root :global(.scan-terminal.light .scan-map-shell) {
background:
radial-gradient(circle at 18% 18%, rgba(59, 130, 246, 0.12), transparent 34%),
linear-gradient(180deg, #f8fbff, #eaf3ff);
border-color: rgba(37, 99, 235, 0.16);
box-shadow: 0 16px 34px rgba(40, 70, 110, 0.12);
}
.root :global(.scan-terminal.light .scan-map-shell .map),
.root :global(.scan-terminal.light .scan-map-shell .leaflet-container) {
background: #eaf3ff !important;
}
.root :global(.scan-terminal.light .scan-map-shell .leaflet-tile) {
filter: saturate(1.06) contrast(0.98) brightness(1.04) !important;
}
.root :global(.scan-terminal.light .scan-map-caption) {
color: var(--text-muted);
}
/* ── Variable bridge: override dashboard-level CSS vars when
the scan terminal root itself carries the .light class ── */
.root:global(.light) {
--bg-primary: #eef7ff;
--bg-secondary: #e0f2fe;
--bg-card: #ffffff;
--bg-glass: rgba(255, 255, 255, 0.92);
--border-glass: #cfe8ff;
--border-subtle: rgba(125, 171, 214, 0.34);
--text-primary: #0f172a;
--text-secondary: #334155;
--text-muted: #475569;
}
/* ── Scan terminal shell light background ── */
.root :global(.scan-terminal.light) {
background:
radial-gradient(circle at 18% 12%, rgba(59, 130, 246, 0.12), transparent 30%),
linear-gradient(180deg, #eef7ff 0%, #e8f4ff 48%, #f8fbff 100%);
color: var(--text-primary);
}
.root :global(.scan-terminal.light .scan-map-shell),
.root :global(.map) {
border-color: rgba(37, 99, 235, 0.18);
box-shadow:
0 18px 40px rgba(61, 100, 145, 0.14),
inset 0 0 0 1px rgba(255, 255, 255, 0.72);
}
.root :global(.scan-terminal.light .scan-map-shell .leaflet-tile),
.root :global(.scan-terminal.light .scan-map-shell .map .leaflet-tile) {
filter: none !important;
opacity: 1 !important;
}
/* ── Leaflet map light overrides (needs !important to beat Leaflet inline styles) ── */
.root :global(.map),
html.light .root :global(.scan-terminal.light .scan-map-shell .map),
html.light .root :global(.scan-terminal.light .scan-map-shell .leaflet-container),
html.light .root :global(.leaflet-container),
html.light .root :global(.leaflet-pane),
html.light .root :global(.leaflet-map-pane),
html.light .root :global(.leaflet-tile-pane) {
background: #eef7ff !important;
}
/* ── City detail rail light overrides ── */
html.light .root :global(.scan-city-detail-rail),
html.light .root :global(.scan-terminal.light > .detail-panel.scan-city-detail-rail) {
background: linear-gradient(180deg, rgba(238, 247, 255, 0.98), rgba(255, 255, 255, 0.96));
border-color: rgba(37, 99, 235, 0.16);
color: var(--text-primary);
}
html.light .root :global(.scan-city-detail-rail .panel-header),
html.light .root :global(.scan-city-detail-rail .detail-structured-section),
html.light .root :global(.scan-city-detail-rail .detail-summary-shell),
html.light .root :global(.scan-city-detail-rail .detail-card) {
background: rgba(255, 255, 255, 0.74);
border-color: rgba(125, 171, 214, 0.28);
}
html.light .root :global(.scan-city-detail-rail h2),
html.light .root :global(.scan-city-detail-rail h3),
html.light .root :global(.scan-city-detail-rail strong),
html.light .root :global(.scan-city-detail-rail .detail-value),
html.light .root :global(.scan-city-detail-rail .detail-summary-temp),
html.light .root :global(.scan-city-detail-rail .detail-section-head h3),
html.light .root :global(.scan-city-detail-rail .panel-title-area h2) {
color: var(--text-primary);
}
html.light .root :global(.scan-city-detail-rail p),
html.light .root :global(.scan-city-detail-rail li),
html.light .root :global(.scan-city-detail-rail small),
html.light .root :global(.scan-city-detail-rail .panel-overline),
html.light .root :global(.scan-city-detail-rail .panel-loading-hint),
html.light .root :global(.scan-city-detail-rail .panel-meta-chip),
html.light .root :global(.scan-city-detail-rail .detail-section-kicker),
html.light .root :global(.scan-city-detail-rail .detail-label),
html.light .root :global(.scan-city-detail-rail .detail-value-muted),
html.light .root :global(.scan-city-detail-rail .detail-source-note),
html.light .root :global(.scan-city-detail-rail .detail-source-kind),
html.light .root :global(.scan-city-detail-rail .detail-mini-meta),
html.light .root :global(.scan-city-detail-rail .detail-summary-supporting),
html.light .root :global(.scan-city-detail-rail .scan-detail-city-sub),
html.light .root :global(.scan-city-detail-rail .scan-detail-volume-caption),
html.light .root :global(.scan-city-detail-rail .scan-detail-score-label),
html.light .root :global(.scan-city-detail-rail .scan-detail-empty) {
color: var(--text-secondary);
}
html.light .root :global(.scan-city-detail-rail .panel-meta-chip),
html.light .root :global(.scan-city-detail-rail .panel-weather-chip),
html.light .root :global(.scan-city-detail-rail .detail-source-link),
html.light .root :global(.scan-city-detail-rail .panel-action-button-secondary),
html.light .root :global(.scan-city-detail-rail .panel-action-button-ghost) {
background: #eef7ff;
border-color: rgba(37, 99, 235, 0.18);
color: #1f3654;
}
/* ── AI city card light overrides ── */
html.light .root :global(.scan-terminal.light .scan-ai-city-card),
html.light .root :global(.scan-terminal.light .scan-ai-city-section),
html.light .root :global(.scan-terminal.light .scan-ai-decision-band),
html.light .root :global(.scan-terminal.light .scan-ai-market-decision),
html.light .root :global(.scan-terminal.light .scan-ai-decision-metrics span),
html.light .root :global(.scan-terminal.light .scan-ai-city-pills span),
html.light .root :global(.scan-terminal.light .scan-ai-city-freshness span),
html.light .root :global(.scan-terminal.light .scan-ai-city-metrics > span),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-metrics span),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-reason) {
background: #eef7ff;
border-color: rgba(37, 99, 235, 0.16);
}
html.light .root :global(.scan-terminal.light .scan-ai-city-metrics > span.primary) {
background: #dbeafe;
border-color: rgba(59, 130, 246, 0.34);
}
html.light .root :global(.scan-terminal.light .scan-ai-city-metrics b) {
color: var(--text-primary);
}
html.light .root :global(.scan-terminal.light .scan-ai-city-metrics > span.primary b) {
color: #1d4ed8;
}
html.light .root :global(.scan-terminal.light .scan-ai-city-metrics small) {
color: #64748b;
}
html.light .root :global(.scan-terminal.light .scan-ai-city-card p),
html.light .root :global(.scan-terminal.light .scan-ai-city-card li),
html.light .root :global(.scan-terminal.light .scan-ai-city-card small),
html.light .root :global(.scan-terminal.light .scan-ai-city-card span:not(.scan-ai-city-kicker)) {
color: var(--text-secondary);
}
html.light .root :global(.scan-terminal.light .scan-ai-city-status-tag.green) {
color: #047857;
}
html.light .root :global(.scan-terminal.light .scan-ai-city-status-tag.blue) {
color: #1d4ed8;
}
html.light .root :global(.scan-terminal.light .scan-ai-city-status-tag.amber) {
color: #b45309;
}
html.light .root :global(.scan-terminal.light .scan-ai-city-status-tag.red) {
color: #b91c1c;
}
/* ── Upgrade announcement light overrides ── */
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement) {
background:
radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 36%),
var(--bg-card);
border-color: rgba(37, 99, 235, 0.16);
box-shadow: 0 16px 36px rgba(61, 100, 145, 0.12);
}
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement-copy strong),
html.light .root :global(.scan-terminal.light .scan-ai-city-mobile-priority b),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-metrics b),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-reason),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-head h3),
html.light .root :global(.scan-terminal.light .scan-ai-market-mobile-line b) {
color: var(--text-primary);
}
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement-copy p),
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement li),
html.light .root :global(.scan-terminal.light .scan-ai-city-mobile-priority small),
html.light .root :global(.scan-terminal.light .scan-mobile-decision-metrics small),
html.light .root :global(.scan-terminal.light .scan-ai-market-mobile-line span) {
color: var(--text-secondary);
}
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement-copy span) {
color: #047857;
}
html.light .root :global(.scan-terminal.light .scan-upgrade-announcement li),
html.light .root :global(.scan-terminal.light .scan-ai-city-mobile-priority span),
html.light .root :global(.scan-terminal.light .scan-ai-decision-why),
html.light .root :global(.scan-terminal.light .scan-ai-market-mobile-line) {
background: #eef7ff;
border-color: rgba(37, 99, 235, 0.16);
}
html.light .root :global(.scan-terminal.light .scan-ai-decision-why) {
color: #1d4ed8;
}
/* ── Section titles ── */
html.light .root :global(.scan-terminal.light .scan-ai-city-section-title) {
color: #1d4ed8;
}
html.light .root :global(.scan-terminal.light .scan-ai-decision-band span) {
color: #1d4ed8;
}
html.light .root :global(.scan-terminal.light .scan-ai-decision-band p) {
color: var(--text-muted);
}
html.light .root :global(.scan-terminal.light .scan-ai-decision-band strong) {
color: var(--text-primary);
}
/* ── Scrollbar light overrides ── */
html.light .root :global(.scan-terminal.light .scan-ai-city-body) {
scrollbar-color: rgba(37, 99, 235, 0.18) transparent;
}
html.light .root :global(.scan-ai-city-body::-webkit-scrollbar-thumb) {
background: rgba(37, 99, 235, 0.22);
}
/* ── AI prediction dual-card light mode ── */
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card) {
background: var(--bg-card);
border-color: var(--border-glass);
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card.ai) {
background: linear-gradient(180deg, rgba(219, 234, 254, 0.52), var(--bg-card));
border-color: rgba(14, 165, 233, 0.28);
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card.deb) {
background: var(--bg-card);
border-color: var(--border-glass);
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card small) {
color: #64748b;
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card strong) {
color: var(--text-primary);
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card.ai strong) {
color: #0369a1;
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card em) {
color: #64748b;
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card.ai.pending) {
background: rgba(219, 234, 254, 0.28);
border-color: rgba(14, 165, 233, 0.16);
}
html.light .root :global(.scan-terminal.light .scan-ai-prediction-card.ai.pending strong) {
color: #94a3b8;
}
html.light .root :global(.scan-terminal.light .scan-ai-confidence) {
background: rgba(59, 130, 246, 0.1);
color: #2563eb;
}
html.light .root :global(.scan-terminal.light .scan-ai-confidence.high) {
background: rgba(16, 185, 129, 0.12);
color: #047857;
}
html.light .root :global(.scan-terminal.light .scan-ai-confidence.medium) {
background: rgba(245, 158, 11, 0.12);
color: #b45309;
}
html.light .root :global(.scan-terminal.light .scan-ai-confidence.low) {
background: rgba(148, 163, 184, 0.12);
color: #64748b;
}
html.light .root :global(.scan-terminal.light .scan-ai-confidence.neutral) {
background: rgba(148, 163, 184, 0.08);
color: #64748b;
}
/* ── Empty / Error / Retry light overrides ── */
html.light .root :global(.scan-terminal.light .scan-empty-title),
html.light .root :global(.scan-terminal.light .scan-error-title) {
color: var(--text-primary);
}
html.light .root :global(.scan-terminal.light .scan-empty-copy),
html.light .root :global(.scan-terminal.light .scan-error-copy) {
color: var(--text-muted);
}
html.light .root :global(.scan-terminal.light .scan-empty-icon) {
background: rgba(37, 99, 235, 0.08);
border-color: rgba(37, 99, 235, 0.2);
color: #2563EB;
}
html.light .root :global(.scan-terminal.light .scan-error-icon) {
background: rgba(239, 68, 68, 0.06);
border-color: rgba(239, 68, 68, 0.18);
color: #DC2626;
}
html.light .root :global(.scan-terminal.light .scan-retry-button) {
background: rgba(37, 99, 235, 0.08);
border-color: rgba(37, 99, 235, 0.24);
color: #2563EB;
}
html.light .root :global(.scan-terminal.light .scan-retry-button:hover) {
background: rgba(37, 99, 235, 0.14);
}
/* ── AMOS runway panel light overrides ── */
html.light .root :global(.scan-terminal.light .scan-amos-runway-panel) {
background: rgba(37, 99, 235, 0.03);
border-color: rgba(37, 99, 235, 0.12);
}
html.light .root :global(.scan-terminal.light .scan-amos-runway-card) {
background: var(--bg-card);
border-color: rgba(37, 99, 235, 0.08);
}
html.light .root :global(.scan-terminal.light .scan-amos-runway-label) {
color: #2563EB;
}
html.light .root :global(.scan-terminal.light .scan-amos-runway-temp) {
color: var(--text-primary);
}
html.light .root :global(.scan-terminal.light .scan-amos-source-tag) {
background: rgba(37, 99, 235, 0.08);
color: #2563EB;
}
html.light .root :global(.scan-terminal.light .scan-amos-runway-detail) {
color: #64748B;
}
@@ -45,6 +45,7 @@ import {
useScanTerminalTheme,
useUserLocalClock,
} from "@/components/dashboard/scan-terminal/use-scan-terminal-ui-state";
import { useRelativeTime } from "@/hooks/useRelativeTime";
const MonitorPanel = dynamic(
() => import("@/components/dashboard/monitoring/MonitorPanel"),
{ ssr: false },
@@ -113,6 +114,20 @@ function ScanTerminalScreen() {
const userLocalTime = useUserLocalClock();
const { setThemeMode, themeMode } = useScanTerminalTheme();
const lastMapSelectedCityRef = useRef<string>("");
const lastFetchedAtRef = useRef<number>(0);
const serverAgeText = useRelativeTime(terminalData?.generated_at ?? null);
const localAgeText = useRelativeTime(
lastFetchedAtRef.current
? new Date(lastFetchedAtRef.current).toISOString()
: null,
);
useEffect(() => {
if (terminalData?.generated_at) {
lastFetchedAtRef.current = Date.now();
}
}, [terminalData?.generated_at]);
const scanTerminalRootClassName = clsx(
styles.root,
scanRootClass,
@@ -446,20 +461,13 @@ function ScanTerminalScreen() {
</div>
<div className="scan-list-status">
{terminalData?.generated_at ? (
<span className="scan-status-chip live">
{isEn ? "Updated" : "已更新"}{" "}
{new Date(terminalData.generated_at).toLocaleTimeString(
isEn ? "en-US" : "zh-CN",
{
hour: "2-digit",
minute: "2-digit",
},
)}
<span className={clsx("scan-status-chip", terminalData?.stale ? "stale" : "live")}>
{isEn ? "Updated" : "已更新"} {serverAgeText || ""}
</span>
) : null}
{terminalData?.stale ? (
{terminalData?.stale && localAgeText ? (
<span className="scan-status-chip stale">
{isEn ? "Delayed snapshot" : "延迟快照"}
{isEn ? "Local fetch " : "本地下发 "}{localAgeText}
</span>
) : null}
{isPro ? (
File diff suppressed because it is too large Load Diff
+373 -422
View File
@@ -1,11 +1,15 @@
"use client";
import { CSSProperties, useEffect, useRef, useState } from "react";
import * as THREE from "three";
import { CSSProperties, useEffect, useMemo, useState } from "react";
import { useDashboardSelection } from "@/hooks/useDashboardStore";
import { usePrefersReducedMotion } from "@/hooks/usePrefersReducedMotion";
import { getWeatherAuraProfile } from "@/lib/weather-aura";
import styles from "./Dashboard.module.css";
/*
Pure-CSS weather-aura particle layer
Replaces the former Three.js WebGL implementation with
CSS @keyframes animations no canvas, no WebGL.
*/
function hexToRgba(hex: string, alpha: number) {
const sanitized = hex.replace("#", "");
@@ -23,453 +27,390 @@ function hexToRgba(hex: string, alpha: number) {
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
/* ── Injection-safe style IDs ── */
const AURA_STYLE_ID = "poly-aura-keyframes";
/* ── CSS @keyframes (injected once via <style>) ── */
const PARTICLE_KEYFRAMES = `
@keyframes aura-float {
0% { transform: translate(0, 0); opacity: 0; }
10% { opacity: var(--p-op, 0.5); }
50% { transform: translate(var(--p-dx, 40px), var(--p-dy, -15px)); }
90% { opacity: var(--p-op, 0.5); }
100% { transform: translate(calc(var(--p-dx, 40px) * 1.4), var(--p-dy, 5px)); opacity: 0; }
}
@keyframes aura-rain {
0% { transform: translateY(-30px); opacity: 0; }
5% { opacity: 0.75; }
100% { transform: translateY(calc(100vh + 30px)); opacity: 0; }
}
@keyframes aura-snow {
0% { transform: translate(0, -20px); opacity: 0; }
15% { opacity: 0.9; }
50% { transform: translate(var(--s-sway, 25px), 50vh); }
100% { transform: translate(calc(var(--s-sway, 25px) * -1.2), calc(100vh + 20px)); opacity: 0; }
}
@keyframes aura-fog {
0% { transform: translateX(-30px); opacity: 0; }
20% { opacity: var(--f-op, 0.12); }
80% { opacity: var(--f-op, 0.12); }
100% { transform: translateX(calc(100vw + 30px)); opacity: 0; }
}
@keyframes aura-cloud {
0% { transform: translateX(-50px); opacity: 0; }
20% { opacity: var(--c-op, 0.1); }
80% { opacity: var(--c-op, 0.1); }
100% { transform: translateX(calc(100vw + 50px)); opacity: 0; }
}
@keyframes aura-storm-flash {
0%, 100% { opacity: 0; }
3% { opacity: 0.18; }
6% { opacity: 0; }
25% { opacity: 0; }
28% { opacity: 0.12; }
31% { opacity: 0; }
}
.aura-particle {
position: absolute;
pointer-events: none;
will-change: transform, opacity;
border-radius: 50%;
}
`;
/* ── Particle config type ── */
interface Particle {
id: number;
keyframe: string;
style: CSSProperties;
}
/* ── Particle generators ── */
function genFloatParticles(
count: number,
color: string,
baseOpacity: number,
sizeMin: number,
sizeMax: number,
idOffset: number,
intensity: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const size = sizeMin + Math.random() * (sizeMax - sizeMin);
const op = baseOpacity * (0.35 + Math.random() * 0.65);
const dx = (15 + Math.random() * 50) * (intensity * 0.75);
const dy = (-4 - Math.random() * 14) * intensity;
out.push({
id: idOffset + i,
keyframe: "aura-float",
style: {
left: `${Math.random() * 100}%`,
top: `${Math.random() * 100}%`,
width: size,
height: size,
background: color,
boxShadow: `0 0 ${size * 3}px ${color}`,
"--p-op": op,
"--p-dx": `${dx}px`,
"--p-dy": `${dy}px`,
animationDuration: `${10 + Math.random() * 14}s`,
animationDelay: `${Math.random() * 8}s`,
animationTimingFunction: "ease-in-out",
animationIterationCount: "infinite",
animationName: "aura-float",
opacity: 0,
} as unknown as CSSProperties,
});
}
return out;
}
function genRainParticles(
count: number,
idOffset: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const h = 8 + Math.random() * 10;
out.push({
id: idOffset + i,
keyframe: "aura-rain",
style: {
left: `${Math.random() * 100}%`,
top: `${-5 - Math.random() * 10}%`,
width: 1.5,
height: h,
borderRadius: "1px",
background: "linear-gradient(180deg, transparent, rgba(111, 183, 255, 0.85))",
opacity: 0.5 + Math.random() * 0.4,
animationDuration: `${0.5 + Math.random() * 0.5}s`,
animationDelay: `${Math.random() * 2}s`,
animationTimingFunction: "linear",
animationIterationCount: "infinite",
animationName: "aura-rain",
} as CSSProperties,
});
}
return out;
}
function genSnowParticles(
count: number,
idOffset: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const size = 2.5 + Math.random() * 4.5;
const sway = 12 + Math.random() * 28;
out.push({
id: idOffset + i,
keyframe: "aura-snow",
style: {
left: `${Math.random() * 100}%`,
top: `${-10 - Math.random() * 15}%`,
width: size,
height: size,
background: "rgba(248, 250, 252, 0.92)",
boxShadow: `0 0 ${size * 2}px rgba(248, 250, 252, 0.35)`,
"--s-sway": `${sway}px`,
opacity: 0.6 + Math.random() * 0.35,
animationDuration: `${4.5 + Math.random() * 7}s`,
animationDelay: `${Math.random() * 5}s`,
animationTimingFunction: "ease-in-out",
animationIterationCount: "infinite",
animationName: "aura-snow",
} as unknown as CSSProperties,
});
}
return out;
}
function genFogParticles(
count: number,
intensity: number,
idOffset: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const w = 40 + Math.random() * 70;
const h = 18 + Math.random() * 32;
out.push({
id: idOffset + i,
keyframe: "aura-fog",
style: {
left: `${-5 - Math.random() * 10}%`,
top: `${5 + Math.random() * 75}%`,
width: w,
height: h,
background: `radial-gradient(circle, rgba(203, 213, 225, 0.12), transparent 70%)`,
filter: `blur(${8 + Math.random() * 10}px)`,
borderRadius: "50%",
"--f-op": (0.08 + Math.random() * 0.08) * intensity,
animationDuration: `${18 + Math.random() * 18}s`,
animationDelay: `${Math.random() * 12}s`,
animationTimingFunction: "linear",
animationIterationCount: "infinite",
animationName: "aura-fog",
opacity: 0,
} as unknown as CSSProperties,
});
}
return out;
}
function genCloudParticles(
count: number,
idOffset: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const w = 60 + Math.random() * 90;
const h = 22 + Math.random() * 38;
out.push({
id: idOffset + i,
keyframe: "aura-cloud",
style: {
left: `${-10 - Math.random() * 15}%`,
top: `${5 + Math.random() * 45}%`,
width: w,
height: h,
background: `radial-gradient(circle, rgba(219, 234, 254, 0.08), transparent 70%)`,
filter: `blur(${14 + Math.random() * 12}px)`,
borderRadius: "50%",
"--c-op": 0.06 + Math.random() * 0.06,
animationDuration: `${28 + Math.random() * 22}s`,
animationDelay: `${Math.random() * 14}s`,
animationTimingFunction: "linear",
animationIterationCount: "infinite",
animationName: "aura-cloud",
opacity: 0,
} as unknown as CSSProperties,
});
}
return out;
}
function genWindParticles(
count: number,
color: string,
idOffset: number,
): Particle[] {
const out: Particle[] = [];
for (let i = 0; i < count; i++) {
const size = 1.5 + Math.random() * 2.5;
out.push({
id: idOffset + i,
keyframe: "aura-float",
style: {
left: `${-5 - Math.random() * 8}%`,
top: `${Math.random() * 100}%`,
width: size,
height: size,
background: color,
boxShadow: `0 0 ${size * 2}px ${color}`,
"--p-op": 0.35 + Math.random() * 0.3,
"--p-dx": `${120 + Math.random() * 180}px`,
"--p-dy": `${-2 + Math.random() * 4}px`,
animationDuration: `${2.5 + Math.random() * 3.5}s`,
animationDelay: `${Math.random() * 3}s`,
animationTimingFunction: "linear",
animationIterationCount: "infinite",
animationName: "aura-float",
opacity: 0,
} as unknown as CSSProperties,
});
}
return out;
}
/* ── Component ── */
export function WeatherAuraLayer() {
const { cities, selectedDetail } = useDashboardSelection();
const prefersReducedMotion = usePrefersReducedMotion();
const [isDesktop, setIsDesktop] = useState(false);
const containerRef = useRef<HTMLDivElement | null>(null);
const aura = getWeatherAuraProfile(selectedDetail, cities);
/* Inject keyframes once */
useEffect(() => {
if (typeof window === "undefined" || !window.matchMedia) {
return;
}
const mediaQuery = window.matchMedia("(min-width: 1024px)");
const apply = () => {
setIsDesktop(mediaQuery.matches);
};
apply();
mediaQuery.addEventListener("change", apply);
if (document.getElementById(AURA_STYLE_ID)) return;
const el = document.createElement("style");
el.id = AURA_STYLE_ID;
el.textContent = PARTICLE_KEYFRAMES;
document.head.appendChild(el);
return () => {
mediaQuery.removeEventListener("change", apply);
const existing = document.getElementById(AURA_STYLE_ID);
if (existing) existing.remove();
};
}, []);
/* Desktop media query */
useEffect(() => {
const host = containerRef.current;
if (!host || !isDesktop || prefersReducedMotion) {
return;
}
if (typeof window === "undefined" || !window.matchMedia) return;
const mq = window.matchMedia("(min-width: 1024px)");
const apply = () => setIsDesktop(mq.matches);
apply();
mq.addEventListener("change", apply);
return () => mq.removeEventListener("change", apply);
}, []);
const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
powerPreference: "low-power",
});
renderer.setClearColor(0x000000, 0);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
/* Build particles */
const particles = useMemo(() => {
if (!isDesktop || prefersReducedMotion) return [];
const list: Particle[] = [];
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 10);
camera.position.z = 2;
const clock = new THREE.Clock();
const cleanupMaterials = new Set<THREE.Material>();
const particleGroups: Array<{
kind: "flow" | "rain" | "snow" | "fog" | "cloud";
geometry: THREE.BufferGeometry;
positions: Float32Array;
baseY: Float32Array;
drift: Float32Array;
phase: Float32Array;
material: THREE.Material;
mesh: THREE.Object3D;
}> = [];
const effectLights: THREE.Light[] = [];
const flashOverlay = new THREE.Mesh(
new THREE.PlaneGeometry(2.2, 2.2),
new THREE.MeshBasicMaterial({
color: new THREE.Color("#e0f2fe"),
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
}),
/* Primary float layer */
list.push(
...genFloatParticles(30, aura.primary, aura.particleOpacity * 0.9, 2, 4, 0, aura.intensity),
);
/* Secondary float layer */
list.push(
...genFloatParticles(
20,
aura.secondary,
aura.particleOpacity * 0.6,
3,
6,
100,
aura.intensity * 0.8,
),
);
flashOverlay.position.z = -0.3;
scene.add(flashOverlay);
cleanupMaterials.add(flashOverlay.material as THREE.Material);
function createParticleField(
count: number,
pointSize: number,
opacity: number,
depthShift: number,
) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const baseY = new Float32Array(count);
const drift = new Float32Array(count);
const phase = new Float32Array(count);
const primaryColor = new THREE.Color(aura.primary);
const secondaryColor = new THREE.Color(aura.secondary);
const tertiaryColor = new THREE.Color(aura.tertiary);
for (let index = 0; index < count; index += 1) {
const offset = index * 3;
const x = Math.random() * 2.6 - 1.3;
const y = Math.random() * 1.8 - 0.9;
const z = (Math.random() * 0.8 - 0.4) + depthShift;
positions[offset] = x;
positions[offset + 1] = y;
positions[offset + 2] = z;
baseY[index] = y;
drift[index] = (0.00045 + Math.random() * 0.0012) * aura.drift;
phase[index] = Math.random() * Math.PI * 2;
const mixedColor = primaryColor
.clone()
.lerp(secondaryColor, Math.random() * 0.65)
.lerp(tertiaryColor, Math.random() * 0.4);
colors[offset] = mixedColor.r;
colors[offset + 1] = mixedColor.g;
colors[offset + 2] = mixedColor.b;
switch (aura.effect) {
case "rain": {
list.push(...genRainParticles(25, 200));
break;
}
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: pointSize,
transparent: true,
opacity,
vertexColors: true,
depthWrite: false,
blending: THREE.AdditiveBlending,
sizeAttenuation: true,
});
const points = new THREE.Points(geometry, material);
scene.add(points);
cleanupMaterials.add(material);
particleGroups.push({
geometry,
positions,
baseY,
drift,
phase,
kind: "flow",
material,
mesh: points,
});
}
function createRainField(count: number) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(count * 3);
const baseY = new Float32Array(count);
const drift = new Float32Array(count);
const phase = new Float32Array(count);
for (let index = 0; index < count; index += 1) {
const offset = index * 3;
positions[offset] = Math.random() * 2.8 - 1.4;
positions[offset + 1] = Math.random() * 2.2 - 1.1;
positions[offset + 2] = Math.random() * 0.4 - 0.2;
baseY[index] = positions[offset + 1];
drift[index] = (0.018 + Math.random() * 0.016) * aura.effectIntensity;
phase[index] = 0.004 + Math.random() * 0.004;
case "storm": {
list.push(...genRainParticles(35, 200));
break;
}
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
size: 0.018,
color: new THREE.Color("#7dd3fc"),
transparent: true,
opacity: 0.72,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geometry, material);
scene.add(points);
cleanupMaterials.add(material);
particleGroups.push({
geometry,
positions,
baseY,
drift,
phase,
kind: "rain",
material,
mesh: points,
});
}
function createSnowField(count: number) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(count * 3);
const baseY = new Float32Array(count);
const drift = new Float32Array(count);
const phase = new Float32Array(count);
for (let index = 0; index < count; index += 1) {
const offset = index * 3;
positions[offset] = Math.random() * 2.8 - 1.4;
positions[offset + 1] = Math.random() * 2.1 - 1.05;
positions[offset + 2] = Math.random() * 0.35 - 0.18;
baseY[index] = positions[offset + 1];
drift[index] = (0.0045 + Math.random() * 0.0045) * aura.effectIntensity;
phase[index] = Math.random() * Math.PI * 2;
case "snow": {
list.push(...genSnowParticles(25, 200));
break;
}
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
size: 0.024,
color: new THREE.Color("#f8fafc"),
transparent: true,
opacity: 0.85,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geometry, material);
scene.add(points);
cleanupMaterials.add(material);
particleGroups.push({
geometry,
positions,
baseY,
drift,
phase,
kind: "snow",
material,
mesh: points,
});
}
function createFogField(count: number) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(count * 3);
const baseY = new Float32Array(count);
const drift = new Float32Array(count);
const phase = new Float32Array(count);
for (let index = 0; index < count; index += 1) {
const offset = index * 3;
positions[offset] = Math.random() * 2.6 - 1.3;
positions[offset + 1] = Math.random() * 0.9 - 0.45;
positions[offset + 2] = Math.random() * 0.45 - 0.2;
baseY[index] = positions[offset + 1];
drift[index] = (0.0014 + Math.random() * 0.001) * aura.effectIntensity;
phase[index] = Math.random() * Math.PI * 2;
case "fog": {
list.push(...genFogParticles(15, aura.effectIntensity, 200));
break;
}
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
size: 0.12,
color: new THREE.Color("#cbd5e1"),
transparent: true,
opacity: 0.18,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geometry, material);
scene.add(points);
cleanupMaterials.add(material);
particleGroups.push({
geometry,
positions,
baseY,
drift,
phase,
kind: "fog",
material,
mesh: points,
});
}
function createCloudField(count: number) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(count * 3);
const baseY = new Float32Array(count);
const drift = new Float32Array(count);
const phase = new Float32Array(count);
for (let index = 0; index < count; index += 1) {
const offset = index * 3;
positions[offset] = Math.random() * 2.7 - 1.35;
positions[offset + 1] = Math.random() * 0.75 + 0.1;
positions[offset + 2] = Math.random() * 0.3 - 0.15;
baseY[index] = positions[offset + 1];
drift[index] = (0.0012 + Math.random() * 0.0009) * aura.effectIntensity;
phase[index] = Math.random() * Math.PI * 2;
case "cloud": {
list.push(...genCloudParticles(12, 200));
break;
}
case "wind": {
list.push(...genWindParticles(30, aura.primary, 200));
break;
}
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
size: 0.1,
color: new THREE.Color("#dbeafe"),
transparent: true,
opacity: 0.13,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geometry, material);
scene.add(points);
cleanupMaterials.add(material);
particleGroups.push({
geometry,
positions,
baseY,
drift,
phase,
kind: "cloud",
material,
mesh: points,
});
}
createParticleField(90, 0.018, aura.particleOpacity * 0.9, -0.1);
createParticleField(60, 0.026, aura.particleOpacity * 0.65, 0.08);
if (aura.effect === "rain" || aura.effect === "storm") {
createRainField(aura.effect === "storm" ? 240 : 170);
} else if (aura.effect === "snow") {
createSnowField(150);
} else if (aura.effect === "fog") {
createFogField(90);
} else if (aura.effect === "cloud" || aura.effect === "wind") {
createCloudField(aura.effect === "wind" ? 80 : 54);
}
/* Storm flash overlay */
if (aura.effect === "storm") {
const flashLight = new THREE.PointLight(0xdbeafe, 0, 6, 2);
flashLight.position.set(0.2, 0.9, 1.1);
scene.add(flashLight);
effectLights.push(flashLight);
list.push({
id: 999,
keyframe: "aura-storm-flash",
style: {
position: "absolute" as const,
inset: 0,
width: "100%",
height: "100%",
borderRadius: 0,
background:
"radial-gradient(ellipse at 50% 30%, rgba(219, 234, 254, 0.25), transparent 60%)",
animationDuration: "4s",
animationTimingFunction: "step-end",
animationIterationCount: "infinite",
animationName: "aura-storm-flash",
opacity: 0,
} as CSSProperties,
});
}
const resize = () => {
const width = host.clientWidth || window.innerWidth;
const height = host.clientHeight || window.innerHeight;
renderer.setSize(width, height, false);
};
resize();
host.appendChild(renderer.domElement);
let frameId = 0;
let lastFrameAt = 0;
const renderFrame = (timestamp: number) => {
frameId = window.requestAnimationFrame(renderFrame);
if (timestamp - lastFrameAt < 40) {
return;
}
lastFrameAt = timestamp;
const elapsed = clock.getElapsedTime();
for (const field of particleGroups) {
for (let index = 0; index < field.baseY.length; index += 1) {
const offset = index * 3;
if (field.kind === "flow") {
let nextX = field.positions[offset] + field.drift[index];
if (nextX > 1.35) {
nextX = -1.35;
field.baseY[index] = Math.random() * 1.8 - 0.9;
}
field.positions[offset] = nextX;
field.positions[offset + 1] =
field.baseY[index] +
Math.sin(elapsed * 0.45 + field.phase[index] + nextX * 2.4) *
0.06 *
aura.intensity;
} else if (field.kind === "rain") {
let nextY = field.positions[offset + 1] - field.drift[index];
let nextX = field.positions[offset] + field.phase[index] * aura.drift;
if (nextY < -1.12 || nextX > 1.45) {
nextY = 1.15 + Math.random() * 0.25;
nextX = Math.random() * 2.9 - 1.45;
}
field.positions[offset] = nextX;
field.positions[offset + 1] = nextY;
} else if (field.kind === "snow") {
let nextY = field.positions[offset + 1] - field.drift[index];
let nextX =
field.positions[offset] +
Math.sin(elapsed * 0.9 + field.phase[index]) * 0.0024 * aura.effectIntensity;
if (nextY < -1.1) {
nextY = 1.12 + Math.random() * 0.2;
nextX = Math.random() * 2.8 - 1.4;
}
field.positions[offset] = nextX;
field.positions[offset + 1] = nextY;
} else if (field.kind === "fog" || field.kind === "cloud") {
let nextX = field.positions[offset] + field.drift[index];
if (nextX > 1.38) {
nextX = -1.38;
field.baseY[index] =
field.kind === "cloud"
? Math.random() * 0.75 + 0.1
: Math.random() * 0.9 - 0.45;
}
field.positions[offset] = nextX;
field.positions[offset + 1] =
field.baseY[index] +
Math.sin(elapsed * 0.3 + field.phase[index]) *
(field.kind === "cloud" ? 0.03 : 0.05);
}
}
field.geometry.attributes.position.needsUpdate = true;
}
if (effectLights.length > 0) {
const flashPulse = Math.max(0, Math.sin(elapsed * 2.1) - 0.78) * 20;
for (const light of effectLights) {
if (light instanceof THREE.PointLight) {
light.intensity = flashPulse;
}
}
(flashOverlay.material as THREE.MeshBasicMaterial).opacity = Math.min(
0.18,
flashPulse / 120,
);
} else {
(flashOverlay.material as THREE.MeshBasicMaterial).opacity = 0;
}
renderer.render(scene, camera);
};
frameId = window.requestAnimationFrame(renderFrame);
window.addEventListener("resize", resize);
return () => {
window.cancelAnimationFrame(frameId);
window.removeEventListener("resize", resize);
for (const child of [...scene.children]) {
scene.remove(child);
}
for (const field of particleGroups) {
field.geometry.dispose();
}
cleanupMaterials.forEach((material) => material.dispose());
renderer.dispose();
if (renderer.domElement.parentNode === host) {
host.removeChild(renderer.domElement);
}
};
}, [
aura.drift,
aura.intensity,
aura.particleOpacity,
aura.primary,
aura.secondary,
aura.tertiary,
aura.effect,
aura.effectIntensity,
isDesktop,
prefersReducedMotion,
]);
return list;
}, [aura, isDesktop, prefersReducedMotion]);
if (!isDesktop) {
return null;
}
const overlayStyle = {
const overlayStyle: CSSProperties = {
position: "absolute",
inset: 0,
zIndex: 2,
pointerEvents: "none",
opacity: 0.96,
overflow: "hidden",
backgroundImage: [
`radial-gradient(circle at 18% 22%, ${hexToRgba(aura.primary, 0.18 * aura.intensity)}, transparent 32%)`,
`radial-gradient(circle at 78% 20%, ${hexToRgba(aura.secondary, 0.14 * aura.intensity)}, transparent 34%)`,
@@ -484,17 +425,27 @@ export function WeatherAuraLayer() {
? `linear-gradient(180deg, ${hexToRgba("#dbeafe", 0.04 * aura.effectIntensity)}, transparent 40%)`
: "none",
].join(", "),
} as CSSProperties;
};
const scrimStyle: CSSProperties = {
position: "absolute",
inset: 0,
backgroundImage: [
"linear-gradient(180deg, rgba(3, 8, 19, 0.64) 0%, rgba(5, 10, 20, 0.16) 24%, rgba(4, 8, 18, 0.1) 54%, rgba(3, 6, 14, 0.42) 100%)",
"radial-gradient(circle at 50% 60%, rgba(0, 224, 164, 0.08) 0%, rgba(123, 97, 255, 0) 48%)",
].join(", "),
};
return (
<div
ref={containerRef}
aria-hidden="true"
className={styles.weatherAura}
data-reduced-motion={prefersReducedMotion ? "true" : "false"}
style={overlayStyle}
>
<div className={styles.weatherAuraScrim} />
{particles.map((p) => (
<div key={p.id} className="aura-particle" style={p.style} />
))}
<div style={scrimStyle} />
</div>
);
}
@@ -1,5 +1,5 @@
/* Barrel: pre-combined scan-terminal root class name.
Consolidates 22 CSS Modules that are always co-imported into
Consolidates 20 CSS Modules that are always co-imported into
a single className, keeping ScanTerminalDashboard.tsx lean. */
import clsx from "clsx";
@@ -18,7 +18,6 @@ import scanTerminalBoardStyles from "./ScanTerminalBoard.module.css";
import scanTerminalCardStyles from "./ScanTerminalCard.module.css";
import scanTerminalDetailStyles from "./ScanTerminalDetail.module.css";
import scanTerminalFiltersStyles from "./ScanTerminalFilters.module.css";
import scanTerminalLightThemeStyles from "./ScanTerminalLightTheme.module.css";
import scanTerminalListStyles from "./ScanTerminalList.module.css";
import scanTerminalMobileStyles from "./ScanTerminalMobile.module.css";
import scanTerminalOpportunityStyles from "./ScanTerminalOpportunity.module.css";
@@ -41,7 +40,6 @@ export const scanRootClass = clsx(
scanTerminalOpportunityStyles.root,
scanTerminalCardStyles.root,
scanTerminalMobileStyles.root,
scanTerminalLightThemeStyles.root,
detailChromeStyles.root,
detailContentStyles.root,
detailSectionsStyles.root,
+37
View File
@@ -0,0 +1,37 @@
"use client";
import { useEffect, useState } from "react";
function relativeTime(date: Date, now: Date): string {
const diffMs = now.getTime() - date.getTime();
if (diffMs < 0) return "刚刚";
const seconds = Math.floor(diffMs / 1000);
if (seconds < 10) return "刚刚";
if (seconds < 60) return `${seconds}秒前`;
const minutes = Math.floor(seconds / 60);
if (minutes < 60) return `${minutes}分钟前`;
const hours = Math.floor(minutes / 60);
if (hours < 24) return `${hours}小时前`;
const days = Math.floor(hours / 24);
return `${days}天前`;
}
export function useRelativeTime(isoString: string | null | undefined): string {
const [tick, setTick] = useState(0);
const date = isoString ? new Date(isoString) : null;
useEffect(() => {
if (!date) return;
const interval = setInterval(() => setTick((n) => n + 1), 30_000);
const onVisible = () => setTick((n) => n + 1);
document.addEventListener("visibilitychange", onVisible);
return () => {
clearInterval(interval);
document.removeEventListener("visibilitychange", onVisible);
};
}, [date]);
if (!date || isNaN(date.getTime())) return "";
return relativeTime(date, new Date());
}
+15 -74
View File
@@ -21,15 +21,13 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-leaflet": "^5.0.0",
"tailwind-merge": "^3.3.0",
"three": "^0.183.2"
"tailwind-merge": "^3.3.0"
},
"devDependencies": {
"@types/leaflet": "^1.9.20",
"@types/node": "^22.15.21",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@types/three": "^0.183.1",
"@types/trusted-types": "^2.0.7",
"autoprefixer": "^10.4.20",
"playwright": "^1.59.1",
@@ -53,11 +51,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@dimforge/rapier3d-compat": {
"version": "0.12.0",
"dev": true,
"license": "Apache-2.0"
},
"node_modules/@img/colour": {
"version": "1.1.0",
"license": "MIT",
@@ -1204,6 +1197,7 @@
"node_modules/@supabase/supabase-js": {
"version": "2.99.1",
"license": "MIT",
"peer": true,
"dependencies": {
"@supabase/auth-js": "2.99.1",
"@supabase/functions-js": "2.99.1",
@@ -1222,11 +1216,6 @@
"tslib": "^2.8.0"
}
},
"node_modules/@tweenjs/tween.js": {
"version": "23.1.3",
"dev": true,
"license": "MIT"
},
"node_modules/@types/cookie": {
"version": "0.6.0",
"license": "MIT"
@@ -1259,6 +1248,7 @@
"version": "19.2.14",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"csstype": "^3.2.2"
}
@@ -1271,34 +1261,10 @@
"@types/react": "^19.2.0"
}
},
"node_modules/@types/stats.js": {
"version": "0.17.4",
"dev": true,
"license": "MIT"
},
"node_modules/@types/three": {
"version": "0.183.1",
"dev": true,
"license": "MIT",
"dependencies": {
"@dimforge/rapier3d-compat": "~0.12.0",
"@tweenjs/tween.js": "~23.1.3",
"@types/stats.js": "*",
"@types/webxr": ">=0.5.17",
"@webgpu/types": "*",
"fflate": "~0.8.2",
"meshoptimizer": "~1.0.1"
}
},
"node_modules/@types/trusted-types": {
"version": "2.0.7",
"license": "MIT"
},
"node_modules/@types/webxr": {
"version": "0.5.24",
"dev": true,
"license": "MIT"
},
"node_modules/@types/ws": {
"version": "8.18.1",
"license": "MIT",
@@ -1719,11 +1685,6 @@
"version": "1.14.1",
"license": "0BSD"
},
"node_modules/@webgpu/types": {
"version": "0.1.69",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"license": "MIT",
@@ -1895,6 +1856,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.9.0",
"caniuse-lite": "^1.0.30001759",
@@ -2227,11 +2189,6 @@
"reusify": "^1.0.4"
}
},
"node_modules/fflate": {
"version": "0.8.2",
"dev": true,
"license": "MIT"
},
"node_modules/fill-range": {
"version": "7.1.1",
"dev": true,
@@ -2327,7 +2284,8 @@
},
"node_modules/idb-keyval": {
"version": "6.2.1",
"license": "Apache-2.0"
"license": "Apache-2.0",
"peer": true
},
"node_modules/ieee754": {
"version": "1.2.1",
@@ -2430,6 +2388,7 @@
"version": "1.21.7",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"jiti": "bin/jiti.js"
}
@@ -2440,7 +2399,8 @@
},
"node_modules/leaflet": {
"version": "1.9.4",
"license": "BSD-2-Clause"
"license": "BSD-2-Clause",
"peer": true
},
"node_modules/lilconfig": {
"version": "3.1.3",
@@ -2515,11 +2475,6 @@
"node": ">= 8"
}
},
"node_modules/meshoptimizer": {
"version": "1.0.1",
"dev": true,
"license": "MIT"
},
"node_modules/micromatch": {
"version": "4.0.8",
"dev": true,
@@ -2664,7 +2619,6 @@
"version": "4.8.4",
"license": "MIT",
"optional": true,
"peer": true,
"bin": {
"node-gyp-build": "bin.js",
"node-gyp-build-optional": "optional.js",
@@ -2875,6 +2829,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@@ -3070,6 +3025,7 @@
"node_modules/react": {
"version": "19.2.4",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=0.10.0"
}
@@ -3077,6 +3033,7 @@
"node_modules/react-dom": {
"version": "19.2.4",
"license": "MIT",
"peer": true,
"dependencies": {
"scheduler": "^0.27.0"
},
@@ -3422,10 +3379,6 @@
"real-require": "^0.2.0"
}
},
"node_modules/three": {
"version": "0.183.2",
"license": "MIT"
},
"node_modules/tinyglobby": {
"version": "0.2.15",
"dev": true,
@@ -3461,6 +3414,7 @@
"version": "4.0.3",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -3496,6 +3450,7 @@
"version": "5.9.3",
"devOptional": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -3670,21 +3625,6 @@
"browserslist": ">= 4.21.0"
}
},
"node_modules/utf-8-validate": {
"version": "5.0.10",
"resolved": "https://registry.npmmirror.com/utf-8-validate/-/utf-8-validate-5.0.10.tgz",
"integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"engines": {
"node": ">=6.14.2"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"dev": true,
@@ -3860,6 +3800,7 @@
"node_modules/ws": {
"version": "8.19.0",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=10.0.0"
},
+1 -3
View File
@@ -24,15 +24,13 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-leaflet": "^5.0.0",
"tailwind-merge": "^3.3.0",
"three": "^0.183.2"
"tailwind-merge": "^3.3.0"
},
"devDependencies": {
"@types/leaflet": "^1.9.20",
"@types/node": "^22.15.21",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@types/three": "^0.183.1",
"@types/trusted-types": "^2.0.7",
"autoprefixer": "^10.4.20",
"playwright": "^1.59.1",
+1 -1
View File
@@ -1 +1 @@
{"background_color":"#ffffff","display":"standalone","icons":[{"sizes":"192x192","src":"/android-chrome-192x192.png","type":"image/png"},{"sizes":"512x512","src":"/android-chrome-512x512.png","type":"image/png"}],"name":"","short_name":"","theme_color":"#ffffff"}
{"background_color":"#0B1220","display":"standalone","icons":[{"sizes":"192x192","src":"/android-chrome-192x192.png","type":"image/png"},{"sizes":"512x512","src":"/android-chrome-512x512.png","type":"image/png"}],"name":"PolyWeather","short_name":"PolyWeather","theme_color":"#0B1220"}
+44
View File
@@ -0,0 +1,44 @@
const CACHE_NAME = "polyweather-v1";
const STATIC_ASSETS = ["/_next/", "/favicon"];
self.addEventListener("install", (event) => {
event.waitUntil(self.skipWaiting());
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)),
),
),
);
});
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
if (STATIC_ASSETS.some((prefix) => url.pathname.startsWith(prefix))) {
event.respondWith(
caches.open(CACHE_NAME).then((cache) =>
cache.match(event.request).then(
(cached) =>
cached ||
fetch(event.request).then((response) => {
if (response.ok) {
cache.put(event.request, response.clone());
}
return response;
}),
),
),
);
return;
}
event.respondWith(
fetch(event.request).catch(() =>
caches.match(event.request).then((cached) => cached || Response.error()),
),
);
});
+18 -16
View File
@@ -978,10 +978,14 @@ def update_daily_record(
save_history(history_file, data)
def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7, decay_factor=0.85):
"""
计算动态权重融合 (Dynamic Ensemble Blending, DEB)
根据过去 N 天各模型的 Mean Absolute Error (MAE) 计算倒数权重
根据过去 N 天各模型的加权 MAE时间衰减计算倒数权重
- 时间衰减越近的天误差权重越大 (decay_factor^days_ago)
- decay_factor=0.85 1天前权重 0.853天前 0.617天前 0.32
返回: blended_high (融合预报值), weights_info (权重展示字符串)
"""
project_root = os.path.dirname(
@@ -1001,7 +1005,6 @@ def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
dedup_note = "家族去重" if raw_forecast_count > len(current_forecasts) else ""
if city_name not in data or not data[city_name]:
# 没有历史数据,返回简单的平均/中位数
valid_vals = [v for v in current_forecasts.values() if v is not None]
if not valid_vals:
return None, "暂无模型数据"
@@ -1011,17 +1014,12 @@ def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
note = f"{note} | {dedup_note}"
return round(avg, 1), note
# 获取过去 lookback_days 天的有 actual_high 的记录
city_data = data[city_name]
sorted_dates = sorted(city_data.keys(), reverse=True)
# 我们只用真正结清(或者有比较准确最高温)的历史来算误差
# 这边简化:凡是有 actual_high 的都算进去
errors = {model: [] for model in current_forecasts.keys()}
errors: dict = {model: [] for model in current_forecasts.keys()}
days_used = 0
for date_str in sorted_dates:
# 跳过今天,今天还没出最终结果
if date_str == datetime.now().strftime("%Y-%m-%d"):
continue
@@ -1032,6 +1030,8 @@ def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
if actual is None:
continue
decay_weight = decay_factor ** days_used
for model in current_forecasts.keys():
if model in past_forecasts and past_forecasts[model] is not None:
try:
@@ -1039,13 +1039,12 @@ def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
av = float(actual)
except (TypeError, ValueError):
continue
errors[model].append(abs(pv - av))
errors[model].append((abs(pv - av), decay_weight))
days_used += 1
if days_used >= lookback_days:
break
# 如果有效历史天数 < 2 天,还是使用等权
if days_used < 2:
valid_vals = [v for v in current_forecasts.values() if v is not None]
if not valid_vals:
@@ -1056,13 +1055,16 @@ def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):
note = f"{note} | {dedup_note}"
return round(avg, 1), note
# 计算 MAE
# 计算加权 MAE(时间衰减)
maes = {}
for model, err_list in errors.items():
if err_list:
maes[model] = sum(err_list) / len(err_list)
for model, err_weighted in errors.items():
if err_weighted:
total_weight = sum(w for _e, w in err_weighted)
if total_weight > 0:
maes[model] = sum(e * w for e, w in err_weighted) / total_weight
else:
maes[model] = sum(e for e, _w in err_weighted) / len(err_weighted)
else:
# 如果某个新模型没有历史数据,给它一个平均误差
maes[model] = 2.0
# 计算权重(用 MAE 的倒数,误差越小权重越大;加 0.1 防止除以0)
+5
View File
@@ -2683,6 +2683,7 @@ def _analyze_summary(city: str, force_refresh: bool = False) -> Dict[str, Any]:
jobs = {
"settlement_current": lambda: _weather.fetch_settlement_current(city) or {},
"open_meteo": lambda: _weather.fetch_from_open_meteo(lat, lon, use_fahrenheit=is_f) or {},
"multi_model": lambda: _weather.fetch_multi_model(lat, lon, city=city, use_fahrenheit=is_f) or {},
}
if _weather._supports_aviationweather(city): # type: ignore[attr-defined]
jobs["metar"] = lambda: _weather.fetch_metar(
@@ -2710,6 +2711,7 @@ def _analyze_summary(city: str, force_refresh: bool = False) -> Dict[str, Any]:
settlement_current = fetched.get("settlement_current") or {}
open_meteo = fetched.get("open_meteo") or {}
mm = fetched.get("multi_model") or {}
utc_offset = open_meteo.get("utc_offset")
if utc_offset is None:
utc_offset = default_utc_offset
@@ -2848,6 +2850,9 @@ def _analyze_summary(city: str, force_refresh: bool = False) -> Dict[str, Any]:
current_forecasts: Dict[str, float] = {}
if om_today is not None:
current_forecasts["Open-Meteo"] = om_today
for m, v in mm.get("forecasts", {}).items():
if v is not None and not _is_excluded_model_name(m):
current_forecasts[m] = _sf(v)
if nws_high is not None:
current_forecasts["NWS"] = nws_high
if mgm_high is not None:
+6
View File
@@ -5,6 +5,7 @@ from typing import Optional
from fastapi import APIRouter, BackgroundTasks, Request
from fastapi.responses import PlainTextResponse
from web.services.dashboard_init_api import build_dashboard_init_payload
from web.services.system_api import (
get_health_payload,
get_prometheus_metrics_response,
@@ -61,3 +62,8 @@ async def system_priority_warm(
@router.get("/metrics", response_class=PlainTextResponse)
async def metrics():
return get_prometheus_metrics_response()
@router.get("/api/dashboard/init")
async def dashboard_init(request: Request):
return await build_dashboard_init_payload(request)
+90
View File
@@ -0,0 +1,90 @@
"""Dashboard init — bundled payload to reduce API waterfall on first paint."""
from __future__ import annotations
import time
from typing import Any, Dict, Optional
from fastapi import Request
from fastapi.concurrency import run_in_threadpool
from loguru import logger
import web.routes as legacy_routes
from web.services.city_api import _build_cities_payload
def _resolve_default_city(request: Request) -> Optional[str]:
tz = (
getattr(request.state, "auth_timezone", None)
or str(request.headers.get("X-User-Timezone") or "").strip()
or None
)
if tz and hasattr(legacy_routes, "TIMEZONE_DEFAULT_CITIES"):
cities_map = getattr(legacy_routes, "TIMEZONE_DEFAULT_CITIES", {})
if tz in cities_map:
return cities_map[tz]
return next(iter(getattr(legacy_routes, "DEFAULT_PREWARM_CITIES", [])), None)
async def build_dashboard_init_payload(request: Request) -> Dict[str, Any]:
started = time.perf_counter()
legacy_routes._bind_optional_supabase_identity(request)
is_pro = bool(getattr(request.state, "auth_user_id", None))
cities_payload = await run_in_threadpool(_build_cities_payload)
default_city = _resolve_default_city(request)
detail_payload: Optional[Dict[str, Any]] = None
if default_city:
try:
cached_entry = await run_in_threadpool(
legacy_routes._CACHE_DB.get_city_cache, "panel", default_city,
)
if cached_entry:
detail_payload = cached_entry.get("payload") or {}
else:
detail_payload = await run_in_threadpool(
legacy_routes._refresh_city_panel_cache, default_city, False,
)
except Exception as exc:
logger.warning(
"dashboard_init default_city={} panel failed: {}", default_city, exc
)
scan_payload: Optional[Dict[str, Any]] = None
if is_pro:
try:
scan_payload = await run_in_threadpool(
legacy_routes.build_scan_terminal_payload,
{
"scan_mode": "tradable",
"min_price": 0.05,
"max_price": 0.95,
"min_edge_pct": 2.0,
"min_liquidity": 500.0,
"market_type": "maxtemp",
"time_range": "today",
"limit": 25,
},
False,
)
except Exception as exc:
logger.warning("dashboard_init scan terminal failed: {}", exc)
duration_ms = round((time.perf_counter() - started) * 1000.0, 1)
logger.info(
"dashboard_init is_pro={} default_city={} duration_ms={}",
is_pro,
default_city,
duration_ms,
)
payload: Dict[str, Any] = {
"cities": cities_payload.get("cities", []),
"default_city": default_city or "",
"default_city_detail": detail_payload,
"is_pro": is_pro,
}
if scan_payload is not None:
payload["scan_terminal"] = scan_payload
return payload