diff --git a/src/App.tsx b/src/App.tsx index 9a874b5..33c8994 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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('map') const api = useContacts() @@ -21,10 +22,12 @@ export default function App() {
- {tab === 'map' && } - {tab === 'people' && } - {tab === 'roster' && } - {tab === 'settings' && } + + {tab === 'map' && } + {tab === 'people' && } + {tab === 'roster' && } + {tab === 'settings' && } + {api.selected && ( @@ -88,10 +89,6 @@ function HubGlobeBase({ rotY }: { rotY: number }) { - - - - @@ -119,7 +116,10 @@ function HubGlobeBase({ rotY }: { rotY: number }) { strokeWidth="1.5" /> - + ) -} +}) 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>(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 (
- - , -) +// 移动端 / WebView:关闭高开销视觉效果 +if (window.matchMedia('(hover: none), (pointer: coarse)').matches) { + document.documentElement.classList.add('perf-lite') +} + +createRoot(document.getElementById('root')!).render() diff --git a/src/store/useContacts.ts b/src/store/useContacts.ts index 01aeb05..1de1bb6 100644 --- a/src/store/useContacts.ts +++ b/src/store/useContacts.ts @@ -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(() => { diff --git a/src/styles/global.css b/src/styles/global.css index 884e8aa..5b6c36c 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -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; +} diff --git a/src/utils/rafThrottle.ts b/src/utils/rafThrottle.ts new file mode 100644 index 0000000..a7af41b --- /dev/null +++ b/src/utils/rafThrottle.ts @@ -0,0 +1,14 @@ +/** 合并同一帧内的多次回调,降低 React 重渲染频率 */ +export function createRafThrottle(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) + }) + } +}