fix: 优化留言和分享数据
This commit is contained in:
@@ -6,10 +6,10 @@ import {
|
||||
Ship,
|
||||
Shield,
|
||||
Car,
|
||||
Scan,
|
||||
Drone,
|
||||
Rocket,
|
||||
Wind,
|
||||
Anchor,
|
||||
Asterisk,
|
||||
Amphora,
|
||||
TrendingDown,
|
||||
UserCircle,
|
||||
Activity,
|
||||
@@ -35,10 +35,10 @@ export function CombatLossesPanel({ usLosses, iranLosses, conflictStats, civilia
|
||||
{ label: '战舰', icon: Ship, iconColor: 'text-blue-500', us: usLosses.warships, ir: iranLosses.warships },
|
||||
{ label: '装甲', icon: Shield, iconColor: 'text-emerald-500', us: usLosses.armor, ir: iranLosses.armor },
|
||||
{ label: '车辆', icon: Car, iconColor: 'text-slate-400', us: usLosses.vehicles, ir: iranLosses.vehicles },
|
||||
{ label: '无人机', icon: Scan, iconColor: 'text-violet-400', us: usLosses.drones ?? 0, ir: iranLosses.drones ?? 0 },
|
||||
{ label: '无人机', icon: Drone, iconColor: 'text-violet-400', us: usLosses.drones ?? 0, ir: iranLosses.drones ?? 0 },
|
||||
{ label: '导弹', icon: Rocket, iconColor: 'text-orange-500', us: usLosses.missiles ?? 0, ir: iranLosses.missiles ?? 0 },
|
||||
{ label: '直升机', icon: Wind, iconColor: 'text-teal-400', us: usLosses.helicopters ?? 0, ir: iranLosses.helicopters ?? 0 },
|
||||
{ label: '潜艇', icon: Anchor, iconColor: 'text-indigo-400', us: usLosses.submarines ?? 0, ir: iranLosses.submarines ?? 0 },
|
||||
{ label: '直升机', icon: Asterisk, iconColor: 'text-teal-400', us: usLosses.helicopters ?? 0, ir: iranLosses.helicopters ?? 0 },
|
||||
{ label: '潜艇', icon: Amphora, iconColor: 'text-indigo-400', us: usLosses.submarines ?? 0, ir: iranLosses.submarines ?? 0 },
|
||||
]
|
||||
|
||||
return (
|
||||
|
||||
@@ -25,6 +25,8 @@ export function HeaderPanel() {
|
||||
const [liked, setLiked] = useState(false)
|
||||
const [viewers, setViewers] = useState(0)
|
||||
const [cumulative, setCumulative] = useState(0)
|
||||
const [feedbackCount, setFeedbackCount] = useState(0)
|
||||
const [shareCount, setShareCount] = useState(0)
|
||||
const [feedbackOpen, setFeedbackOpen] = useState(false)
|
||||
const [feedbackText, setFeedbackText] = useState('')
|
||||
const [feedbackSending, setFeedbackSending] = useState(false)
|
||||
@@ -41,6 +43,8 @@ export function HeaderPanel() {
|
||||
const data = await res.json()
|
||||
if (data.viewers != null) setViewers(data.viewers)
|
||||
if (data.cumulative != null) setCumulative(data.cumulative)
|
||||
if (data.feedbackCount != null) setFeedbackCount(data.feedbackCount)
|
||||
if (data.shareCount != null) setShareCount(data.shareCount)
|
||||
} catch {
|
||||
setViewers((v) => (v > 0 ? v : 0))
|
||||
setCumulative((c) => (c > 0 ? c : 0))
|
||||
@@ -56,16 +60,27 @@ export function HeaderPanel() {
|
||||
const handleShare = async () => {
|
||||
const url = window.location.href
|
||||
const title = '美伊军事态势显示'
|
||||
let shared = false
|
||||
if (typeof navigator.share === 'function') {
|
||||
try {
|
||||
await navigator.share({ title, url })
|
||||
shared = true
|
||||
} catch (e) {
|
||||
if ((e as Error).name !== 'AbortError') {
|
||||
await copyToClipboard(url)
|
||||
shared = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await copyToClipboard(url)
|
||||
shared = true
|
||||
}
|
||||
if (shared) {
|
||||
try {
|
||||
const res = await fetch('/api/share', { method: 'POST' })
|
||||
const data = await res.json()
|
||||
if (data.shareCount != null) setShareCount(data.shareCount)
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +102,7 @@ export function HeaderPanel() {
|
||||
if (data.ok) {
|
||||
setFeedbackText('')
|
||||
setFeedbackDone(true)
|
||||
setFeedbackCount((c) => c + 1)
|
||||
setTimeout(() => {
|
||||
setFeedbackOpen(false)
|
||||
setFeedbackDone(false)
|
||||
@@ -163,7 +179,7 @@ export function HeaderPanel() {
|
||||
className="flex shrink-0 items-center gap-1 rounded border border-military-border px-1.5 py-0.5 text-[9px] text-military-text-secondary hover:bg-military-border/30 hover:text-cyan-400 sm:px-2 sm:py-1 sm:text-[10px]"
|
||||
>
|
||||
<MessageSquare className="h-2.5 w-2.5 sm:h-3 sm:w-3" />
|
||||
留言
|
||||
留言 {feedbackCount > 0 && <span className="tabular-nums">{feedbackCount}</span>}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@@ -171,7 +187,7 @@ export function HeaderPanel() {
|
||||
className="flex shrink-0 items-center gap-1 rounded border border-military-border px-1.5 py-0.5 text-[9px] text-military-text-secondary hover:bg-military-border/30 hover:text-cyan-400 sm:px-2 sm:py-1 sm:text-[10px]"
|
||||
>
|
||||
<Share2 className="h-2.5 w-2.5 sm:h-3 sm:w-3" />
|
||||
分享
|
||||
分享 {shareCount > 0 && <span className="tabular-nums">{shareCount}</span>}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -39,18 +39,19 @@ export function Dashboard() {
|
||||
<div className="h-[45vmin] min-h-[180px] w-full shrink-0 xl:min-h-0 xl:flex-1">
|
||||
<WarMap />
|
||||
</div>
|
||||
{/* 竖屏:战损→美国基地→伊朗基地。xl:美国基地|战损(中)|伊朗基地 */}
|
||||
<div className="flex shrink-0 flex-col gap-2 overflow-x-auto border-t border-military-border bg-military-panel/95 px-3 py-2 xl:flex-row xl:items-stretch xl:overflow-visible xl:px-4">
|
||||
<BaseStatusPanel keyLocations={situation.usForces.keyLocations} className="order-2 shrink-0 xl:order-1 xl:min-w-[200px] xl:border-r xl:border-military-border xl:pr-4" />
|
||||
<CombatLossesPanel
|
||||
usLosses={situation.usForces.combatLosses}
|
||||
iranLosses={situation.iranForces.combatLosses}
|
||||
conflictStats={situation.conflictStats}
|
||||
civilianTotal={situation.civilianCasualtiesTotal}
|
||||
className="min-w-0 flex-1 shrink-0 py-1"
|
||||
className="order-1 min-w-0 flex-1 shrink-0 py-1 xl:order-2"
|
||||
/>
|
||||
<BaseStatusPanel keyLocations={situation.usForces.keyLocations} className="shrink-0 xl:min-w-[200px] xl:border-r xl:border-military-border xl:pr-4" />
|
||||
<IranBaseStatusPanel
|
||||
keyLocations={situation.iranForces.keyLocations}
|
||||
className="min-w-0 shrink-0 xl:min-w-[200px]"
|
||||
className="order-3 min-w-0 shrink-0 xl:min-w-[200px]"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user