From 8f5051be6741f48c6e403d59f5860b3b84494367 Mon Sep 17 00:00:00 2001 From: Mus Date: Sat, 5 Dec 2026 20:39:20 +0800 Subject: [PATCH 01/22] =?UTF-8?q?feat(charts):=20=E6=A8=A1=E5=9E=8B/?= =?UTF-8?q?=E5=88=86=E7=BB=84=E7=8E=AF=E5=BD=A2=E5=9B=BE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=20ECharts=EF=BC=8Ctooltip=20=E6=94=AF=E6=8C=81=E7=82=B9?= =?UTF-8?q?=E5=87=BB/=E8=A7=A6=E6=91=B8=E4=B8=94=E4=B8=8D=E8=A3=81?= =?UTF-8?q?=E5=88=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bun.lock | 12 +- docs/DESIGN-SYSTEM.md | 3 +- package.json | 2 + .../charts/GroupDistributionChart.vue | 101 +++++--- .../charts/ModelDistributionChart.vue | 242 ++++++++---------- .../components/charts/distribution-layout.css | 19 ++ 6 files changed, 209 insertions(+), 170 deletions(-) diff --git a/bun.lock b/bun.lock index f4e4f8d..b20f7ea 100644 --- a/bun.lock +++ b/bun.lock @@ -19,6 +19,7 @@ "chart.js": "^4.6.2", "dompurify": "^3.5.0", "driver.js": "^1.14.0", + "echarts": "^6.1.0", "file-saver": "^2.0.5", "marked": "^17.0.1", "pinia": "^2.1.7", @@ -28,6 +29,7 @@ "vue": "^3.5.46", "vue-chartjs": "^5.3.7", "vue-draggable-plus": "^0.6.1", + "vue-echarts": "^8.3.2", "vue-i18n": "^11.4.24", "vue-router": "^4.2.5", "xlsx": "npm:@e965/xlsx@0.20.3", @@ -433,6 +435,8 @@ "dunder-proto": ["dunder-proto@1.0.1", "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz", { "dependencies": { "call-bind-apply-helpers": "1.0.2", "es-errors": "1.3.0", "gopd": "1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="], + "echarts": ["echarts@6.1.0", "https://registry.npmmirror.com/echarts/-/echarts-6.1.0.tgz", { "dependencies": { "tslib": "2.3.0", "zrender": "6.1.0" } }, "sha512-q0yaFPggC9FUdsWH4blavRWFmxdrIodbkoKNAjJudAI6CA9gNPxHtV2RcZNEepZVlk4yvBYkOkbk6HIVpIyHZA=="], + "electron-to-chromium": ["electron-to-chromium@1.5.495", "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.5.495.tgz", {}, "sha512-dZcmtNbDI5oeT9uP9Z+D7h/H5C1mvBewDTLgZgo9WgyPmqOXSt2cmoCK99evPygUOn9lyXZ4w0Eb8APrkBjqBA=="], "emoji-regex": ["emoji-regex@8.0.0", "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], @@ -757,7 +761,7 @@ "ts-interface-checker": ["ts-interface-checker@0.1.13", "https://registry.npmmirror.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", {}, "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="], - "tslib": ["tslib@2.9.1", "https://registry.npmmirror.com/tslib/-/tslib-2.9.1.tgz", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], + "tslib": ["tslib@2.3.0", "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", {}, "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="], "type-check": ["type-check@0.4.0", "https://registry.npmmirror.com/type-check/-/type-check-0.4.0.tgz", { "dependencies": { "prelude-ls": "1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="], @@ -787,6 +791,8 @@ "vue-draggable-plus": ["vue-draggable-plus@0.6.1", "https://registry.npmmirror.com/vue-draggable-plus/-/vue-draggable-plus-0.6.1.tgz", { "peerDependencies": { "@types/sortablejs": "1.15.9" } }, "sha512-FbtQ/fuoixiOfTZzG3yoPl4JAo9HJXRHmBQZFB9x2NYCh6pq0TomHf7g5MUmpaDYv+LU2n6BPq2YN9sBO+FbIg=="], + "vue-echarts": ["vue-echarts@8.3.2", "https://registry.npmmirror.com/vue-echarts/-/vue-echarts-8.3.2.tgz", { "peerDependencies": { "echarts": "^6.0.0", "vue": "^3.3.0" } }, "sha512-FbJD49OZZZv1I8aclHQ+gcQxU+Y9nNWQMuod1sewE7/YjGQUJAaeVcf6WrSfQDBRPke+WoVsUtdRFIqPOsRrnw=="], + "vue-eslint-parser": ["vue-eslint-parser@9.4.3", "https://registry.npmmirror.com/vue-eslint-parser/-/vue-eslint-parser-9.4.3.tgz", { "dependencies": { "debug": "4.4.3", "eslint-scope": "7.2.2", "eslint-visitor-keys": "3.4.3", "espree": "9.6.1", "esquery": "1.7.0", "lodash": "4.18.1", "semver": "7.7.3" }, "peerDependencies": { "eslint": "8.57.1" } }, "sha512-2rYRLWlIpaiN8xbPiDyXZXRgLGOtWxERV7ND5fFAv5qo1D2N9Fu9MNajBNc6o13lZ+24DAWCkQCvj4klgmcITg=="], "vue-i18n": ["vue-i18n@11.4.24", "https://registry.npmmirror.com/vue-i18n/-/vue-i18n-11.4.24.tgz", { "dependencies": { "@intlify/core-base": "11.4.24", "@intlify/devtools-types": "11.4.24", "@intlify/shared": "11.4.24", "@vue/devtools-api": "6.6.4" }, "peerDependencies": { "vue": "3.5.46" } }, "sha512-tJOAoZawEz2xFdDyHD2prvIjf1VbsTJUUeAe0VY9wiMzZV/SYhq3uz92achoGPGZk9eaBykyAI2NcvUcsX/ESw=="], @@ -817,6 +823,8 @@ "yocto-queue": ["yocto-queue@0.1.0", "https://registry.npmmirror.com/yocto-queue/-/yocto-queue-0.1.0.tgz", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="], + "zrender": ["zrender@6.1.0", "https://registry.npmmirror.com/zrender/-/zrender-6.1.0.tgz", { "dependencies": { "tslib": "2.3.0" } }, "sha512-oEGMDB6pOP2S6OwRR4PdVv610zrjnA3Bh+JnSG12fYJlBKjtNAoEb5fSUoCOOINlH96I2fU38/A2UpRKs67xYQ=="], + "@babel/types/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "https://registry.npmmirror.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="], "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.5", "https://registry.npmmirror.com/minimatch/-/minimatch-9.0.5.tgz", { "dependencies": { "brace-expansion": "2.0.2" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="], @@ -833,6 +841,8 @@ "anymatch/picomatch": ["picomatch@2.3.1", "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], + "aria-hidden/tslib": ["tslib@2.9.1", "https://registry.npmmirror.com/tslib/-/tslib-2.9.1.tgz", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], + "chokidar/glob-parent": ["glob-parent@5.1.2", "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz", { "dependencies": { "is-glob": "4.0.3" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], "fast-glob/glob-parent": ["glob-parent@5.1.2", "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz", { "dependencies": { "is-glob": "4.0.3" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], diff --git a/docs/DESIGN-SYSTEM.md b/docs/DESIGN-SYSTEM.md index 04d23de..464d38f 100644 --- a/docs/DESIGN-SYSTEM.md +++ b/docs/DESIGN-SYSTEM.md @@ -59,7 +59,8 @@ ## 图表 -- 仪表盘与使用记录复用 `TokenUsageTrend.vue` 与 `ModelDistributionChart.vue`。 +- 仪表盘与使用记录复用 `TokenUsageTrend.vue`、`ModelDistributionChart.vue`、`GroupDistributionChart.vue`。 +- 模型/分组环形图使用 ECharts(`vue-echarts`),tooltip 使用 HTML 并挂到 body,避免 canvas 边界裁切,鼠标悬停和手机点击都能完整展示;`TokenUsageTrend` 仍使用 Chart.js。 - 缓存读取、缓存命中率使用 `--st-chart-cache-read` / `--st-chart-cache-hit-rate` 语义色,不按文字灰度推导。 - 图表颜色同时适配亮暗主题和三套强调色;切换配色时同一帧更新。 diff --git a/package.json b/package.json index 0f02114..599b059 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "chart.js": "^4.6.2", "dompurify": "^3.5.0", "driver.js": "^1.14.0", + "echarts": "^6.1.0", "file-saver": "^2.0.5", "marked": "^17.0.1", "pinia": "^2.1.7", @@ -65,6 +66,7 @@ "vue": "^3.5.46", "vue-chartjs": "^5.3.7", "vue-draggable-plus": "^0.6.1", + "vue-echarts": "^8.3.2", "vue-i18n": "^11.4.24", "vue-router": "^4.2.5", "xlsx": "npm:@e965/xlsx@0.20.3" diff --git a/src/theme/components/charts/GroupDistributionChart.vue b/src/theme/components/charts/GroupDistributionChart.vue index 3ae0b7a..cd59487 100644 --- a/src/theme/components/charts/GroupDistributionChart.vue +++ b/src/theme/components/charts/GroupDistributionChart.vue @@ -14,7 +14,13 @@
- +
/g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') +} + const themeTick = ref(0) let themeObserver: MutationObserver | null = null onMounted(() => { @@ -242,35 +260,56 @@ const chartData = computed(() => { } }) -const doughnutOptions = computed(() => ({ - responsive: true, - maintainAspectRatio: false, - plugins: { - legend: { - display: false - }, +function tooltipHtml(title: string, color: string, value: number, total: number, asCost: boolean): string { + const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' + const formatted = asCost ? `$${formatCost(value)}` : formatTokens(value) + return [ + '
', + `

${escapeHtml(title)}

`, + '
', + ``, + `${escapeHtml(formatted)} (${percentage}%)`, + '
', + '
', + ].join('') +} + +const doughnutOption = computed(() => { + const data = chartData.value + if (!data) return {} + const labels = data.labels + const values = data.datasets[0].data as number[] + const colors = data.datasets[0].backgroundColor as string[] + const total = values.reduce((sum, value) => sum + value, 0) + const asCost = props.metric === 'actual_cost' + return { + animation: !themeUpdating.value, + color: colors, tooltip: { - backgroundColor: chartTokens.value.ink, - titleColor: chartTokens.value.bg, - bodyColor: chartTokens.value.bg, - borderColor: chartTokens.value.border, - borderWidth: 1, - padding: 10, - cornerRadius: 8, - callbacks: { - label: (context: any) => { - const value = context.raw as number - const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0) - const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' - const formattedValue = props.metric === 'actual_cost' - ? `$${formatCost(value)}` - : formatTokens(value) - return `${context.label}: ${formattedValue} (${percentage}%)` - } - } - } + trigger: 'item', + triggerOn: 'mousemove|click', + appendToBody: true, + className: 'chart-echarts-tooltip', + backgroundColor: 'transparent', + borderWidth: 0, + padding: 0, + extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, asCost), + }, + series: [ + { + type: 'pie', + radius: ['54%', '82%'], + center: ['50%', '50%'], + avoidLabelOverlap: false, + label: { show: false }, + labelLine: { show: false }, + emphasis: { scale: false }, + data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), + }, + ], } -})) +}) const formatTokens = (value: number): string => { if (value >= 1_000_000_000) { diff --git a/src/theme/components/charts/ModelDistributionChart.vue b/src/theme/components/charts/ModelDistributionChart.vue index ce1867b..db2d75d 100644 --- a/src/theme/components/charts/ModelDistributionChart.vue +++ b/src/theme/components/charts/ModelDistributionChart.vue @@ -29,10 +29,10 @@ class="distribution-layout" >
- @@ -123,7 +123,13 @@
- +
@@ -179,19 +185,6 @@ {{ t('admin.dashboard.noDataAvailable') }} - - @@ -201,56 +194,26 @@ import { useDistributionTableLimit } from './useDistributionTableLimit' import { computed, onMounted, onUnmounted, ref } from 'vue' import { useI18n } from 'vue-i18n' import { themeUpdating } from '@/utils/theme-transition' -import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js' -import { Doughnut } from 'vue-chartjs' +import { use as useECharts } from 'echarts/core' +import { PieChart } from 'echarts/charts' +import { TooltipComponent } from 'echarts/components' +import { CanvasRenderer } from 'echarts/renderers' +import VChart from 'vue-echarts' import UserBreakdownSubTable from './UserBreakdownSubTable.vue' import type { ModelStat, UserSpendingRankingItem, UserBreakdownItem } from '@/types' import { getUserBreakdown } from '@/api/admin/dashboard' -ChartJS.register(ArcElement, Tooltip, Legend) - -// Chart.js 在配置 external 后仍会绘制 canvas 原生 tooltip, -// 导致 hover 时出现「DOM tooltip + canvas tooltip」两份。 -// 这里用 beforeTooltipDraw 钩子取消原生绘制,只保留 DOM 浮层。 -const externalTooltipOnly = { - id: 'external-tooltip-only', - beforeTooltipDraw(chart: any) { - return chart?.options?.plugins?.tooltip?.external ? false : undefined - }, -} -ChartJS.register(externalTooltipOnly) +useECharts([PieChart, TooltipComponent, CanvasRenderer]) const { t } = useI18n() -interface ChartTooltipState { - title: string - lines: Array<{ text: string; color: string }> -} -const tooltipState = ref(null) -const tooltipStyle = ref>({}) - -function externalTooltipHandler(context: any): void { - const { chart, tooltip } = context - if (!tooltip || tooltip.opacity === 0) { - tooltipState.value = null - return - } - const lines: ChartTooltipState['lines'] = [] - tooltip.body?.forEach((body: { lines?: string[] }, bodyIndex: number) => { - const color = tooltip.labelColors?.[bodyIndex]?.backgroundColor - for (const text of body.lines ?? []) { - lines.push({ text, color: typeof color === 'string' ? color : 'var(--st-brand)' }) - } - }) - const canvasRect = chart.canvas.getBoundingClientRect() - const halfWidth = 130 - const x = canvasRect.left + tooltip.caretX - const y = canvasRect.top + tooltip.caretY - tooltipState.value = { title: tooltip.title?.[0] ?? '', lines } - tooltipStyle.value = { - left: `${Math.round(Math.min(Math.max(x, halfWidth + 8), window.innerWidth - halfWidth - 8))}px`, - top: `${Math.round(Math.max(y, 72))}px`, - } +function escapeHtml(value: unknown): string { + return String(value ?? '') + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') } const themeTick = ref(0) @@ -478,64 +441,92 @@ const rankingDisplayItems = computed(() => { : [...props.rankingItems] }) -const doughnutOptions = computed(() => ({ - responsive: true, - maintainAspectRatio: false, - plugins: { - legend: { - display: false - }, +function tooltipHtml(title: string, color: string, value: number, total: number, asCost: boolean): string { + const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' + const formatted = asCost ? `$${formatCost(value)}` : formatTokens(value) + return [ + '
', + `

${escapeHtml(title)}

`, + '
', + ``, + `${escapeHtml(formatted)} (${percentage}%)`, + '
', + '
', + ].join('') +} + +const doughnutOption = computed(() => { + const data = chartData.value + if (!data) return {} + const labels = data.labels + const values = data.datasets[0].data as number[] + const colors = data.datasets[0].backgroundColor as string[] + const total = values.reduce((sum, value) => sum + value, 0) + const asCost = props.metric === 'actual_cost' + return { + animation: !themeUpdating.value, + color: colors, tooltip: { - external: externalTooltipHandler, - backgroundColor: chartTokens.value.ink, - titleColor: chartTokens.value.bg, - bodyColor: chartTokens.value.bg, - borderColor: chartTokens.value.border, - borderWidth: 1, - padding: 10, - cornerRadius: 8, - callbacks: { - label: (context: any) => { - const value = context.raw as number - const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0) - const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' - const formattedValue = props.metric === 'actual_cost' - ? `$${formatCost(value)}` - : formatTokens(value) - return `${formattedValue} (${percentage}%)` - } - } - } + trigger: 'item', + triggerOn: 'mousemove|click', + appendToBody: true, + className: 'chart-echarts-tooltip', + backgroundColor: 'transparent', + borderWidth: 0, + padding: 0, + extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, asCost), + }, + series: [ + { + type: 'pie', + radius: ['54%', '82%'], + center: ['50%', '50%'], + avoidLabelOverlap: false, + label: { show: false }, + labelLine: { show: false }, + emphasis: { scale: false }, + data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), + }, + ], } -})) +}) -const rankingDoughnutOptions = computed(() => ({ - responsive: true, - maintainAspectRatio: false, - plugins: { - legend: { - display: false - }, +const rankingDoughnutOption = computed(() => { + const data = rankingChartData.value + if (!data) return {} + const labels = data.labels + const values = data.datasets[0].data as number[] + const colors = data.datasets[0].backgroundColor as string[] + const total = values.reduce((sum, value) => sum + value, 0) + return { + animation: !themeUpdating.value, + color: colors, tooltip: { - external: externalTooltipHandler, - backgroundColor: chartTokens.value.ink, - titleColor: chartTokens.value.bg, - bodyColor: chartTokens.value.bg, - borderColor: chartTokens.value.border, - borderWidth: 1, - padding: 10, - cornerRadius: 8, - callbacks: { - label: (context: any) => { - const value = context.raw as number - const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0) - const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' - return `$${formatCost(value)} (${percentage}%)` - } - } - } + trigger: 'item', + triggerOn: 'mousemove|click', + appendToBody: true, + className: 'chart-echarts-tooltip', + backgroundColor: 'transparent', + borderWidth: 0, + padding: 0, + extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, true), + }, + series: [ + { + type: 'pie', + radius: ['54%', '82%'], + center: ['50%', '50%'], + avoidLabelOverlap: false, + label: { show: false }, + labelLine: { show: false }, + emphasis: { scale: false }, + data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), + }, + ], } -})) +}) const formatTokens = (value: number): string => { if (value >= 1_000_000_000) { @@ -585,29 +576,6 @@ const formatCost = (value: number | null | undefined): string => { diff --git a/src/theme/styles/simple-theme.css b/src/theme/styles/simple-theme.css index 3a353fb..79cb534 100644 --- a/src/theme/styles/simple-theme.css +++ b/src/theme/styles/simple-theme.css @@ -577,6 +577,26 @@ body:has(.st-root) { } .ch-filter-popover:focus { outline: none; } +/* ---- ECharts 图表 tooltip:挂到 body,避免 canvas/面板裁切 ---- */ +.chart-echarts-tip { + box-sizing: border-box; + max-width: min(280px, calc(100vw - 40px)); + padding: 9px 11px; + border: 1px solid var(--st-line-2); + border-radius: 8px; + background: var(--st-bg); + color: var(--st-ink); + box-shadow: var(--st-shadow-3); + font-size: 12px; + line-height: 1.45; + white-space: normal; + overflow-wrap: anywhere; +} +.chart-echarts-tip__title { margin: 0 0 3px; font-size: 12px; font-weight: 600; } +.chart-echarts-tip__row { display: flex; align-items: flex-start; gap: 6px; } +.chart-echarts-tip__dot { flex: none; width: 10px; height: 10px; margin-top: 3px; border-radius: 2px; } +.chart-echarts-tip__footer { margin-top: 5px; padding-top: 5px; border-top: 1px solid color-mix(in srgb, currentColor 18%, transparent); font-size: 11px; opacity: 0.8; } + /* ---- 统一 Popover / DropdownMenu 进离场动效 ---- Reka 的浮层内容都挂在 [data-reka-popper-content-wrapper] 下; 在这里统一加 fade + scale,避免各组件自己写一套、有的有动效有的没有。 */ From 30975e6156373bbb7e6c8f3c243abd45986b5d8d Mon Sep 17 00:00:00 2001 From: Mus Date: Sat, 5 Dec 2026 22:32:16 +0800 Subject: [PATCH 03/22] =?UTF-8?q?fix(charts):=20=E5=9B=BE=E8=A1=A8=20toolt?= =?UTF-8?q?ip=20=E6=8C=87=E5=90=91=E7=AE=AD=E5=A4=B4=E3=80=81=E6=8A=98?= =?UTF-8?q?=E7=BA=BF=E5=B7=A6=E5=AF=B9=E9=BD=90=E4=B8=8E=E5=9B=BE=E4=BE=8B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/DESIGN-SYSTEM.md | 2 +- .../charts/GroupDistributionChart.vue | 18 +- .../charts/ModelDistributionChart.vue | 32 ++-- .../components/charts/TokenUsageTrend.vue | 159 ++++++++++++------ .../components/charts/distribution-layout.css | 2 +- .../components/monitor/MonitorTrendChart.vue | 3 +- src/theme/styles/simple-theme.css | 20 ++- 7 files changed, 161 insertions(+), 75 deletions(-) diff --git a/docs/DESIGN-SYSTEM.md b/docs/DESIGN-SYSTEM.md index 7f43cd1..2a58c30 100644 --- a/docs/DESIGN-SYSTEM.md +++ b/docs/DESIGN-SYSTEM.md @@ -60,7 +60,7 @@ ## 图表 - 仪表盘与使用记录复用 `TokenUsageTrend.vue`、`ModelDistributionChart.vue`、`GroupDistributionChart.vue`。 -- 用户端图表统一使用 ECharts(`vue-echarts`):Token 趋势、模型/分组分布、渠道状态趋势都走同一套主题令牌和 HTML tooltip(挂到 body),避免 canvas 边界裁切,鼠标悬停和手机点击都能完整展示。 +- 用户端图表统一使用 ECharts(`vue-echarts`):Token 趋势、模型/分组分布、渠道状态趋势都走同一套主题令牌和 HTML tooltip(图表容器内 + `confine`),避免 canvas 边界裁切,鼠标悬停和手机点击都能完整展示。 - 缓存读取、缓存命中率使用 `--st-chart-cache-read` / `--st-chart-cache-hit-rate` 语义色,不按文字灰度推导。 - 图表颜色同时适配亮暗主题和三套强调色;切换配色时同一帧更新。 diff --git a/src/theme/components/charts/GroupDistributionChart.vue b/src/theme/components/charts/GroupDistributionChart.vue index cd59487..18decf4 100644 --- a/src/theme/components/charts/GroupDistributionChart.vue +++ b/src/theme/components/charts/GroupDistributionChart.vue @@ -264,7 +264,7 @@ function tooltipHtml(title: string, color: string, value: number, total: number, const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' const formatted = asCost ? `$${formatCost(value)}` : formatTokens(value) return [ - '
', + '
', `

${escapeHtml(title)}

`, '
', ``, @@ -288,12 +288,17 @@ const doughnutOption = computed(() => { tooltip: { trigger: 'item', triggerOn: 'mousemove|click', - appendToBody: true, + appendToBody: false, + confine: false, + position: 'top', className: 'chart-echarts-tooltip', - backgroundColor: 'transparent', - borderWidth: 0, - padding: 0, - extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + backgroundColor: chartTokens.value.ink, + borderColor: chartTokens.value.border, + borderWidth: 1, + padding: 9, + borderRadius: 8, + textStyle: { color: chartTokens.value.bg, fontSize: 12 }, + extraCssText: 'box-shadow:var(--st-shadow-2);max-width:calc(100vw - 40px);white-space:normal;', formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, asCost), }, series: [ @@ -310,7 +315,6 @@ const doughnutOption = computed(() => { ], } }) - const formatTokens = (value: number): string => { if (value >= 1_000_000_000) { return `${(value / 1_000_000_000).toFixed(2)}B` diff --git a/src/theme/components/charts/ModelDistributionChart.vue b/src/theme/components/charts/ModelDistributionChart.vue index db2d75d..17ca38b 100644 --- a/src/theme/components/charts/ModelDistributionChart.vue +++ b/src/theme/components/charts/ModelDistributionChart.vue @@ -445,7 +445,7 @@ function tooltipHtml(title: string, color: string, value: number, total: number, const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : '0.0' const formatted = asCost ? `$${formatCost(value)}` : formatTokens(value) return [ - '
', + '
', `

${escapeHtml(title)}

`, '
', ``, @@ -469,12 +469,17 @@ const doughnutOption = computed(() => { tooltip: { trigger: 'item', triggerOn: 'mousemove|click', - appendToBody: true, + appendToBody: false, + confine: false, + position: 'top', className: 'chart-echarts-tooltip', - backgroundColor: 'transparent', - borderWidth: 0, - padding: 0, - extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + backgroundColor: chartTokens.value.ink, + borderColor: chartTokens.value.border, + borderWidth: 1, + padding: 9, + borderRadius: 8, + textStyle: { color: chartTokens.value.bg, fontSize: 12 }, + extraCssText: 'box-shadow:var(--st-shadow-3);max-width:calc(100vw - 40px);white-space:normal;', formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, asCost), }, series: [ @@ -505,12 +510,17 @@ const rankingDoughnutOption = computed(() => { tooltip: { trigger: 'item', triggerOn: 'mousemove|click', - appendToBody: true, + appendToBody: false, + confine: false, + position: 'top', className: 'chart-echarts-tooltip', - backgroundColor: 'transparent', - borderWidth: 0, - padding: 0, - extraCssText: 'box-shadow:none;padding:0;background:transparent;max-width:calc(100vw - 40px);white-space:normal;', + backgroundColor: chartTokens.value.ink, + borderColor: chartTokens.value.border, + borderWidth: 1, + padding: 9, + borderRadius: 8, + textStyle: { color: chartTokens.value.bg, fontSize: 12 }, + extraCssText: 'box-shadow:var(--st-shadow-3);max-width:calc(100vw - 40px);white-space:normal;', formatter: (params: any) => tooltipHtml(String(params.name ?? ''), String(params.color ?? chartTokens.value.brand), Number(params.value) || 0, total, true), }, series: [ diff --git a/src/theme/components/charts/TokenUsageTrend.vue b/src/theme/components/charts/TokenUsageTrend.vue index 67737f3..51d448b 100644 --- a/src/theme/components/charts/TokenUsageTrend.vue +++ b/src/theme/components/charts/TokenUsageTrend.vue @@ -7,13 +7,29 @@
- +
+ +
+
+ +
@@ -338,6 +273,7 @@ function selectPalette(option: UserPalette) { .uac__label { flex: 1; } .uac__chev { flex: none; color: var(--st-ink-3); } .uac__foot { padding-top: 4px; border-top: 1px solid var(--st-line); } +/* 配色:Reka Popover + 预设色板 */ .uac__palette { border: 0; background: none; @@ -345,6 +281,8 @@ function selectPalette(option: UserPalette) { text-align: start; cursor: pointer; } +.uac__palette-current { display: inline-flex; align-items: center; gap: 6px; min-width: 0; } +.uac__palette-dot { flex: none; width: 12px; height: 12px; border: 1px solid var(--st-line-2); border-radius: 50%; } .uac__palette-name { min-width: 0; overflow: hidden; @@ -353,6 +291,24 @@ function selectPalette(option: UserPalette) { text-overflow: ellipsis; white-space: nowrap; } +:global(.uac__palette-panel) { + width: min(220px, calc(100vw - 24px)); + padding: 10px; + border: 1px solid var(--st-line); + border-radius: var(--st-r-md); + background: var(--st-bg); + box-shadow: var(--st-shadow-3); + outline: none; +} +:global([data-reka-popper-content-wrapper]:has(> .uac__palette-panel)) { z-index: 100000020 !important; } +.uac__palette-panel-title { + margin: 0 0 8px; + padding: 0 4px; + color: var(--st-ink-3); + font-size: 0.72rem; + letter-spacing: 0.06em; +} +.uac__palette-grid { display: grid; gap: 2px; } .uac__logout { display: flex; align-items: center; @@ -372,50 +328,30 @@ function selectPalette(option: UserPalette) { } .uac__logout:hover { background: var(--st-danger-soft); } -.uac__palette[aria-expanded='true'] { background: var(--st-bg-soft); } -.uac__palette[aria-expanded='true'] .uac__chev { transform: rotate(90deg); } -.uac__palette-menu { - display: grid; - gap: 2px; - margin: 3px 0 4px 24px; - padding: 4px; - border: 1px solid var(--st-line); - border-radius: var(--st-r-sm); - background: var(--st-bg); - color: var(--st-ink); - font-family: var(--st-font-body); -} -.uac__palette-menu--floating { - z-index: 90; - width: 176px; - max-height: calc(100dvh - 24px); - overflow-y: auto; - margin: 0; - box-shadow: var(--st-shadow-3); -} -.uac__swatch { +.uac__palette-chip { display: flex; align-items: center; gap: 9px; width: 100%; - min-height: 36px; + min-height: 38px; padding: 6px 8px; - border-radius: var(--st-r-xs); + border: 0; + border-radius: 9px; + background: none; color: var(--st-ink-2); + font-family: inherit; + font-size: 0.84rem; text-align: start; + cursor: pointer; + transition: background-color var(--st-t-fast) var(--st-ease), color var(--st-t-fast) var(--st-ease); } -.uac__swatch:hover, -.uac__swatch[aria-checked='true'] { background: var(--st-bg-soft); color: var(--st-ink); } -.uac__swatch:focus-visible, -.uac__palette:focus-visible { outline: 2px solid var(--st-brand-text); outline-offset: -2px; } -.uac__swatch-dot { width: 14px; height: 14px; flex: none; border: 1px solid var(--st-line-2); border-radius: 50%; } -.uac__swatch-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 0.82rem; } -.uac__swatch-check { flex: none; color: var(--st-brand-text); } -@media (min-width: 640px) { - .uac__palette[aria-expanded='true'] .uac__chev { transform: none; } - .uac__palette--opens-left[aria-expanded='true'] .uac__chev { transform: rotate(180deg); } -} +.uac__palette-chip:hover, +.uac__palette-chip[aria-checked='true'] { background: var(--st-bg-soft); color: var(--st-ink); } +.uac__palette-chip:focus-visible { outline: 2px solid var(--st-brand-text); outline-offset: -2px; } +.uac__palette-chip-dot { flex: none; width: 16px; height: 16px; border: 1px solid var(--st-line-2); border-radius: 50%; } +.uac__palette-chip-name { flex: 1; min-width: 0; overflow-wrap: anywhere; } +.uac__palette-chip-check { flex: none; color: var(--st-brand-text); } @media (max-width: 639px) { - .uac__swatch { min-height: 44px; } + .uac__palette-chip { min-height: 44px; } } From 3fb2ab1707df07139fa6f966abd4d2f31a3a42c7 Mon Sep 17 00:00:00 2001 From: Mus Date: Sun, 6 Dec 2026 00:06:57 +0800 Subject: [PATCH 09/22] =?UTF-8?q?refactor(charts):=20=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E6=80=81=E6=94=B9=E7=94=A8=20ECharts=20=E5=8E=9F=E7=94=9F=20em?= =?UTF-8?q?phasis/blur=EF=BC=8C=E7=A7=BB=E9=99=A4=20DOM=20=E8=A7=82?= =?UTF-8?q?=E5=AF=9F=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 17 +---------------- .../charts/GroupDistributionChart.vue | 3 ++- .../charts/ModelDistributionChart.vue | 6 ++++-- src/theme/components/charts/TokenUsageTrend.vue | 4 ++-- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main.ts b/src/main.ts index 5416c1e..2a559ad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -90,28 +90,13 @@ async function bootstrap() { }) } - // 提示一旦隐藏,扇区/数据点高亮必须同步撤掉(ECharts 默认不会)。 + // 提示一旦隐藏(ECharts 自己收起也算),用原生 action 撤掉高亮,保证两者同生同灭。 const syncChartFeedback = (): void => { document.querySelectorAll(CHART_SELECTOR).forEach((node) => { const chart = chartOf(node) if (!chart || syncedCharts.has(chart)) return syncedCharts.add(chart) chart.on('hideTip', () => { chart.dispatchAction({ type: 'downplay' }) }) - let pending = 0 - const observer = new MutationObserver(() => { - if (pending) return - pending = requestAnimationFrame(() => { - pending = 0 - const tip = node.querySelector('.chart-echarts-tooltip') - if (!tip) return - // ECharts 隐藏 tooltip 时可能用 visibility/opacity 而不是 display:none - const style = getComputedStyle(tip) - if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') { - chart.dispatchAction({ type: 'downplay' }) - } - }) - }) - observer.observe(node, { childList: true, subtree: true, attributes: true, attributeFilter: ['style'] }) }) } diff --git a/src/theme/components/charts/GroupDistributionChart.vue b/src/theme/components/charts/GroupDistributionChart.vue index 759460c..e211027 100644 --- a/src/theme/components/charts/GroupDistributionChart.vue +++ b/src/theme/components/charts/GroupDistributionChart.vue @@ -310,7 +310,8 @@ const doughnutOption = computed(() => { avoidLabelOverlap: false, label: { show: false }, labelLine: { show: false }, - emphasis: { scale: true, scaleSize: 8 }, + emphasis: { scale: true, scaleSize: 8, focus: 'self' }, + blur: { itemStyle: { opacity: 0.45 } }, data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), }, ], diff --git a/src/theme/components/charts/ModelDistributionChart.vue b/src/theme/components/charts/ModelDistributionChart.vue index baf2a66..819e6e5 100644 --- a/src/theme/components/charts/ModelDistributionChart.vue +++ b/src/theme/components/charts/ModelDistributionChart.vue @@ -491,7 +491,8 @@ const doughnutOption = computed(() => { avoidLabelOverlap: false, label: { show: false }, labelLine: { show: false }, - emphasis: { scale: true, scaleSize: 8 }, + emphasis: { scale: true, scaleSize: 8, focus: 'self' }, + blur: { itemStyle: { opacity: 0.45 } }, data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), }, ], @@ -532,7 +533,8 @@ const rankingDoughnutOption = computed(() => { avoidLabelOverlap: false, label: { show: false }, labelLine: { show: false }, - emphasis: { scale: true, scaleSize: 8 }, + emphasis: { scale: true, scaleSize: 8, focus: 'self' }, + blur: { itemStyle: { opacity: 0.45 } }, data: labels.map((name, index) => ({ name, value: values[index], itemStyle: { color: colors[index] } })), }, ], diff --git a/src/theme/components/charts/TokenUsageTrend.vue b/src/theme/components/charts/TokenUsageTrend.vue index fbf650d..e3beb01 100644 --- a/src/theme/components/charts/TokenUsageTrend.vue +++ b/src/theme/components/charts/TokenUsageTrend.vue @@ -152,7 +152,7 @@ const lineSeries = ( showSymbol: true, symbol: 'circle' as const, symbolSize: 4, - emphasis: { scale: 1.35 }, + emphasis: { scale: 1.8 }, lineStyle: { width: 2, color }, itemStyle: { color }, ...(area ? { areaStyle: { color, opacity: 0.1 } } : {}), @@ -193,7 +193,7 @@ const lineOption = computed(() => { borderRadius: 8, textStyle: { color: chartTokens.value.bg, fontSize: 12 }, extraCssText: 'box-shadow:var(--st-shadow-2);max-width:calc(100vw - 40px);white-space:normal;', - axisPointer: { type: 'line', lineStyle: { color: chartTokens.value.border, width: 1 } }, + axisPointer: { type: 'line', snap: true, lineStyle: { color: chartTokens.value.border, width: 1 } }, formatter: (params: any) => { const items = Array.isArray(params) ? params : [params] const index = Math.round(Number(items[0]?.dataIndex ?? 0)) From 375105b11cde94a5eb35e90ac366c6dbb92e3e2b Mon Sep 17 00:00:00 2001 From: Mus Date: Sun, 6 Dec 2026 00:12:50 +0800 Subject: [PATCH 10/22] =?UTF-8?q?feat(auth):=20=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=B0=E4=BD=8F=E8=B4=A6=E5=8F=B7=EF=BC=8C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=8B=BE=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/copy/auth.ts | 2 + src/theme/views/auth/LoginView.vue | 93 +++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/composables/copy/auth.ts b/src/composables/copy/auth.ts index 5bb32ad..3ac0819 100644 --- a/src/composables/copy/auth.ts +++ b/src/composables/copy/auth.ts @@ -29,6 +29,7 @@ const zh: Dict = { 'auth.login.submitting': '正在登录…', 'auth.login.passkey': '用通行密钥登录', 'auth.login.passkeyBusy': '正在验证…', + 'auth.login.rememberAccount': '记住账号', // 注册 'auth.register.eyebrow': '开通 API 密钥', @@ -97,6 +98,7 @@ const en: Dict = { 'auth.login.submitting': 'Signing in…', 'auth.login.passkey': 'Sign in with a passkey', 'auth.login.passkeyBusy': 'Verifying…', + 'auth.login.rememberAccount': 'Remember account', 'auth.register.eyebrow': 'GET A KEY', 'auth.register.title': 'Create your key', diff --git a/src/theme/views/auth/LoginView.vue b/src/theme/views/auth/LoginView.vue index d8de630..919a9d1 100644 --- a/src/theme/views/auth/LoginView.vue +++ b/src/theme/views/auth/LoginView.vue @@ -53,7 +53,12 @@
-
+ + +

{{ c('auth.login.or') }}