This commit is contained in:
Eric 2026-10-06 15:32:24 +08:00
parent 94cb2ce681
commit 4c353a12ce
7 changed files with 129 additions and 36 deletions

View File

@ -1,14 +1,15 @@
import { useState } from 'react'
import { lazy, Suspense, useState } from 'react'
import { AuroraBg } from './components/Layout/AuroraBg'
import { BottomNav, type TabId } from './components/Layout/BottomNav'
import { ProfileCard } from './components/ProfileCard/ProfileCard'
import { DisguisePage } from './pages/DisguisePage'
import { MapPage } from './pages/MapPage'
import { PeoplePage } from './pages/PeoplePage'
import { RosterPage } from './pages/RosterPage'
import { SettingsPage } from './pages/SettingsPage'
import { useContacts } from './store/useContacts'
const MapPage = lazy(() => import('./pages/MapPage').then((m) => ({ default: m.MapPage })))
const PeoplePage = lazy(() => import('./pages/PeoplePage').then((m) => ({ default: m.PeoplePage })))
const RosterPage = lazy(() => import('./pages/RosterPage').then((m) => ({ default: m.RosterPage })))
const SettingsPage = lazy(() => import('./pages/SettingsPage').then((m) => ({ default: m.SettingsPage })))
export default function App() {
const [tab, setTab] = useState<TabId>('map')
const api = useContacts()
@ -21,10 +22,12 @@ export default function App() {
<div className="app-shell">
<AuroraBg />
<main className="app-main">
{tab === 'map' && <MapPage api={api} />}
{tab === 'people' && <PeoplePage api={api} />}
{tab === 'roster' && <RosterPage api={api} />}
{tab === 'settings' && <SettingsPage api={api} />}
<Suspense fallback={null}>
{tab === 'map' && <MapPage api={api} />}
{tab === 'people' && <PeoplePage api={api} />}
{tab === 'roster' && <RosterPage api={api} />}
{tab === 'settings' && <SettingsPage api={api} />}
</Suspense>
{api.selected && (
<ProfileCard

View File

@ -9,6 +9,7 @@
user-select: none;
position: relative;
overflow: hidden;
contain: layout style;
}
.globe2d:active {
@ -24,7 +25,17 @@
width: min(88vw, 400px);
aspect-ratio: 1;
transform-origin: center center;
transition: transform 0.08s ease-out;
will-change: transform;
}
.globe2d--dragging .globe2d__float-wrap,
.globe2d--dragging .hub-orbit-ring,
.globe2d--dragging .hub-orbit-ring-2,
.globe2d--dragging .hub-continent,
.globe2d--dragging .hub-pulse-dot,
.globe2d--dragging .hub-flight-path,
.globe2d--dragging .globe2d__label {
animation-play-state: paused !important;
}
@keyframes hub-globe-float {
@ -84,18 +95,20 @@
}
.hub-pulse-dot {
transform-box: fill-box;
transform-origin: center;
animation: hub-dot-pulse 2s ease-in-out infinite;
}
@keyframes hub-dot-pulse {
0%,
100% {
r: 5;
opacity: 1;
transform: scale(1);
}
50% {
r: 8;
opacity: 0.6;
opacity: 0.65;
transform: scale(1.35);
}
}
@ -109,7 +122,6 @@
}
}
/* 浮动城市标签 — 与 nomadro hub-float-card 一致 */
.globe2d__labels {
position: absolute;
inset: 0;
@ -117,7 +129,7 @@
z-index: 5;
}
.hub-float-card {
.hub-float-card.globe2d__label {
position: absolute;
transform: translate(-50%, -50%);
z-index: 2;
@ -206,3 +218,18 @@
min-width: 36px;
text-align: center;
}
/* perf-lite:地球页减少动画 */
.perf-lite .globe2d__float-wrap,
.perf-lite .hub-orbit-ring,
.perf-lite .hub-orbit-ring-2,
.perf-lite .hub-continent,
.perf-lite .hub-flight-path,
.perf-lite .globe2d__label {
animation: none !important;
}
.perf-lite .hub-pulse-dot {
animation: none !important;
opacity: 0.9;
}

View File

@ -1,4 +1,5 @@
import {
memo,
useMemo,
useRef,
useState,
@ -7,6 +8,7 @@ import {
} from 'react'
import type { Contact } from '../../types/contact'
import { clusterByCity, clusterByCountry } from '../../data/mockContacts'
import { createRafThrottle } from '../../utils/rafThrottle'
import './Globe2D.css'
interface MarkerItem {
@ -79,8 +81,7 @@ function clampZoom(v: number) {
return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, v))
}
/** nomadro hub-globe SVG — 线框 + 半透明大陆 + 轨道环 */
function HubGlobeBase({ rotY }: { rotY: number }) {
const HubGlobeBase = memo(function HubGlobeBase({ rotY }: { rotY: number }) {
return (
<svg className="globe2d__svg hub-globe-svg" viewBox="0 0 400 400" aria-hidden>
<defs>
@ -88,10 +89,6 @@ function HubGlobeBase({ rotY }: { rotY: number }) {
<stop offset="0%" stopColor="#4ECDC4" stopOpacity="0.3" />
<stop offset="100%" stopColor="#4ECDC4" stopOpacity="0" />
</radialGradient>
<linearGradient id="hubOrbitGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stopColor="#FF6B6B" />
<stop offset="100%" stopColor="#4ECDC4" />
</linearGradient>
</defs>
<circle cx={CX} cy={CY} r="160" fill="url(#hubGlobeGlow)" />
@ -119,7 +116,10 @@ function HubGlobeBase({ rotY }: { rotY: number }) {
strokeWidth="1.5"
/>
<g className="globe2d__rotating" style={{ transformOrigin: `${CX}px ${CY}px`, transform: `rotate(${rotY * 0.35}deg)` }}>
<g
className="globe2d__rotating"
style={{ transformOrigin: `${CX}px ${CY}px`, transform: `rotate(${rotY * 0.35}deg)` }}
>
<path
className="hub-continent"
d="M160 140 Q180 130 200 135 Q220 128 240 140 Q250 155 245 170 Q235 185 220 190 Q200 195 185 188 Q165 180 160 165 Z"
@ -138,7 +138,7 @@ function HubGlobeBase({ rotY }: { rotY: number }) {
</g>
</svg>
)
}
})
export function Globe2D({
contacts,
@ -150,6 +150,7 @@ export function Globe2D({
}: Globe2DProps) {
const [rotY, setRotY] = useState(0)
const [zoom, setZoom] = useState(1)
const [dragging, setDragging] = useState(false)
const zoomRef = useRef(1)
const pointers = useRef<Map<number, { x: number; y: number }>>(new Map())
const pinch = useRef<{ dist: number; zoom: number } | null>(null)
@ -157,10 +158,13 @@ export function Globe2D({
const drag = useRef({ active: false, x: 0, y: 0, rot: 0 })
const tap = useRef<{ id: string | null; x: number; y: number }>({ id: null, x: 0, y: 0 })
const setRotYThrottled = useRef(createRafThrottle(setRotY)).current
const setZoomThrottled = useRef(createRafThrottle(setZoom)).current
const applyZoom = (next: number) => {
const z = clampZoom(next)
zoomRef.current = z
setZoom(z)
setZoomThrottled(z)
}
const markers: MarkerItem[] = useMemo(() => {
@ -239,6 +243,7 @@ export function Globe2D({
return
}
drag.current = { active: true, x: e.clientX, y: e.clientY, rot: rotY }
setDragging(true)
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
}
@ -252,13 +257,16 @@ export function Globe2D({
return
}
if (!drag.current.active) return
setRotY(drag.current.rot + (e.clientX - drag.current.x) * 0.5)
setRotYThrottled(drag.current.rot + (e.clientX - drag.current.x) * 0.5)
}
const onPointerUp = (e: ReactPointerEvent) => {
pointers.current.delete(e.pointerId)
if (pointers.current.size < 2) pinch.current = null
if (pointers.current.size === 0) drag.current.active = false
if (pointers.current.size === 0) {
drag.current.active = false
setDragging(false)
}
try {
;(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId)
} catch {
@ -281,7 +289,7 @@ export function Globe2D({
return (
<div
className="globe2d"
className={`globe2d${dragging ? ' globe2d--dragging' : ''}`}
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
@ -334,7 +342,7 @@ export function Globe2D({
<button
key={m.id}
type="button"
className="hub-float-card"
className="hub-float-card globe2d__label"
style={{
left: `calc(${lx}% + ${offsetX}px)`,
top: `calc(${ly}% + ${offsetY}px)`,

View File

@ -1,10 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './styles/global.css'
import App from './App'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
// 移动端 / WebView:关闭高开销视觉效果
if (window.matchMedia('(hover: none), (pointer: coarse)').matches) {
document.documentElement.classList.add('perf-lite')
}
createRoot(document.getElementById('root')!).render(<App />)

View File

@ -68,11 +68,13 @@ export function useContacts() {
}, [])
useEffect(() => {
saveContacts(contacts)
const t = window.setTimeout(() => saveContacts(contacts), 500)
return () => window.clearTimeout(t)
}, [contacts])
useEffect(() => {
saveSettings(settings)
const t = window.setTimeout(() => saveSettings(settings), 300)
return () => window.clearTimeout(t)
}, [settings])
const occupations = useMemo(() => {

View File

@ -423,3 +423,42 @@ img {
-webkit-overflow-scrolling: touch;
overscroll-behavior: contain;
}
/* ── 移动端性能模式(Capacitor WebView) ── */
.perf-lite {
--bg-card: rgba(17, 24, 39, 0.94);
--bg-glass: rgba(255, 255, 255, 0.06);
}
.perf-lite .gradient-text {
animation: none;
background-position: 0% center;
}
.perf-lite .glass,
.perf-lite .hub-card,
.perf-lite .hub-portal-card,
.perf-lite .hub-list-row,
.perf-lite .bottom-nav,
.perf-lite .cfp__search,
.perf-lite .cfp__toggle,
.perf-lite .cfp__grid,
.perf-lite .profile-overlay,
.perf-lite .profile-card,
.perf-lite .hub-float-card,
.perf-lite .globe2d__zoom-btn,
.perf-lite .map-topbar {
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
}
.perf-lite .aurora-bg__shape {
animation: none;
filter: blur(48px);
opacity: 0.35;
}
.perf-lite .hub-list-row,
.perf-lite .people-row {
contain: layout style;
}

14
src/utils/rafThrottle.ts Normal file
View File

@ -0,0 +1,14 @@
/** 合并同一帧内的多次回调,降低 React 重渲染频率 */
export function createRafThrottle<T>(fn: (value: T) => void) {
let pending: T | undefined
let raf = 0
return (value: T) => {
pending = value
if (raf) return
raf = requestAnimationFrame(() => {
raf = 0
if (pending !== undefined) fn(pending)
})
}
}