2026-08-05 15:54:59 +08:00
|
|
|
|
<script setup lang="ts">
|
2026-09-11 17:20:58 +08:00
|
|
|
|
import dayjs from 'dayjs'
|
2026-08-05 15:54:59 +08:00
|
|
|
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
|
|
|
|
import {
|
|
|
|
|
|
Expand,
|
|
|
|
|
|
Minimize,
|
2026-09-11 17:20:58 +08:00
|
|
|
|
RefreshCw,
|
2026-08-05 15:54:59 +08:00
|
|
|
|
} from '@lucide/vue'
|
2026-08-10 16:24:54 +08:00
|
|
|
|
import AdminPage from '@/shared/components/AdminPage.vue'
|
2026-09-11 17:20:58 +08:00
|
|
|
|
import {
|
|
|
|
|
|
getActiveCustomerCount,
|
|
|
|
|
|
getDashboardOperationalMetrics,
|
|
|
|
|
|
getTodayNewOrderCount,
|
|
|
|
|
|
type DashboardOperationalMetrics,
|
|
|
|
|
|
} from '../api/dashboard'
|
2026-08-05 15:54:59 +08:00
|
|
|
|
|
|
|
|
|
|
const dashboardRef = ref<HTMLElement | null>(null)
|
|
|
|
|
|
const isFullscreen = ref(false)
|
2026-09-11 17:20:58 +08:00
|
|
|
|
const metricsLoading = ref(true)
|
|
|
|
|
|
const metricsError = ref(false)
|
|
|
|
|
|
const todayNewOrderCount = ref<number | null>(null)
|
|
|
|
|
|
const activeCustomerCount = ref<number | null>(null)
|
|
|
|
|
|
const operationalMetrics = ref<DashboardOperationalMetrics | null>(null)
|
|
|
|
|
|
const metricsUpdatedAt = ref<string | null>(null)
|
2026-08-05 15:54:59 +08:00
|
|
|
|
|
2026-09-11 17:20:58 +08:00
|
|
|
|
function displayNumber(value: number | null | undefined, maximumFractionDigits = 0) {
|
|
|
|
|
|
if (metricsLoading.value) return '…'
|
|
|
|
|
|
if (value === null || value === undefined) return '—'
|
|
|
|
|
|
return new Intl.NumberFormat('zh-CN', { maximumFractionDigits }).format(value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const metrics = computed(() => [
|
|
|
|
|
|
{ label: '今日新运单', value: displayNumber(todayNewOrderCount.value), unit: '票', note: '按今日创建时间统计', tone: 'blue' },
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '在途柜量', value: displayNumber(operationalMetrics.value?.inTransitTeu, 2), unit: 'TEU',
|
|
|
|
|
|
note: operationalMetrics.value
|
|
|
|
|
|
? `已开船未到仓 · ${operationalMetrics.value.inTransitContainerCount} 柜${operationalMetrics.value.unknownContainerTypeCount ? ` · ${operationalMetrics.value.unknownContainerTypeCount} 柜箱型未知` : ''}`
|
|
|
|
|
|
: '已开船且尚未到仓',
|
|
|
|
|
|
tone: 'green',
|
|
|
|
|
|
},
|
|
|
|
|
|
{ label: '活跃客户', value: displayNumber(activeCustomerCount.value), unit: '家', note: '客户状态为启用', tone: 'purple' },
|
|
|
|
|
|
{ label: '待清关票数', value: displayNumber(operationalMetrics.value?.pendingCustomsOrderCount), unit: '票', note: '已进入清关且尚未完成', tone: 'rose' },
|
|
|
|
|
|
])
|
2026-08-05 15:54:59 +08:00
|
|
|
|
|
|
|
|
|
|
async function toggleFullscreen() {
|
|
|
|
|
|
if (!document.fullscreenElement) await dashboardRef.value?.requestFullscreen()
|
|
|
|
|
|
else await document.exitFullscreen()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function syncFullscreenState() {
|
|
|
|
|
|
isFullscreen.value = document.fullscreenElement === dashboardRef.value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-11 17:20:58 +08:00
|
|
|
|
async function loadMetrics() {
|
|
|
|
|
|
metricsLoading.value = true
|
|
|
|
|
|
metricsError.value = false
|
|
|
|
|
|
const [orders, customers, operations] = await Promise.allSettled([
|
|
|
|
|
|
getTodayNewOrderCount(),
|
|
|
|
|
|
getActiveCustomerCount(),
|
|
|
|
|
|
getDashboardOperationalMetrics(),
|
|
|
|
|
|
])
|
|
|
|
|
|
todayNewOrderCount.value = orders.status === 'fulfilled' ? orders.value : null
|
|
|
|
|
|
activeCustomerCount.value = customers.status === 'fulfilled' ? customers.value : null
|
|
|
|
|
|
operationalMetrics.value = operations.status === 'fulfilled' ? operations.value : null
|
|
|
|
|
|
metricsError.value = [orders, customers, operations].some(result => result.status === 'rejected')
|
|
|
|
|
|
metricsUpdatedAt.value = operations.status === 'fulfilled' && operations.value.asOf
|
|
|
|
|
|
? operations.value.asOf
|
|
|
|
|
|
: dayjs().format('YYYY-MM-DDTHH:mm:ss')
|
|
|
|
|
|
metricsLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
document.addEventListener('fullscreenchange', syncFullscreenState)
|
|
|
|
|
|
void loadMetrics()
|
|
|
|
|
|
})
|
2026-08-05 15:54:59 +08:00
|
|
|
|
onBeforeUnmount(() => document.removeEventListener('fullscreenchange', syncFullscreenState))
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<!--
|
2026-09-14 13:48:15 +08:00
|
|
|
|
THESIS: 首页只承载已经接通真实业务数据的四项核心指标。
|
2026-08-05 15:54:59 +08:00
|
|
|
|
OWN-WORLD: 延续 Admin 冷灰工作面、白色数据面板和柏悦蓝主色;状态色只承担分类与告警。
|
2026-09-14 13:48:15 +08:00
|
|
|
|
STORY: 运营人员进入首页后直接识别当前核心体量。
|
|
|
|
|
|
FIRST VIEWPORT: 顶部状态栏与四项核心指标完整占据首屏。
|
2026-08-05 15:54:59 +08:00
|
|
|
|
FORM: 既有后台视觉体系的经营驾驶舱结构,基于用户提供的正式原型直接扩展。
|
|
|
|
|
|
FINISH: unreviewed and undocumented is unfinished; this build ends with the finish review, the verdict, and DESIGN.md
|
|
|
|
|
|
-->
|
|
|
|
|
|
<section ref="dashboardRef" class="dashboard-view">
|
2026-08-10 16:24:54 +08:00
|
|
|
|
<AdminPage as="div" spacing="normal">
|
|
|
|
|
|
<section class="dashboard-context" aria-label="数据看板说明">
|
2026-09-14 13:48:15 +08:00
|
|
|
|
<p>{{ metricsError ? '部分核心指标加载失败,可刷新重试。' : '核心指标来自实时业务数据。' }}</p>
|
2026-08-10 16:24:54 +08:00
|
|
|
|
<div class="dashboard-head-actions">
|
2026-09-11 17:20:58 +08:00
|
|
|
|
<span>数据更新时间:{{ metricsUpdatedAt ? dayjs(metricsUpdatedAt).format('YYYY-MM-DD HH:mm') : '加载中' }}</span>
|
|
|
|
|
|
<button type="button" class="dashboard-outline-button" :disabled="metricsLoading" @click="loadMetrics">
|
|
|
|
|
|
<RefreshCw :size="16" aria-hidden="true" />
|
|
|
|
|
|
刷新数据
|
|
|
|
|
|
</button>
|
2026-08-10 16:24:54 +08:00
|
|
|
|
<button type="button" class="dashboard-outline-button" :aria-pressed="isFullscreen" @click="toggleFullscreen">
|
|
|
|
|
|
<Minimize v-if="isFullscreen" :size="16" aria-hidden="true" />
|
|
|
|
|
|
<Expand v-else :size="16" aria-hidden="true" />
|
|
|
|
|
|
{{ isFullscreen ? '退出全屏' : '全屏展示' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
2026-08-05 15:54:59 +08:00
|
|
|
|
|
2026-09-14 13:48:15 +08:00
|
|
|
|
<div class="dashboard-metrics" aria-label="核心业务指标">
|
|
|
|
|
|
<article v-for="metric in metrics" :key="metric.label" class="dashboard-metric" :class="`is-${metric.tone}`">
|
|
|
|
|
|
<span class="dashboard-metric-mark" aria-hidden="true" />
|
|
|
|
|
|
<p>{{ metric.label }}</p>
|
|
|
|
|
|
<strong>{{ metric.value }} <small>{{ metric.unit }}</small></strong>
|
|
|
|
|
|
<span>{{ metric.note }}</span>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
</div>
|
2026-08-10 16:24:54 +08:00
|
|
|
|
</AdminPage>
|
2026-08-05 15:54:59 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-08-10 16:24:54 +08:00
|
|
|
|
.dashboard-view { --dashboard-panel: var(--cc-surface, #fff); display: block; min-width: 0; color: var(--cc-text, #172033); }
|
|
|
|
|
|
.dashboard-view:fullscreen { overflow: auto; padding: 24px; background: var(--cc-page, #f4f6f8); }
|
|
|
|
|
|
.dashboard-context { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 16px; }
|
|
|
|
|
|
.dashboard-context p { min-width: 0; margin: 0; color: var(--cc-muted, #667085); font-size: 12px; line-height: 1.55; }
|
|
|
|
|
|
.dashboard-head-actions { display: flex; align-items: center; gap: 14px; color: var(--cc-muted, #667085); font-size: 12px; white-space: nowrap; }
|
2026-09-14 13:48:15 +08:00
|
|
|
|
.dashboard-outline-button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--cc-border-strong, #d8deea); border-radius: var(--cc-radius-md, 6px); background: var(--cc-surface, #fff); color: var(--cc-text-secondary, #344054); cursor: pointer; transition: border-color .18s ease, background .18s ease, color .18s ease; }
|
2026-08-05 15:54:59 +08:00
|
|
|
|
.dashboard-outline-button { padding: 0 13px; }
|
2026-09-11 17:20:58 +08:00
|
|
|
|
.dashboard-outline-button:hover:not(:disabled) { border-color: var(--cc-primary); color: var(--cc-primary); }
|
|
|
|
|
|
.dashboard-outline-button:disabled { cursor: wait; opacity: .65; }
|
|
|
|
|
|
.dashboard-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
|
2026-08-05 15:54:59 +08:00
|
|
|
|
.dashboard-metric { position: relative; min-width: 0; overflow: hidden; padding: 20px; border: 1px solid var(--cc-border); border-radius: 8px; background: var(--dashboard-panel); }
|
|
|
|
|
|
.dashboard-metric-mark { position: absolute; top: -38px; right: -30px; width: 110px; height: 110px; border-radius: 50%; background: #edf1ff; }
|
|
|
|
|
|
.dashboard-metric.is-green .dashboard-metric-mark { background: #e8f7ee; }
|
|
|
|
|
|
.dashboard-metric.is-purple .dashboard-metric-mark { background: #f1eaff; }
|
|
|
|
|
|
.dashboard-metric.is-rose .dashboard-metric-mark { background: #fdeaf1; }
|
|
|
|
|
|
.dashboard-metric p { position: relative; margin: 0 0 25px; color: #5f6573; font-size: 13px; font-weight: 700; }
|
|
|
|
|
|
.dashboard-metric strong { position: relative; display: block; overflow-wrap: anywhere; font-size: 31px; line-height: 1; letter-spacing: -.02em; }
|
|
|
|
|
|
.dashboard-metric strong small { color: #525866; font-size: 12px; font-weight: 600; letter-spacing: 0; }
|
|
|
|
|
|
.dashboard-metric > span:last-child { position: relative; display: block; margin-top: 17px; color: #8a91a0; font-size: 11px; }
|
|
|
|
|
|
@media (max-width: 1180px) {
|
|
|
|
|
|
.dashboard-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
|
|
|
|
}
|
|
|
|
|
|
@media (max-width: 760px) {
|
2026-08-10 16:24:54 +08:00
|
|
|
|
.dashboard-context { align-items: flex-start; flex-direction: column; }
|
2026-08-05 15:54:59 +08:00
|
|
|
|
.dashboard-head-actions { align-items: flex-start; flex-direction: column; gap: 9px; white-space: normal; }
|
|
|
|
|
|
.dashboard-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
|
|
|
|
}
|
|
|
|
|
|
@media (max-width: 420px) {
|
|
|
|
|
|
.dashboard-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
|
|
|
|
|
|
.dashboard-metric { min-height: 116px; padding: 13px; }
|
|
|
|
|
|
.dashboard-metric-mark { top: -30px; right: -24px; width: 80px; height: 80px; }
|
|
|
|
|
|
.dashboard-metric p { margin-bottom: 12px; font-size: 11px; }
|
|
|
|
|
|
.dashboard-metric strong { font-size: 23px; }
|
|
|
|
|
|
.dashboard-metric strong small { font-size: 10px; }
|
|
|
|
|
|
.dashboard-metric > span:last-child { margin-top: 10px; font-size: 10px; }
|
|
|
|
|
|
}
|
|
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
2026-09-14 13:48:15 +08:00
|
|
|
|
.dashboard-outline-button { transition: none; }
|
2026-08-05 15:54:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|