Files
JayuCloud/JC-Salon-Frontend/src/views/admin/SalonDashboardView.vue
T

215 lines
19 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<main class="salon-dashboard">
<header class="dashboard-head">
<div>
<span class="dashboard-eyebrow">SALON PLATFORM</span>
<h1>Salon 管理驾驶舱</h1>
<p>用门店、员工、客户和服务数据掌握平台经营状态。</p>
<div class="dashboard-freshness"><span>系统日期 {{ currentDateLabel }}</span><span>最近刷新 {{ lastRefreshedAt || '尚未刷新' }}</span></div>
</div>
<div class="dashboard-tools">
<label class="date-control"><span>统计日期</span><input v-model="date" type="date" @change="loadOverview" /></label>
<div class="range-control" role="group" aria-label="趋势范围">
<button v-for="item in ranges" :key="item.value" type="button" :class="{ active: days === item.value }" @click="changeRange(item.value)">{{ item.label }}</button>
</div>
<button class="refresh-button" type="button" :disabled="loading" @click="loadOverview"><ReloadOutlined :spin="loading" /> 刷新</button>
</div>
</header>
<a-alert v-if="overview.degraded" class="dashboard-alert" type="warning" show-icon :message="overview.degradedMessage || '经营数据暂时不可用'" description="当前页面已保留空数据展示,稍后可重新刷新。" />
<section class="kpi-strip" aria-label="今日经营指标">
<div class="kpi-item kpi-item--primary"><span class="kpi-label">{{ selectedToday ? '今日预约' : '当日预约' }}</span><strong>{{ overview.today.appointmentCount }}</strong><small>含已排期服务</small></div>
<div class="kpi-item"><span class="kpi-label">服务中</span><strong>{{ overview.today.serviceInProgressCount }}</strong><small>当前进行中的服务</small></div>
<div class="kpi-item"><span class="kpi-label">{{ selectedToday ? '今日完成' : '当日完成' }}</span><strong>{{ overview.today.completedServiceCount }}</strong><small>已完成服务</small></div>
<div class="kpi-item"><span class="kpi-label">{{ selectedToday ? '今日营业额' : '当日营业额' }}</span><strong>¥{{ money(overview.today.orderAmount) }}</strong><small>订单与历史补单</small></div>
<div class="kpi-item kpi-item--attention"><span class="kpi-label">待处理事项</span><strong>{{ attentionTotal }}</strong><small>需要管理员关注</small></div>
</section>
<div class="dashboard-grid">
<section class="dashboard-panel trend-panel">
<div class="panel-head"><div><h2>经营趋势</h2><p>最近 {{ days }} 天预约、完成和营业额</p></div><span class="panel-date">截至 {{ overview.date }}</span></div>
<div class="trend-chart" :class="{ 'trend-chart--empty': !hasTrend }">
<div v-for="item in overview.trend" :key="item.date" class="trend-column">
<div class="trend-bars">
<span class="trend-bar trend-bar--appointment" :style="{ height: `${barHeight(item.appointmentCount, maxTrendCount)}%` }" :title="`预约 ${item.appointmentCount}`" />
<span class="trend-bar trend-bar--completed" :style="{ height: `${barHeight(item.completedCount, maxTrendCount)}%` }" :title="`完成 ${item.completedCount}`" />
</div>
<strong>{{ shortDate(item.date) }}</strong>
<small>¥{{ money(item.amount) }}</small>
</div>
<div v-if="!hasTrend" class="empty-state">暂无趋势数据</div>
</div>
<div class="chart-legend"><span><i class="legend-dot legend-dot--appointment" />预约</span><span><i class="legend-dot legend-dot--completed" />完成</span><span class="legend-note">柱高按数量,金额显示在日期下方</span></div>
</section>
<section class="dashboard-panel attention-panel">
<div class="panel-head"><div><h2>待处理事项</h2><p>需要管理员进一步处理的业务</p></div><span class="attention-total">{{ attentionTotal }}</span></div>
<div class="attention-list">
<button v-for="item in attentionItems" :key="item.key" type="button" class="attention-row" @click="go(item.path)">
<span class="attention-icon" :class="`attention-icon--${item.tone}`"><component :is="item.icon" /></span>
<span class="attention-copy"><strong>{{ item.label }}</strong><small>{{ item.hint }}</small></span>
<b>{{ item.count }}</b><span class="attention-arrow">›</span>
</button>
<div v-if="attentionTotal === 0" class="empty-state empty-state--inline">当前没有待处理事项</div>
</div>
</section>
</div>
<div class="dashboard-grid dashboard-grid--lower">
<section class="dashboard-panel ranking-panel">
<div class="panel-head"><div><h2>门店经营排行</h2><p>按统计范围内的营业额排序</p></div><span class="panel-date">Top 10</span></div>
<div v-if="overview.shopRanking.length" class="ranking-list">
<div v-for="(shop, index) in overview.shopRanking" :key="String(shop.shopId)" class="ranking-row">
<span class="ranking-index">{{ String(index + 1).padStart(2, '0') }}</span>
<span class="ranking-copy"><strong>{{ shop.shopName || '未命名门店' }}</strong><small>{{ shop.appointmentCount }} 次预约 · {{ shop.completedCount }} 次完成</small></span>
<strong class="ranking-amount">¥{{ money(shop.amount) }}</strong>
</div>
</div>
<div v-else class="empty-state">暂无门店经营数据</div>
</section>
<section class="dashboard-panel assets-panel">
<div class="panel-head"><div><h2>平台资产规模</h2><p>当前启用的 Salon 业务资源</p></div></div>
<div class="asset-list">
<div class="asset-row"><span><i class="asset-mark asset-mark--shop" />门店</span><strong>{{ overview.platform.activeShopCount }}</strong><small>启用中</small></div>
<div class="asset-row"><span><i class="asset-mark asset-mark--manager" />店长</span><strong>{{ overview.platform.activeManagerCount }}</strong><small>有效账号</small></div>
<div class="asset-row"><span><i class="asset-mark asset-mark--staff" />员工</span><strong>{{ overview.platform.activeStaffCount }}</strong><small>有效账号</small></div>
<div class="asset-row"><span><i class="asset-mark asset-mark--customer" />客户</span><strong>{{ overview.platform.customerCount }}</strong><small>业务资料</small></div>
<div class="asset-row"><span><i class="asset-mark asset-mark--style" />款式</span><strong>{{ overview.platform.styleCount }}</strong><small>已公开</small></div>
</div>
</section>
</div>
</main>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ReloadOutlined, AuditOutlined, SafetyCertificateOutlined, ShoppingOutlined, TeamOutlined, WarningOutlined } from '@ant-design/icons-vue'
import { adminDashboardApi, type SalonDashboardOverviewVO } from '@/api/admin'
const router = useRouter()
const localDate = () => {
const now = new Date()
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`
}
const date = ref(localDate())
const days = ref<7 | 30>(7)
const loading = ref(false)
const lastRefreshedAt = ref('')
const overview = ref<SalonDashboardOverviewVO>(emptyOverview(date.value, days.value))
const ranges = [{ label: '7 天', value: 7 as const }, { label: '30 天', value: 30 as const }]
const currentDateLabel = computed(() => localDate())
function emptyOverview(targetDate: string, range: number): SalonDashboardOverviewVO {
return {
date: targetDate,
degraded: false,
platform: { activeShopCount: 0, activeManagerCount: 0, activeStaffCount: 0, customerCount: 0, styleCount: 0 },
today: { appointmentCount: 0, serviceInProgressCount: 0, completedServiceCount: 0, orderAmount: 0, pendingOrderCount: 0 },
attention: { registrationReviewCount: 0, contentReviewCount: 0, afterSaleCount: 0, artistChangeCount: 0, lowStockCount: 0 },
trend: Array.from({ length: range }, (_, index) => ({ date: new Date(Date.parse(targetDate) - (range - index - 1) * 86400000).toISOString().slice(0, 10), appointmentCount: 0, completedCount: 0, amount: 0 })),
shopRanking: []
}
}
const attentionTotal = computed(() => Object.values(overview.value.attention).reduce((sum, value) => sum + Number(value || 0), 0))
const selectedToday = computed(() => date.value === localDate())
const attentionItems = computed(() => [
{ key: 'registration', label: '注册审核', hint: '员工与店长申请', count: overview.value.attention.registrationReviewCount, path: '/admin/registrations', tone: 'mint', icon: AuditOutlined },
{ key: 'content', label: '内容复核', hint: '文字与图片审核', count: overview.value.attention.contentReviewCount, path: '/admin/privacy', tone: 'blue', icon: SafetyCertificateOutlined },
{ key: 'afterSale', label: '售后处理', hint: '等待管理员处理', count: overview.value.attention.afterSaleCount, path: '/admin/after-sales', tone: 'amber', icon: ShoppingOutlined },
{ key: 'artistChange', label: '改派申请', hint: '等待重新分配员工', count: overview.value.attention.artistChangeCount, path: '/admin/orders', tone: 'violet', icon: TeamOutlined },
{ key: 'stock', label: '库存异常', hint: '低于库存预警线', count: overview.value.attention.lowStockCount, path: '/admin/inventory', tone: 'red', icon: WarningOutlined }
].filter(item => item.count > 0))
const hasTrend = computed(() => overview.value.trend.some(item => item.appointmentCount || item.completedCount || item.amount))
const maxTrendCount = computed(() => Math.max(1, ...overview.value.trend.flatMap(item => [item.appointmentCount, item.completedCount])))
const money = (value: number | undefined) => Number(value || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
const shortDate = (value: string) => value.slice(5).replace('-', '/')
const barHeight = (value: number, max: number) => value ? Math.max(9, Math.round(value / max * 100)) : 3
const go = (path: string) => router.push(path)
const loadOverview = async () => {
loading.value = true
try {
const result = await adminDashboardApi.getOverview({ date: date.value, days: days.value })
overview.value = result || emptyOverview(date.value, days.value)
} catch (error: any) {
overview.value = { ...emptyOverview(date.value, days.value), degraded: true, degradedMessage: error?.message || '经营数据加载失败' }
} finally {
lastRefreshedAt.value = new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
loading.value = false
}
}
const changeRange = (range: 7 | 30) => {
days.value = range
void loadOverview()
}
onMounted(() => { void loadOverview() })
</script>
<style scoped>
.salon-dashboard { display: grid; gap: 22px; color: var(--admin-mobile-ink); }
.dashboard-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding-bottom: 5px; }
.dashboard-eyebrow { color: var(--theme-primary-action); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.dashboard-head h1 { margin: 7px 0 5px; font-size: 32px; }
.dashboard-head p { margin: 0; color: var(--admin-mobile-muted); font-size: 13px; }
.dashboard-freshness { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; color: var(--admin-mobile-muted); font-size: 11px; }
.dashboard-tools { display: flex; align-items: flex-end; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.date-control { display: grid; gap: 5px; color: var(--admin-mobile-muted); font-size: 11px; }
.date-control input { height: 34px; padding: 0 9px; border: 1px solid var(--admin-mobile-border); border-radius: 8px; background: var(--theme-card-bg); color: var(--admin-mobile-ink); font: inherit; }
.range-control { display: flex; height: 34px; padding: 3px; border: 1px solid var(--admin-mobile-border); border-radius: 8px; background: var(--theme-card-bg); }
.range-control button, .refresh-button { border: 0; border-radius: 6px; background: transparent; color: var(--admin-mobile-muted); font: inherit; font-size: 12px; cursor: pointer; }
.range-control button { padding: 0 11px; }
.range-control button.active { background: var(--admin-mobile-accent-soft); color: var(--theme-primary-action); font-weight: 700; }
.refresh-button { display: inline-flex; height: 34px; align-items: center; gap: 5px; padding: 0 11px; border: 1px solid var(--admin-mobile-border); background: var(--theme-card-bg); }
.refresh-button:disabled { cursor: wait; opacity: .6; }
.dashboard-alert { margin: -4px 0 0; }
.kpi-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--admin-mobile-border); border-bottom: 1px solid var(--admin-mobile-border); background: color-mix(in srgb, var(--theme-card-bg) 74%, transparent); }
.kpi-item { display: grid; gap: 6px; min-height: 128px; padding: 20px 18px; border-right: 1px solid var(--admin-mobile-border); }
.kpi-item:last-child { border-right: 0; }
.kpi-label { color: var(--admin-mobile-muted); font-size: 12px; }
.kpi-item strong { color: var(--admin-mobile-ink); font-size: 29px; }
.kpi-item small { color: var(--admin-mobile-muted); font-size: 11px; }
.kpi-item--primary strong { color: var(--theme-primary-action); }
.kpi-item--attention strong { color: #be7951; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .95fr); gap: 18px; }
.dashboard-grid--lower { grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); }
.dashboard-panel { min-width: 0; border-top: 2px solid var(--theme-primary); background: color-mix(in srgb, var(--theme-card-bg) 78%, transparent); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 17px 0 13px; border-bottom: 1px solid var(--admin-mobile-border); }
.panel-head h2 { margin: 0 0 4px; font-size: 16px; }
.panel-head p, .panel-date { margin: 0; color: var(--admin-mobile-muted); font-size: 11px; }
.panel-date { white-space: nowrap; }
.trend-chart { display: grid; grid-template-columns: repeat(auto-fit, minmax(34px, 1fr)); align-items: end; gap: 9px; min-height: 230px; padding: 22px 4px 9px; border-bottom: 1px solid var(--admin-mobile-border); }
.trend-column { display: grid; min-width: 0; gap: 6px; align-items: end; text-align: center; }
.trend-bars { display: flex; height: 150px; align-items: end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--admin-mobile-border); }
.trend-bar { display: block; width: 9px; min-height: 3px; border-radius: 3px 3px 0 0; transition: height .25s ease; }
.trend-bar--appointment { background: #55bfa4; }
.trend-bar--completed { background: #275f58; }
.trend-column strong { color: var(--admin-mobile-ink); font-size: 10px; font-weight: 700; }
.trend-column small { overflow: hidden; color: var(--admin-mobile-muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend { display: flex; align-items: center; gap: 15px; padding-top: 12px; color: var(--admin-mobile-muted); font-size: 11px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot--appointment { background: #55bfa4; }.legend-dot--completed { background: #275f58; }.legend-note { margin-left: auto; }
.attention-total { display: grid; place-items: center; min-width: 27px; height: 27px; border-radius: 50%; background: var(--admin-mobile-accent-soft); color: var(--theme-primary-action); font-size: 12px; font-weight: 800; }
.attention-list { display: grid; }
.attention-row { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 9px 0; border: 0; border-bottom: 1px solid var(--admin-mobile-border); background: transparent; color: inherit; text-align: left; cursor: pointer; }
.attention-row:hover { background: var(--admin-mobile-accent-soft); }
.attention-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; font-size: 14px; }
.attention-icon--mint { background: #e2f5ee; color: #2a9a7f; }.attention-icon--blue { background: #e5f0fa; color: #397ba8; }.attention-icon--amber { background: #fff2d9; color: #b77a27; }.attention-icon--violet { background: #eee8fa; color: #7559a5; }.attention-icon--red { background: #fde8e4; color: #bd665d; }
.attention-copy { display: grid; flex: 1; gap: 2px; min-width: 0; }.attention-copy strong { font-size: 12px; }.attention-copy small { color: var(--admin-mobile-muted); font-size: 10px; }.attention-row b { color: var(--admin-mobile-ink); font-size: 14px; }.attention-arrow { color: var(--admin-mobile-muted); font-size: 20px; }
.ranking-list, .asset-list { display: grid; }
.ranking-row { display: flex; align-items: center; gap: 12px; min-height: 61px; border-bottom: 1px solid var(--admin-mobile-border); }
.ranking-index { width: 26px; color: var(--theme-primary-action); font-size: 11px; font-weight: 800; }.ranking-copy { display: grid; flex: 1; gap: 3px; min-width: 0; }.ranking-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }.ranking-copy small { color: var(--admin-mobile-muted); font-size: 10px; }.ranking-amount { font-size: 12px; white-space: nowrap; }
.asset-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; min-height: 50px; border-bottom: 1px solid var(--admin-mobile-border); }.asset-row span { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }.asset-row strong { font-size: 16px; }.asset-row small { width: 46px; color: var(--admin-mobile-muted); font-size: 10px; text-align: right; }.asset-mark { width: 7px; height: 7px; border-radius: 50%; background: var(--theme-primary); }.asset-mark--manager { background: #6f9fd1; }.asset-mark--staff { background: #a887d1; }.asset-mark--customer { background: #d89b64; }.asset-mark--style { background: #78a8a1; }
.empty-state { display: grid; place-items: center; min-height: 160px; color: var(--admin-mobile-muted); font-size: 12px; }.empty-state--inline { min-height: 180px; }.trend-chart--empty { opacity: .8; }
@media (max-width: 1000px) { .dashboard-head { align-items: flex-start; flex-direction: column; }.dashboard-tools { justify-content: flex-start; }.dashboard-grid, .dashboard-grid--lower { grid-template-columns: 1fr; } }
@media (max-width: 680px) { .dashboard-head h1 { font-size: 27px; } }
@media (max-width: 680px) { .dashboard-head h1 { font-size: 27px; }.kpi-strip { grid-template-columns: repeat(2, 1fr); }.kpi-item { min-height: 100px; padding: 15px 13px; }.kpi-item:nth-child(2n) { border-right: 0; }.kpi-item:nth-child(-n+3) { border-bottom: 1px solid var(--admin-mobile-border); }.kpi-item strong { font-size: 24px; }.trend-chart { gap: 3px; }.trend-bar { width: 6px; }.chart-legend { flex-wrap: wrap; }.legend-note { width: 100%; margin-left: 0; }.dashboard-tools { width: 100%; }.date-control { flex: 1; }.date-control input { width: 100%; }.range-control button { padding: 0 8px; } }
</style>