's'
This commit is contained in:
parent
94cb2ce681
commit
4c353a12ce
21
src/App.tsx
21
src/App.tsx
@ -1,14 +1,15 @@
|
|||||||
import { useState } from 'react'
|
import { lazy, Suspense, useState } from 'react'
|
||||||
import { AuroraBg } from './components/Layout/AuroraBg'
|
import { AuroraBg } from './components/Layout/AuroraBg'
|
||||||
import { BottomNav, type TabId } from './components/Layout/BottomNav'
|
import { BottomNav, type TabId } from './components/Layout/BottomNav'
|
||||||
import { ProfileCard } from './components/ProfileCard/ProfileCard'
|
import { ProfileCard } from './components/ProfileCard/ProfileCard'
|
||||||
import { DisguisePage } from './pages/DisguisePage'
|
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'
|
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() {
|
export default function App() {
|
||||||
const [tab, setTab] = useState<TabId>('map')
|
const [tab, setTab] = useState<TabId>('map')
|
||||||
const api = useContacts()
|
const api = useContacts()
|
||||||
@ -21,10 +22,12 @@ export default function App() {
|
|||||||
<div className="app-shell">
|
<div className="app-shell">
|
||||||
<AuroraBg />
|
<AuroraBg />
|
||||||
<main className="app-main">
|
<main className="app-main">
|
||||||
{tab === 'map' && <MapPage api={api} />}
|
<Suspense fallback={null}>
|
||||||
{tab === 'people' && <PeoplePage api={api} />}
|
{tab === 'map' && <MapPage api={api} />}
|
||||||
{tab === 'roster' && <RosterPage api={api} />}
|
{tab === 'people' && <PeoplePage api={api} />}
|
||||||
{tab === 'settings' && <SettingsPage api={api} />}
|
{tab === 'roster' && <RosterPage api={api} />}
|
||||||
|
{tab === 'settings' && <SettingsPage api={api} />}
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
{api.selected && (
|
{api.selected && (
|
||||||
<ProfileCard
|
<ProfileCard
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
.globe2d:active {
|
.globe2d:active {
|
||||||
@ -24,7 +25,17 @@
|
|||||||
width: min(88vw, 400px);
|
width: min(88vw, 400px);
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
transform-origin: center center;
|
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 {
|
@keyframes hub-globe-float {
|
||||||
@ -84,18 +95,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.hub-pulse-dot {
|
.hub-pulse-dot {
|
||||||
|
transform-box: fill-box;
|
||||||
|
transform-origin: center;
|
||||||
animation: hub-dot-pulse 2s ease-in-out infinite;
|
animation: hub-dot-pulse 2s ease-in-out infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes hub-dot-pulse {
|
@keyframes hub-dot-pulse {
|
||||||
0%,
|
0%,
|
||||||
100% {
|
100% {
|
||||||
r: 5;
|
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
r: 8;
|
opacity: 0.65;
|
||||||
opacity: 0.6;
|
transform: scale(1.35);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +122,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 浮动城市标签 — 与 nomadro hub-float-card 一致 */
|
|
||||||
.globe2d__labels {
|
.globe2d__labels {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@ -117,7 +129,7 @@
|
|||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hub-float-card {
|
.hub-float-card.globe2d__label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
@ -206,3 +218,18 @@
|
|||||||
min-width: 36px;
|
min-width: 36px;
|
||||||
text-align: center;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
memo,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
@ -7,6 +8,7 @@ import {
|
|||||||
} from 'react'
|
} from 'react'
|
||||||
import type { Contact } from '../../types/contact'
|
import type { Contact } from '../../types/contact'
|
||||||
import { clusterByCity, clusterByCountry } from '../../data/mockContacts'
|
import { clusterByCity, clusterByCountry } from '../../data/mockContacts'
|
||||||
|
import { createRafThrottle } from '../../utils/rafThrottle'
|
||||||
import './Globe2D.css'
|
import './Globe2D.css'
|
||||||
|
|
||||||
interface MarkerItem {
|
interface MarkerItem {
|
||||||
@ -79,8 +81,7 @@ function clampZoom(v: number) {
|
|||||||
return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, v))
|
return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** nomadro hub-globe SVG — 线框 + 半透明大陆 + 轨道环 */
|
const HubGlobeBase = memo(function HubGlobeBase({ rotY }: { rotY: number }) {
|
||||||
function HubGlobeBase({ rotY }: { rotY: number }) {
|
|
||||||
return (
|
return (
|
||||||
<svg className="globe2d__svg hub-globe-svg" viewBox="0 0 400 400" aria-hidden>
|
<svg className="globe2d__svg hub-globe-svg" viewBox="0 0 400 400" aria-hidden>
|
||||||
<defs>
|
<defs>
|
||||||
@ -88,10 +89,6 @@ function HubGlobeBase({ rotY }: { rotY: number }) {
|
|||||||
<stop offset="0%" stopColor="#4ECDC4" stopOpacity="0.3" />
|
<stop offset="0%" stopColor="#4ECDC4" stopOpacity="0.3" />
|
||||||
<stop offset="100%" stopColor="#4ECDC4" stopOpacity="0" />
|
<stop offset="100%" stopColor="#4ECDC4" stopOpacity="0" />
|
||||||
</radialGradient>
|
</radialGradient>
|
||||||
<linearGradient id="hubOrbitGrad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
||||||
<stop offset="0%" stopColor="#FF6B6B" />
|
|
||||||
<stop offset="100%" stopColor="#4ECDC4" />
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
</defs>
|
||||||
|
|
||||||
<circle cx={CX} cy={CY} r="160" fill="url(#hubGlobeGlow)" />
|
<circle cx={CX} cy={CY} r="160" fill="url(#hubGlobeGlow)" />
|
||||||
@ -119,7 +116,10 @@ function HubGlobeBase({ rotY }: { rotY: number }) {
|
|||||||
strokeWidth="1.5"
|
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
|
<path
|
||||||
className="hub-continent"
|
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"
|
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>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
export function Globe2D({
|
export function Globe2D({
|
||||||
contacts,
|
contacts,
|
||||||
@ -150,6 +150,7 @@ export function Globe2D({
|
|||||||
}: Globe2DProps) {
|
}: Globe2DProps) {
|
||||||
const [rotY, setRotY] = useState(0)
|
const [rotY, setRotY] = useState(0)
|
||||||
const [zoom, setZoom] = useState(1)
|
const [zoom, setZoom] = useState(1)
|
||||||
|
const [dragging, setDragging] = useState(false)
|
||||||
const zoomRef = useRef(1)
|
const zoomRef = useRef(1)
|
||||||
const pointers = useRef<Map<number, { x: number; y: number }>>(new Map())
|
const pointers = useRef<Map<number, { x: number; y: number }>>(new Map())
|
||||||
const pinch = useRef<{ dist: number; zoom: number } | null>(null)
|
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 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 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 applyZoom = (next: number) => {
|
||||||
const z = clampZoom(next)
|
const z = clampZoom(next)
|
||||||
zoomRef.current = z
|
zoomRef.current = z
|
||||||
setZoom(z)
|
setZoomThrottled(z)
|
||||||
}
|
}
|
||||||
|
|
||||||
const markers: MarkerItem[] = useMemo(() => {
|
const markers: MarkerItem[] = useMemo(() => {
|
||||||
@ -239,6 +243,7 @@ export function Globe2D({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
drag.current = { active: true, x: e.clientX, y: e.clientY, rot: rotY }
|
drag.current = { active: true, x: e.clientX, y: e.clientY, rot: rotY }
|
||||||
|
setDragging(true)
|
||||||
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
|
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,13 +257,16 @@ export function Globe2D({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!drag.current.active) 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) => {
|
const onPointerUp = (e: ReactPointerEvent) => {
|
||||||
pointers.current.delete(e.pointerId)
|
pointers.current.delete(e.pointerId)
|
||||||
if (pointers.current.size < 2) pinch.current = null
|
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 {
|
try {
|
||||||
;(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId)
|
;(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId)
|
||||||
} catch {
|
} catch {
|
||||||
@ -281,7 +289,7 @@ export function Globe2D({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="globe2d"
|
className={`globe2d${dragging ? ' globe2d--dragging' : ''}`}
|
||||||
onPointerDown={onPointerDown}
|
onPointerDown={onPointerDown}
|
||||||
onPointerMove={onPointerMove}
|
onPointerMove={onPointerMove}
|
||||||
onPointerUp={onPointerUp}
|
onPointerUp={onPointerUp}
|
||||||
@ -334,7 +342,7 @@ export function Globe2D({
|
|||||||
<button
|
<button
|
||||||
key={m.id}
|
key={m.id}
|
||||||
type="button"
|
type="button"
|
||||||
className="hub-float-card"
|
className="hub-float-card globe2d__label"
|
||||||
style={{
|
style={{
|
||||||
left: `calc(${lx}% + ${offsetX}px)`,
|
left: `calc(${lx}% + ${offsetX}px)`,
|
||||||
top: `calc(${ly}% + ${offsetY}px)`,
|
top: `calc(${ly}% + ${offsetY}px)`,
|
||||||
|
|||||||
12
src/main.tsx
12
src/main.tsx
@ -1,10 +1,10 @@
|
|||||||
import { StrictMode } from 'react'
|
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
import './styles/global.css'
|
import './styles/global.css'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')!).render(
|
// 移动端 / WebView:关闭高开销视觉效果
|
||||||
<StrictMode>
|
if (window.matchMedia('(hover: none), (pointer: coarse)').matches) {
|
||||||
<App />
|
document.documentElement.classList.add('perf-lite')
|
||||||
</StrictMode>,
|
}
|
||||||
)
|
|
||||||
|
createRoot(document.getElementById('root')!).render(<App />)
|
||||||
|
|||||||
@ -68,11 +68,13 @@ export function useContacts() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
saveContacts(contacts)
|
const t = window.setTimeout(() => saveContacts(contacts), 500)
|
||||||
|
return () => window.clearTimeout(t)
|
||||||
}, [contacts])
|
}, [contacts])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
saveSettings(settings)
|
const t = window.setTimeout(() => saveSettings(settings), 300)
|
||||||
|
return () => window.clearTimeout(t)
|
||||||
}, [settings])
|
}, [settings])
|
||||||
|
|
||||||
const occupations = useMemo(() => {
|
const occupations = useMemo(() => {
|
||||||
|
|||||||
@ -423,3 +423,42 @@ img {
|
|||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
overscroll-behavior: contain;
|
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
14
src/utils/rafThrottle.ts
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user