feat(admin): 统一我的首页与综合转化统计的新版主题

This commit is contained in:
2026-12-02 09:56:13 +08:00
parent edfc67e6f6
commit d063d2a8fe
5 changed files with 649 additions and 101 deletions
+85
View File
@@ -0,0 +1,85 @@
import { onActivated, onDeactivated, onMounted, onScopeDispose, shallowRef } from 'vue'
type RGB = [number, number, number]
const unpack = (hex: string): RGB => [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16)) as RGB
const pack = (c: number[]) => '#' + c.map(n => Math.round(n).toString(16).padStart(2, '0')).join('')
const mix = (a: string, b: string, weight: number) => {
const left = unpack(a), right = unpack(b)
return pack(left.map((v, i) => v + (right[i] - v) * weight))
}
const luminance = (hex: string) => {
const [r, g, b] = unpack(hex).map(n => {
const x = n / 255
return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4
})
return r * 0.2126 + g * 0.7152 + b * 0.0722
}
const legible = (color: string, bg: string, ink: string, minimum: number) => {
const s = luminance(bg)
for (let i = 0; i <= 64; i++) {
const value = i ? mix(color, ink, i / 64) : color
const l = luminance(value)
if ((Math.max(l, s) + .05) / (Math.min(l, s) + .05) >= minimum) return value
}
return ink
}
function concrete(value: string, fallback: string) {
const str = value.trim()
if (/^#[\da-f]{6}$/i.test(str)) return str.toLowerCase()
if (/^#[\da-f]{3}$/i.test(str)) return '#' + [...str.slice(1)].map(c => c + c).join('').toLowerCase()
const rgb = str.match(/^rgb\(\s*(\d+)\s*[, ]\s*(\d+)\s*[, ]\s*(\d+)\s*\)$/i)
return rgb && rgb.slice(1).every(x => +x <= 255) ? pack(rgb.slice(1).map(Number)) : fallback
}
// Canvas doesn't inherit CSS variables: resolve the active screen theme at the boundary.
export function statsChartPalette(read: (key: string) => string, dark: boolean) {
const get = (key: string, fallback: string) => concrete(read(key), fallback)
const surface = get('--zyt-surface', dark ? '#161618' : '#ffffff')
const ink = get('--zyt-ink', dark ? '#e3e3e8' : '#323251')
const text = get('--zyt-text', dark ? '#ababba' : '#4d5875')
const accent = get('--el-color-primary', '#5d87ff')
return {
dark, accent, surface, ink, text,
accentInk: legible(accent, surface, ink, 3),
accentText: legible(accent, surface, ink, 4.5),
muted: legible(get('--zyt-muted', text), surface, ink, 4.5),
soft: get('--zyt-accent-soft', mix(surface, accent, dark ? .19 : .10)),
grid: mix(surface, text, dark ? .20 : .14),
border: get('--zyt-border', mix(surface, text, .25))
}
}
export function useStatsChartPalette() {
const palette = shallowRef<ReturnType<typeof statsChartPalette> | null>(null)
let observer: MutationObserver | undefined
let paletteSheet: Element | null = null
function refresh() {
const root = document.documentElement
// Settings writes the accent into a stylesheet, not the root's inline style.
const sheet = document.getElementById('art-theme-vars')
if (sheet && sheet !== paletteSheet && observer) {
observer.observe(sheet, { childList: true })
paletteSheet = sheet
}
if (root.dataset.adminUi !== 'v2') { palette.value = null; return }
const css = getComputedStyle(root)
const next = statsChartPalette(key => css.getPropertyValue(key), root.classList.contains('dark'))
const previous = palette.value
if (!previous || (Object.keys(next) as (keyof typeof next)[]).some(key => previous[key] !== next[key])) {
palette.value = next
}
}
function start() {
if (observer || typeof document === 'undefined') return
observer = new MutationObserver(refresh)
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['style', 'class', 'data-admin-ui'] })
observer.observe(document.head, { childList: true })
refresh()
}
function stop() { observer?.disconnect(); observer = undefined; paletteSheet = null }
onMounted(start)
onActivated(start)
onDeactivated(stop)
onScopeDispose(stop)
return palette
}
+205 -90
View File
@@ -1,8 +1,12 @@
<template>
<div class="conversion-stats-page">
<el-card class="!border-none" shadow="never">
<header v-if="palette" class="stats-page-header">
<h1>综合转化统计</h1>
<p>按部门、医助或医生查看从挂号到接诊的转化表现。</p>
</header>
<el-card class="stats-filter-card" :class="{ '!border-none': !palette }" shadow="never">
<el-form :inline="true" :model="queryParams" class="stats-filter-form">
<el-form-item label="统计维度">
<el-form-item label="统计维度" class="stats-field-wide">
<el-segmented
v-model="queryParams.dimension"
:options="dimensionOptions"
@@ -61,7 +65,7 @@
</el-select>
</el-form-item>
<el-form-item label="时间范围">
<el-form-item label="时间范围" class="stats-field-wide">
<el-radio-group v-model="queryParams.time_type" @change="handleTimeTypeChange">
<el-radio-button label="today">今天</el-radio-button>
<el-radio-button label="yesterday">昨天</el-radio-button>
@@ -71,7 +75,7 @@
</el-radio-group>
</el-form-item>
<el-form-item v-if="queryParams.time_type === 'custom'">
<el-form-item v-if="queryParams.time_type === 'custom'" class="stats-field-wide">
<el-date-picker
v-model="dateRange"
type="daterange"
@@ -84,14 +88,14 @@
/>
</el-form-item>
<el-form-item>
<el-form-item class="stats-field-wide">
<el-button type="primary" :loading="pager.loading" @click="handleQuery">查询</el-button>
<el-button @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<div class="stats-kpi-grid">
<section class="stats-kpi-grid" aria-label="核心指标">
<div
v-for="card in summaryCards"
:key="card.key"
@@ -102,14 +106,14 @@
{{ renderMetric(card.key, overview.summary, card.type, card.placeholder) }}
</div>
</div>
</div>
</section>
<el-row :gutter="20" class="mt-4">
<el-row :gutter="palette ? 16 : 20" class="mt-4">
<el-col :span="24">
<el-card class="!border-none" shadow="never">
<el-card :class="{ '!border-none': !palette }" shadow="never">
<template #header>
<div class="card-header">
<span>转化排行</span>
<span class="panel-title">转化排行</span>
<span class="card-hint">{{ dateRangeText }} · TOP 10</span>
</div>
</template>
@@ -124,12 +128,12 @@
</el-col>
</el-row>
<el-row :gutter="20" class="mt-4">
<el-row :gutter="palette ? 16 : 20" class="mt-4 stats-pie-row">
<el-col :xs="24" :lg="12">
<el-card class="!border-none" shadow="never">
<el-card :class="{ '!border-none': !palette }" shadow="never">
<template #header>
<div class="card-header">
<span>{{ amountPieTitle }}</span>
<span class="panel-title">{{ amountPieTitle }}</span>
<span class="card-hint">TOP 10</span>
</div>
</template>
@@ -143,10 +147,10 @@
</el-card>
</el-col>
<el-col :xs="24" :lg="12">
<el-card class="!border-none" shadow="never">
<el-card :class="{ '!border-none': !palette }" shadow="never">
<template #header>
<div class="card-header">
<span>{{ secondaryPieTitle }}</span>
<span class="panel-title">{{ secondaryPieTitle }}</span>
<span class="card-hint">TOP 10</span>
</div>
</template>
@@ -161,9 +165,9 @@
</el-col>
</el-row>
<el-row :gutter="20" class="mt-4">
<el-row :gutter="palette ? 16 : 20" class="mt-4">
<el-col :span="24">
<el-card class="!border-none stats-detail-card" shadow="never">
<el-card class="stats-detail-card" :class="{ '!border-none': !palette }" shadow="never">
<template #header>
<div class="card-header">
<div class="card-header-main">
@@ -215,14 +219,14 @@
组长
</el-tag>
<el-tag
v-if="row.type === 'member' && row.role"
v-if="row.type === 'member' && (row.role || (palette && !row.is_leader))"
size="small"
:type="row.role === '医生' ? 'success' : 'info'"
effect="plain"
round
class="role-tag"
>
{{ row.role }}
{{ row.role || '成员' }}
</el-tag>
<el-tag
v-if="row.type === 'unbound'"
@@ -267,6 +271,7 @@ import vCharts from 'vue-echarts'
import { getConversionStatsOverview } from '@/api/stats'
import { usePaging } from '@/hooks/usePaging'
import { useStatsChartPalette } from '@/hooks/useStatsChartPalette'
type StatsDimension = 'dept' | 'assistant' | 'doctor'
@@ -293,6 +298,7 @@ interface MetricColumn extends MetricCard {
align?: 'left' | 'center' | 'right'
}
const palette = useStatsChartPalette()
const dateRange = ref<string[]>([])
const deptTreeOptions = ref<any[]>([])
@@ -485,34 +491,62 @@ const rankingChartData = computed(() => {
}
})
const seriesPalette = computed(() => {
const skin = palette.value
if (!skin) return ['#4a78ff', '#15b8a6', '#ff9f43', '#7c3aed']
// The first series follows the picker; categorical data stays distinguishable.
return skin.dark
? [skin.accentInk, '#3bc6ad', '#ffb967', '#b99af8', '#5db9e6', '#e78eae', '#a1c276', '#df9376', '#b9ad77', '#88adb2']
: [skin.accentInk, '#158478', '#b8681a', '#895cc0', '#237da5', '#b34f81', '#60823c', '#b15b46', '#8e7739', '#487f86']
})
const tooltipSkin = computed(() => {
const skin = palette.value
return skin ? { backgroundColor: skin.surface, borderColor: skin.border, textStyle: { color: skin.ink } } : {}
})
const rankingChartOption = computed(() => {
const skin = palette.value
const axis = skin ? {
nameTextStyle: { color: skin.text },
axisLine: { lineStyle: { color: skin.grid } },
axisLabel: { color: skin.text },
splitLine: { lineStyle: { color: skin.grid } }
} : {}
const colors = seriesPalette.value
const legend = skin ? {
textStyle: { color: skin.text }, type: 'scroll',
pageIconColor: skin.accentInk, pageIconInactiveColor: skin.muted, pageTextStyle: { color: skin.text }
} : {}
const common = {
tooltip: { trigger: 'axis' },
grid: { left: 48, right: 24, top: 48, bottom: 48 },
tooltip: { trigger: 'axis', ...tooltipSkin.value },
grid: skin ? { left: 12, right: 16, top: 66, bottom: 8, containLabel: true }
: { left: 48, right: 24, top: 48, bottom: 48 },
xAxis: {
...axis,
type: 'category',
data: rankingChartData.value.names,
axisLabel: {
interval: 0,
...axis.axisLabel,
interval: skin ? 'auto' : 0,
rotate: rankingChartData.value.names.length > 6 ? 25 : 0
}
},
yAxis: [
{ type: 'value', name: '金额 / 数量' }
{ ...axis, type: 'value', name: '金额 / 数量' }
]
}
if (!isDoctorDimension.value) {
return {
...common,
legend: { data: ['诊单金额', '接诊诊单', '加粉数'] },
legend: { ...legend, data: ['诊单金额', '接诊诊单', '加粉数'] },
series: [
{
name: '诊单金额',
type: 'bar',
barMaxWidth: 36,
data: rankingChartData.value.amounts,
itemStyle: { color: '#4a78ff' }
itemStyle: { color: colors[0] }
},
{
name: '接诊诊单',
@@ -522,7 +556,7 @@ const rankingChartOption = computed(() => {
symbolSize: 8,
lineStyle: { width: 3 },
data: rankingChartData.value.orderCounts,
itemStyle: { color: '#15b8a6' }
itemStyle: { color: colors[1] }
},
{
name: '加粉数',
@@ -532,7 +566,7 @@ const rankingChartOption = computed(() => {
symbolSize: 8,
lineStyle: { width: 3 },
data: rankingChartData.value.fanCounts,
itemStyle: { color: '#ff9f43' }
itemStyle: { color: colors[2] }
}
]
}
@@ -540,14 +574,14 @@ const rankingChartOption = computed(() => {
return {
...common,
legend: { data: ['开药金额', '挂号数', '面诊数', '接诊单数'] },
legend: { ...legend, data: ['开药金额', '挂号数', '面诊数', '接诊单数'] },
series: [
{
name: '开药金额',
type: 'bar',
barMaxWidth: 36,
data: rankingChartData.value.amounts,
itemStyle: { color: '#4a78ff' }
itemStyle: { color: colors[0] }
},
{
name: '挂号数',
@@ -557,7 +591,7 @@ const rankingChartOption = computed(() => {
symbolSize: 8,
lineStyle: { width: 3 },
data: rankingChartData.value.appointmentCounts,
itemStyle: { color: '#15b8a6' }
itemStyle: { color: colors[1] }
},
{
name: '面诊数',
@@ -567,7 +601,7 @@ const rankingChartOption = computed(() => {
symbolSize: 8,
lineStyle: { width: 3 },
data: rankingChartData.value.interviewCounts,
itemStyle: { color: '#ff9f43' }
itemStyle: { color: colors[2] }
},
{
name: '接诊单数',
@@ -577,75 +611,44 @@ const rankingChartOption = computed(() => {
symbolSize: 8,
lineStyle: { width: 3 },
data: rankingChartData.value.orderCounts,
itemStyle: { color: '#7c3aed' }
itemStyle: { color: colors[3] }
}
]
}
})
const amountPieOption = computed(() => ({
tooltip: { trigger: 'item' },
legend: {
bottom: 0,
type: 'scroll',
pageIconColor: '#409eff',
pageTextStyle: {
color: '#909399',
function makePieOption(title: string, data: { name: string; value: number }[]) {
const skin = palette.value
return {
...(skin ? { color: seriesPalette.value } : {}),
tooltip: { trigger: 'item', ...tooltipSkin.value },
legend: {
bottom: 0,
type: 'scroll',
...(skin ? { textStyle: { color: skin.text }, pageIconInactiveColor: skin.muted } : {}),
pageIconColor: skin?.accentInk || '#409eff',
pageTextStyle: { color: skin?.text || '#909399' }
},
},
series: [
{
name: amountPieTitle.value,
series: [{
name: title,
type: 'pie',
radius: ['42%', '70%'],
center: ['50%', '42%'],
avoidLabelOverlap: true,
minAngle: 3,
label: {
show: true,
formatter: '{b}',
overflow: 'truncate',
width: 90,
show: true, formatter: '{b}', overflow: 'truncate', width: 90,
...(skin ? { color: skin.text } : {})
},
labelLayout: {
hideOverlap: true,
},
data: overview.charts.amount_share
}
]
}))
const secondaryPieOption = computed(() => ({
tooltip: { trigger: 'item' },
legend: {
bottom: 0,
type: 'scroll',
pageIconColor: '#409eff',
pageTextStyle: {
color: '#909399',
},
},
series: [
{
name: secondaryPieTitle.value,
type: 'pie',
radius: ['42%', '70%'],
center: ['50%', '42%'],
avoidLabelOverlap: true,
minAngle: 3,
label: {
show: true,
formatter: '{b}',
overflow: 'truncate',
width: 90,
},
labelLayout: {
hideOverlap: true,
},
data: isDoctorDimension.value ? overview.charts.order_share : overview.charts.fan_share
}
]
}))
...(skin ? { itemStyle: { borderColor: skin.surface, borderWidth: 1 } } : {}),
labelLayout: { hideOverlap: true },
data
}]
}
}
const amountPieOption = computed(() => makePieOption(amountPieTitle.value, overview.charts.amount_share))
const secondaryPieOption = computed(() => makePieOption(secondaryPieTitle.value,
isDoctorDimension.value ? overview.charts.order_share : overview.charts.fan_share))
const flattenDepts = (items: any[]): OptionItem[] => {
let result: OptionItem[] = []
@@ -918,11 +921,11 @@ onMounted(async () => {
align-items: center;
}
:deep(.member-row) td {
:root:not([data-admin-ui='v2']) .conversion-stats-page :deep(.member-row td) {
background-color: #fafbff !important;
}
:deep(.member-row--leader) td {
:root:not([data-admin-ui='v2']) .conversion-stats-page :deep(.member-row--leader td) {
background-color: #fff8ec !important;
}
@@ -931,7 +934,7 @@ onMounted(async () => {
font-weight: 600;
}
:deep(.member-row--unbound) td {
:root:not([data-admin-ui='v2']) .conversion-stats-page :deep(.member-row--unbound td) {
background-color: #fff5f5 !important;
}
@@ -952,4 +955,116 @@ onMounted(async () => {
.stats-chart-wide {
height: 380px;
}
// The shell owns the outer gutter. Restrict new surfaces and compact layout to Art.
:root[data-admin-ui='v2'] .conversion-stats-page {
--member-surface: var(--zyt-surface-subtle);
--member-ink: var(--zyt-feedback-ink);
--leader-ink: #804b11;
--unbound-ink: #9b383c;
--leader-surface: color-mix(in srgb, var(--el-color-warning) 9%, var(--zyt-surface));
--unbound-surface: color-mix(in srgb, var(--el-color-danger) 6%, var(--zyt-surface));
padding: 0;
min-width: 0;
color: var(--zyt-text);
.stats-page-header {
margin-bottom: 16px;
h1 { margin: 0; color: var(--zyt-ink); font-size: 24px; line-height: 1.35; font-weight: 600; }
p { margin: 4px 0 0; font-size: 13px; line-height: 1.6; }
}
.stats-filter-form {
display: flex;
align-items: flex-end;
flex-wrap: wrap;
gap: 12px 20px;
:deep(.el-form-item) { margin: 0; max-width: 100%; }
:deep(.el-form-item__label) { color: var(--zyt-text); }
:deep(.el-select), :deep(.el-date-editor) { max-width: 100%; }
:deep(.el-radio-button) { --el-radio-button-checked-text-color: var(--zyt-on-primary); }
:deep(.el-segmented) { --el-segmented-item-selected-color: var(--zyt-on-primary); }
}
.stats-kpi-grid {
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 12px;
}
.stats-kpi-card {
min-width: 0;
padding: 16px;
background: var(--zyt-surface);
border: 1px solid var(--zyt-card-border);
border-radius: var(--zyt-radius);
box-shadow: var(--zyt-shadow);
}
.stats-kpi-label, .card-hint { color: var(--zyt-text); }
.stats-kpi-value {
color: var(--zyt-ink);
margin-top: 8px;
font-size: 26px;
font-weight: 600;
line-height: 1.25;
overflow-wrap: anywhere;
font-variant-numeric: tabular-nums;
&.is-money { font-size: 22px; }
}
.stats-pie-row { row-gap: 16px; }
.card-header-main { width: 100%; flex-wrap: wrap; justify-content: space-between; }
.panel-title, .card-title { font-size: 16px; font-weight: 600; color: var(--zyt-ink); }
:deep(.el-card__header) { padding: 16px 20px 0; border: none; }
:deep(.el-card__body) { padding: 16px 20px; }
.stats-detail-card :deep(.el-table) {
--el-table-header-bg-color: var(--zyt-surface-subtle);
--el-table-text-color: var(--zyt-text);
--el-table-header-text-color: var(--zyt-ink);
--el-table-row-hover-bg-color: var(--zyt-hover);
--el-table-tr-bg-color: var(--zyt-surface);
}
// Each fixed name cell needs the same opaque fill as its scrolling metrics.
// Use row-local colors so hovering a member never restores a classic pale row.
:deep(.member-row) {
--member-fill: var(--member-surface);
--role-ink: var(--member-ink);
--el-table-tr-bg-color: var(--member-fill);
color: var(--zyt-text);
}
:deep(.member-row--leader) { --member-fill: var(--leader-surface); --role-ink: var(--leader-ink); }
:deep(.member-row--unbound) { --member-fill: var(--unbound-surface); --role-ink: var(--unbound-ink); }
:deep(.member-row > td) { background-color: var(--member-fill); }
:deep(.member-row:is(:hover, .hover-row) > td) { background-color: var(--zyt-hover); }
.member-icon { color: var(--role-ink); background: var(--zyt-surface); }
:deep(.member-row .entity-name) { color: var(--zyt-ink); }
.role-tag {
--el-tag-text-color: var(--role-ink);
--el-tag-bg-color: var(--zyt-surface);
--el-tag-border-color: var(--zyt-border);
}
@media (max-width: 1080px) {
.stats-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
.stats-page-header h1 { font-size: 21px; }
.stats-filter-form {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
.stats-field-wide { grid-column: 1 / -1; }
:deep(.el-form-item) { min-width: 0; flex-direction: column; align-items: stretch; }
:deep(.el-form-item__label) { justify-content: flex-start; line-height: 22px; height: auto; }
:deep(.el-form-item__content) { min-width: 0; }
:deep(.el-radio-group) { row-gap: 4px; }
:deep(.el-radio-button__inner) { padding-inline: 8px; }
}
.stats-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stats-kpi-card { padding: 12px; }
.stats-kpi-value { font-size: 23px; &.is-money { font-size: 20px; } }
:deep(.el-card__header), :deep(.el-card__body) { padding-inline: 12px; }
.stats-chart { height: 268px; }
.stats-chart-wide { height: 300px; }
// A 300px sticky name can obscure all metrics on a narrow phone.
:deep(.dept-name-column.el-table-fixed-column--left) { position: static; }
}
}
:root.dark[data-admin-ui='v2'] .conversion-stats-page {
--leader-ink: #ffca77;
--unbound-ink: #ffadb0;
}
</style>
@@ -0,0 +1,178 @@
// Only the Art shell uses this layout. The chart palette supplies concrete, contrast-checked
// colors for the chosen accent; comparison colors always carry their original business meaning.
html[data-admin-ui='v2'] .performance-dashboard {
--dash-accent: var(--zyt-primary);
--dash-accent-soft: var(--zyt-accent-soft);
--dash-border: var(--zyt-card-border);
--dash-surface: var(--zyt-surface);
--dash-surface-muted: var(--zyt-surface-subtle);
--dash-text: var(--zyt-ink);
--dash-text-muted: var(--dash-detail, var(--zyt-text));
--dash-secondary-mark: var(--art-gray-600);
--dash-positive: #15704b;
--dash-negative: #b33643;
--dash-pad: clamp(14px, 2cqi, 20px);
--dash-radius: calc(var(--zyt-radius) + 4px);
container: performance-home / inline-size;
min-width: 0;
padding: 0;
background: var(--zyt-canvas);
.dashboard-header {
padding: 4px 0 0;
margin-bottom: 20px;
border: 0;
border-radius: 0;
background: transparent;
}
.dashboard-heading__icon {
color: var(--dash-accent-text);
background: var(--dash-accent-soft);
}
.dashboard-title-row h1 { font-size: 24px; font-weight: 600; }
.dashboard-heading p { color: var(--zyt-text); font-size: 13px; }
.scope-badge, .panel-meta {
border: 1px solid var(--dash-border);
border-radius: 6px;
color: var(--zyt-text);
background: var(--dash-surface);
font-size: 12px;
font-weight: 500;
}
.updated-at, .metric-hint, .dashboard-notes { color: var(--dash-text-muted); font-size: 12px; }
.updated-at { display: block; }
.performance-strip, .operating-grid, .dashboard-grid { margin-bottom: 16px; }
.section-heading, .panel-header h2 {
margin: 0;
color: var(--dash-text);
font-size: 17px;
font-weight: 600;
line-height: 1.4;
}
.section-heading { grid-column: 1 / -1; }
.performance-strip {
grid-template-columns: repeat(var(--performance-cols, 5), minmax(0, 1fr));
&:has(> article:nth-of-type(4):last-child) { --performance-cols: 4; }
}
.dashboard-panel, .metric-card, .operating-grid {
border: 1px solid var(--dash-border);
border-radius: var(--dash-radius);
background: var(--dash-surface);
}
.metric-card, .dashboard-panel { padding: var(--dash-pad); }
.metric-label, .metric-label-row { color: var(--zyt-text); font-size: 13px; }
.metric-value, .ranking-value, .target-copy strong {
font-family: var(--el-font-family);
font-variant-numeric: tabular-nums;
}
.metric-value {
overflow: visible;
white-space: normal;
overflow-wrap: anywhere;
font-size: clamp(21px, 2.5cqi, 26px);
font-weight: 600;
line-height: 1.2;
}
.metric-card--primary { box-shadow: inset 3px 0 var(--dash-accent-mark); }
.metric-card--primary .metric-label { color: var(--dash-accent-text); font-weight: 600; }
.metric-card--clock { background: var(--dash-surface-muted); }
.metric-value--time { color: var(--zyt-text); font-size: 19px; font-weight: 500; }
.metric-foot {
color: var(--dash-text-muted);
font-size: 12px;
&.is-positive { color: var(--dash-positive); }
&.is-negative { color: var(--dash-negative); }
&.is-flat { color: var(--dash-text-muted); }
}
.metric-help, .metric-value--pair span { color: var(--dash-text-muted); }
.metric-card--clock .metric-foot { color: var(--zyt-text); }
// The seven daily figures belong to one readout, not seven competing panels.
.operating-grid {
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 0 20px;
padding: var(--dash-pad);
padding-bottom: 4px;
.section-heading { margin-bottom: 12px; }
.metric-card {
grid-column: span 3;
padding: 12px 0;
border: 0;
border-top: 1px solid var(--dash-border);
border-radius: 0;
background: transparent;
}
.metric-card:nth-last-child(-n + 3) { grid-column: span 4; }
.metric-value { margin-top: 4px; font-size: 23px; }
.metric-value--pair { font-size: 20px; }
.metric-hint { margin-top: 4px; white-space: normal; }
}
.dashboard-grid { gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-grid--bottom { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.panel-header { flex-wrap: wrap; align-items: flex-start; }
.panel-header-actions { align-items: center; flex-direction: row; flex-wrap: wrap; }
.ranking-dept-select { width: min(155px, 100%); }
.ranking-row { background: transparent; border-radius: 8px; }
.ranking-row.is-self { background: var(--dash-accent-soft); box-shadow: none; }
.ranking-index, .ranking-index.is-top {
color: var(--zyt-text);
background: var(--dash-surface-muted);
font-variant-numeric: tabular-nums;
}
.ranking-index.is-top { color: var(--dash-text); box-shadow: inset 0 0 0 1px var(--dash-border); }
.ranking-index.is-self, .ranking-self-tag { color: var(--dash-accent-text); background: var(--dash-surface); }
.ranking-copy { flex-wrap: wrap; gap: 2px 8px; }
.ranking-copy strong { white-space: normal; overflow-wrap: anywhere; font-size: 13px; }
.ranking-copy span { display: inline; color: var(--dash-text-muted); font-size: 12px; }
.ranking-meter, :deep(.el-progress-bar__outer) { background: var(--art-gray-300); }
.ranking-meter span { background: var(--dash-secondary-mark); }
.ranking-row.is-self .ranking-meter span { background: var(--dash-accent-mark); }
.target-block { background: var(--dash-surface-muted); }
.target-copy strong { font-weight: 600; }
.target-empty-note { color: var(--zyt-text); }
.trend-panel :deep(.el-segmented) {
--el-segmented-item-selected-bg-color: var(--dash-accent-soft);
--el-segmented-item-selected-color: var(--dash-text);
}
// Size against the actual content column, including when both sidebar levels are open.
@container performance-home (max-width: 920px) {
.dashboard-grid--bottom { grid-template-columns: 1fr; }
.performance-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container performance-home (max-width: 720px) {
.dashboard-grid { grid-template-columns: 1fr; }
.performance-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.operating-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
.metric-card, .metric-card:nth-last-child(-n + 3) { grid-column: auto; }
}
.dashboard-header { flex-wrap: wrap; gap: 10px; }
}
@container performance-home (max-width: 500px) {
.performance-strip, .dashboard-grid { gap: 10px; }
.dashboard-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
.dashboard-actions :deep(.el-button) { width: auto; }
.metric-card--clock:last-child:nth-of-type(odd) {
grid-column: 1 / -1;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 10px;
.metric-value, .metric-foot { margin: 0; }
.metric-foot { margin-left: auto; }
}
.operating-grid { column-gap: 12px; }
.trend-chart { height: 240px; }
}
@container performance-home (max-width: 330px) {
.performance-strip, .operating-grid { grid-template-columns: 1fr; }
}
}
html.dark[data-admin-ui='v2'] .performance-dashboard {
--dash-positive: #72d6a6;
--dash-negative: #ff96a0;
}
@@ -1,5 +1,5 @@
<template>
<div class="performance-dashboard" v-loading="loading" element-loading-text="正在汇总权限范围内的数据">
<div class="performance-dashboard" :style="dashboardColors" v-loading="loading" element-loading-text="正在汇总权限范围内的数据">
<header class="dashboard-header">
<div class="dashboard-heading">
<div class="dashboard-heading__icon">
@@ -50,6 +50,7 @@
<template v-else-if="loaded">
<section class="performance-strip" aria-label="业绩概览">
<h2 v-if="chartPalette" class="section-heading">业绩概览</h2>
<article class="metric-card metric-card--primary">
<div class="metric-label">本月实时业绩</div>
<div class="metric-value metric-value--money">
@@ -119,6 +120,7 @@
</section>
<section class="operating-grid" aria-label="今日运营指标">
<h2 v-if="chartPalette" class="section-heading">今日运营指标</h2>
<article v-for="metric in todayMetrics" :key="metric.key" class="metric-card metric-card--compact">
<div class="metric-label">{{ metric.label }}</div>
<div class="metric-value" :class="{ 'metric-value--pair': metric.key === 'orders' }">
@@ -281,7 +283,7 @@
:percentage="progressValue(dashboard.target.completion_rate)"
:show-text="false"
:stroke-width="12"
color="#0f8f83"
:color="chartPalette?.accentInk ?? '#0f8f83'"
/>
</div>
@@ -299,7 +301,7 @@
:percentage="progressValue(dashboard.target.personal_contribution_rate)"
:show-text="false"
:stroke-width="12"
color="#738196"
:color="chartPalette ? 'var(--dash-secondary-mark)' : '#738196'"
/>
</div>
@@ -337,6 +339,7 @@ import {
import vCharts from 'vue-echarts'
import { performanceDashboardOverview } from '@/api/stats'
import { useStatsChartPalette } from '@/hooks/useStatsChartPalette'
type TrendKey = 'registrations' | 'appointments' | 'leads' | 'orders'
@@ -589,6 +592,13 @@ const performanceRankingMax = computed(() => Math.max(
...dashboard.rankings.performance.items.map((item) => Number(item.amount || 0))
))
const chartPalette = useStatsChartPalette()
const dashboardColors = computed(() => chartPalette.value ? {
'--dash-accent-mark': chartPalette.value.accentInk,
'--dash-accent-text': chartPalette.value.accentText,
'--dash-detail': chartPalette.value.muted,
} : undefined)
const trendChartOption = computed(() => {
const config: Record<TrendKey, { label: string; data: number[] }> = {
registrations: { label: '挂号', data: dashboard.trend.registrations },
@@ -597,26 +607,35 @@ const trendChartOption = computed(() => {
orders: { label: '诊单', data: dashboard.trend.orders },
}
const current = config[activeTrend.value]
const skin = chartPalette.value
const line = skin?.accentInk ?? '#0f8f83'
return {
animationDuration: 320,
tooltip: {
trigger: 'axis',
valueFormatter: (value: number) => `${formatNumber(value)} 条`,
...(skin && {
backgroundColor: skin.surface,
borderColor: skin.border,
textStyle: { color: skin.ink },
axisPointer: { lineStyle: { color: skin.muted, type: 'dashed' } },
confine: true,
}),
},
grid: { left: 42, right: 18, top: 24, bottom: 30, containLabel: true },
xAxis: {
type: 'category',
boundaryGap: false,
data: dashboard.trend.dates,
axisLine: { lineStyle: { color: '#d9e0e7' } },
axisLabel: { color: '#7d8996' },
axisLine: { lineStyle: { color: skin?.border ?? '#d9e0e7' } },
axisLabel: { color: skin?.muted ?? '#7d8996' },
},
yAxis: {
type: 'value',
minInterval: 1,
splitLine: { lineStyle: { color: '#edf1f4' } },
axisLabel: { color: '#7d8996' },
splitLine: { lineStyle: { color: skin?.grid ?? '#edf1f4' } },
axisLabel: { color: skin?.muted ?? '#7d8996' },
},
series: [
{
@@ -626,9 +645,10 @@ const trendChartOption = computed(() => {
showSymbol: true,
symbolSize: 7,
data: current.data,
lineStyle: { color: '#0f8f83', width: 3 },
itemStyle: { color: '#0f8f83', borderColor: '#ffffff', borderWidth: 2 },
lineStyle: { color: line, width: 3 },
itemStyle: { color: line, borderColor: skin?.surface ?? '#ffffff', borderWidth: 2 },
areaStyle: {
...(skin && { opacity: 0.16 }),
color: {
type: 'linear',
x: 0,
@@ -636,8 +656,8 @@ const trendChartOption = computed(() => {
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(15, 143, 131, 0.20)' },
{ offset: 1, color: 'rgba(15, 143, 131, 0.01)' },
{ offset: 0, color: skin ? line : 'rgba(15, 143, 131, 0.20)' },
{ offset: 1, color: skin ? skin.surface : 'rgba(15, 143, 131, 0.01)' },
],
},
},
@@ -1281,3 +1301,5 @@ onBeforeUnmount(() => {
}
}
</style>
<style scoped lang="scss" src="./dashboard-v2.scss"></style>
+148
View File
@@ -0,0 +1,148 @@
const assert = require('node:assert/strict')
const path = require('node:path')
const test = require('node:test')
const { buildSync } = require('esbuild')
const { createPinia } = require('pinia')
const vue = require('vue')
const admin = path.resolve(__dirname, '..')
function compile(file) {
return buildSync({
absWorkingDir: admin, entryPoints: [file], alias: { '@': path.join(admin, 'src') },
bundle: true, packages: 'external', platform: 'node', format: 'cjs', write: false
}).outputFiles[0].text
}
const hookSource = compile('src/hooks/useStatsChartPalette.ts')
const settingsSource = compile('src/stores/modules/setting.ts')
function load(source, globals = {}, imports = {}) {
const mod = { exports: {} }
new Function('module', 'exports', 'require', ...Object.keys(globals), source)(
mod, mod.exports, id => imports[id] || require(id), ...Object.values(globals))
return mod.exports
}
// Independent WCAG relative-luminance check; don't use the hook's own contrast helper.
function contrast(a, b) {
function luminance(color) {
const channels = color.match(/\w\w/g).map(x => parseInt(x, 16) / 255)
return channels.reduce((sum, c, i) => sum + [0.2126, 0.7152, 0.0722][i] *
(c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4), 0)
}
const l = [luminance(a), luminance(b)].sort((x, y) => y - x)
return (l[0] + 0.05) / (l[1] + 0.05)
}
test('custom accents remain literal where legible; marks, text and muted labels meet contrast on both surfaces', () => {
const { statsChartPalette } = load(hookSource)
for (const dark of [false, true]) {
for (const accent of ['#5d87ff', '#6b34c2', '#ffffef', '#030303', '#27eb77']) {
const tokens = { '--el-color-primary': accent, '--zyt-muted': dark ? '#111' : '#eee' }
const p = statsChartPalette(key => tokens[key] || '', dark)
assert.equal(p.accent, accent)
for (const key of ['accentInk', 'accentText', 'muted', 'surface', 'ink', 'soft', 'grid', 'border']) {
assert.match(p[key], /^#[a-f\d]{6}$/i, key)
}
for (const [key, min] of [['accentInk', 3], ['accentText', 4.5], ['muted', 4.5]]) {
assert.ok(contrast(p[key], p.surface) >= min, `${accent} ${key} on ${p.surface}`)
if (key !== 'muted' && contrast(accent, p.surface) >= min) assert.equal(p[key], accent)
}
}
}
})
// Run the production Pinia stylesheet writer against a small DOM. Deliver only mutations
// actually subscribed to, in batches: assigning style.textContent is NOT an html attribute change.
function harness() {
const listeners = new Set()
class MutationObserver {
constructor(callback) { this.callback = callback; this.targets = new Map(); this.pending = [] }
observe(target, options) { this.targets.set(target, options); listeners.add(this) }
disconnect() { this.targets.clear(); this.pending = []; listeners.delete(this) }
}
function emit(target, type, attributeName) {
for (const listener of listeners) {
const opts = listener.targets.get(target)
if (opts?.[type] && (!attributeName || !opts.attributeFilter || opts.attributeFilter.includes(attributeName))) {
listener.pending.push({ target, type, attributeName })
}
}
}
function flush() {
for (const listener of listeners) {
if (listener.pending.length) listener.callback(listener.pending.splice(0))
}
}
let dark = false
const sheets = new Map()
const root = { dataset: { adminUi: 'v2' }, classList: { contains: key => key === 'dark' && dark } }
const head = { appendChild(sheet) { sheets.set(sheet.id, sheet); emit(head, 'childList') } }
const document = { documentElement: root, head, getElementById: id => sheets.get(id) || null,
createElement(tag) {
assert.equal(tag, 'style')
let css = ''
return { id: '', get textContent() { return css },
set textContent(value) { css = value; emit(this, 'childList') } }
}
}
const getComputedStyle = () => ({
getPropertyValue(key) {
const css = sheets.get('art-theme-vars')?.textContent || ''
return css.match(new RegExp('[{;]' + key + ':([^;}]+)'))?.[1] || ''
}
})
const events = {}
const lifecycles = { ...vue }
for (const name of ['onActivated', 'onDeactivated', 'onMounted', 'onScopeDispose']) {
lifecycles[name] = callback => { events[name] = callback }
}
const { useStatsChartPalette } = load(hookSource, { document, getComputedStyle, MutationObserver }, { vue: lifecycles })
const settings = load(settingsSource, { document }).useSettingStore(createPinia())
const palette = useStatsChartPalette()
return { events, palette, flush, sheets, listeners,
pick(hex) { settings.setSetting({ key: 'theme', value: hex }); settings.setTheme(dark); flush() },
mode(value) { root.dataset.adminUi = value; emit(root, 'attributes', 'data-admin-ui'); flush() },
dark(value) { dark = value; emit(root, 'attributes', 'class'); settings.setTheme(dark); flush() }
}
}
test('an open page follows initial stylesheet insertion and subsequent picker writes to the same style node', () => {
const h = harness()
h.events.onMounted()
h.events.onActivated()
assert.equal(h.listeners.size, 1)
h.pick('#8833aa')
const initialSheet = h.sheets.get('art-theme-vars')
assert.ok(initialSheet)
assert.equal(h.palette.value.accent, '#8833aa')
h.pick('#bb3311')
assert.equal(h.sheets.get('art-theme-vars'), initialSheet)
assert.equal(h.palette.value.accentInk, '#bb3311')
const light = h.palette.value
h.dark(true)
assert.equal(h.palette.value.dark, true)
assert.notEqual(h.palette.value.surface, light.surface)
assert.notEqual(h.palette.value.grid, light.grid)
assert.ok(contrast(h.palette.value.grid, h.palette.value.surface) < 2)
h.events.onScopeDispose()
assert.equal(h.listeners.size, 0)
})
test('cached pages disconnect, catch up on reactivation, and relinquish the V2 palette in classic mode', () => {
const h = harness()
h.pick('#4411aa') // The sheet may predate the component mount.
h.events.onMounted()
assert.equal(h.palette.value.accent, '#4411aa')
h.events.onDeactivated()
assert.equal(h.listeners.size, 0)
h.pick('#224455')
assert.equal(h.palette.value.accent, '#4411aa')
h.events.onActivated()
assert.equal(h.palette.value.accent, '#224455')
h.mode('legacy')
assert.equal(h.palette.value, null)
h.mode('v2')
assert.equal(h.palette.value.accent, '#224455')
h.events.onScopeDispose()
h.pick('#331177')
assert.equal(h.palette.value.accent, '#224455')
assert.equal(h.listeners.size, 0)
})