2026-04-29 23:36:18 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="trend-chart">
|
2026-06-03 15:46:56 +08:00
|
|
|
|
<div class="chart-toolbar">
|
|
|
|
|
|
<div class="chart-legend">
|
|
|
|
|
|
<span
|
|
|
|
|
|
v-for="item in legendItems"
|
|
|
|
|
|
:key="item.name"
|
|
|
|
|
|
class="legend-pill"
|
|
|
|
|
|
:title="item.title"
|
|
|
|
|
|
>
|
|
|
|
|
|
<i :style="{ background: item.color }"></i>{{ item.name }}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="chart-unit">{{ unitLabel }}</span>
|
2026-04-29 23:36:18 +08:00
|
|
|
|
</div>
|
2026-05-28 16:24:59 +08:00
|
|
|
|
<div ref="chartElement" class="chart-body" role="img" :aria-label="ariaLabel"></div>
|
2026-04-29 23:36:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-05-28 16:24:59 +08:00
|
|
|
|
import { computed, shallowRef } from 'vue'
|
2026-06-03 15:46:56 +08:00
|
|
|
|
import {
|
|
|
|
|
|
BarChart as EChartsBarChart,
|
|
|
|
|
|
CustomChart as EChartsCustomChart,
|
|
|
|
|
|
LineChart as EChartsLineChart
|
|
|
|
|
|
} from 'echarts/charts'
|
2026-05-28 16:24:59 +08:00
|
|
|
|
import { GridComponent, TooltipComponent } from 'echarts/components'
|
|
|
|
|
|
import { use } from 'echarts/core'
|
|
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
|
|
|
|
|
|
|
|
import { useEcharts } from '../../composables/useEcharts.js'
|
2026-06-03 15:46:56 +08:00
|
|
|
|
import { resolveCssColor, useThemeColors } from '../../composables/useThemeColors.js'
|
2026-04-29 23:36:18 +08:00
|
|
|
|
|
2026-06-03 15:46:56 +08:00
|
|
|
|
use([GridComponent, TooltipComponent, EChartsBarChart, EChartsCustomChart, EChartsLineChart, CanvasRenderer])
|
2026-04-29 23:36:18 +08:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
labels: { type: Array, required: true },
|
2026-06-02 16:22:59 +08:00
|
|
|
|
mode: { type: String, default: 'amount' },
|
|
|
|
|
|
claimCount: { type: Array, default: () => [] },
|
|
|
|
|
|
claimAmount: { type: Array, default: () => [] },
|
2026-06-03 15:46:56 +08:00
|
|
|
|
categoryAmountSeries: { type: Array, default: () => [] },
|
2026-06-02 16:22:59 +08:00
|
|
|
|
applications: { type: Array, default: () => [] },
|
2026-06-03 15:46:56 +08:00
|
|
|
|
approved: { type: Array, default: () => [] }
|
2026-04-29 23:36:18 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-05-28 16:24:59 +08:00
|
|
|
|
const chartElement = shallowRef(null)
|
2026-05-27 09:17:57 +08:00
|
|
|
|
const themeColors = useThemeColors()
|
2026-06-03 15:46:56 +08:00
|
|
|
|
const isCountMode = computed(() => props.mode === 'count')
|
2026-05-27 09:17:57 +08:00
|
|
|
|
const chartColors = computed(() => ({
|
|
|
|
|
|
primary: themeColors.value.chartPrimary,
|
2026-06-03 15:46:56 +08:00
|
|
|
|
blue: themeColors.value.chartBlue,
|
|
|
|
|
|
amber: themeColors.value.chartAmber,
|
|
|
|
|
|
purple: themeColors.value.chartPurple,
|
|
|
|
|
|
success: themeColors.value.success,
|
|
|
|
|
|
danger: themeColors.value.chartDanger
|
|
|
|
|
|
}))
|
|
|
|
|
|
const fallbackSeriesColors = computed(() => [
|
|
|
|
|
|
chartColors.value.blue,
|
|
|
|
|
|
chartColors.value.amber,
|
|
|
|
|
|
chartColors.value.purple,
|
|
|
|
|
|
chartColors.value.success,
|
|
|
|
|
|
chartColors.value.danger,
|
|
|
|
|
|
chartColors.value.primary
|
|
|
|
|
|
])
|
|
|
|
|
|
const expenseCategoryColorMap = computed(() => ({
|
|
|
|
|
|
'差旅': chartColors.value.blue,
|
|
|
|
|
|
'办公用品': chartColors.value.amber,
|
|
|
|
|
|
'业务招待': chartColors.value.purple,
|
|
|
|
|
|
'通讯': chartColors.value.success,
|
|
|
|
|
|
'培训': '#65789b',
|
|
|
|
|
|
'交通': chartColors.value.primary,
|
|
|
|
|
|
'餐饮': '#9a7b4f',
|
|
|
|
|
|
'会议': '#7f6c9f'
|
2026-05-27 09:17:57 +08:00
|
|
|
|
}))
|
2026-06-02 16:22:59 +08:00
|
|
|
|
const claimCountSeries = computed(() => (
|
|
|
|
|
|
props.claimCount.length ? props.claimCount : props.applications
|
|
|
|
|
|
))
|
|
|
|
|
|
const claimAmountSeries = computed(() => (
|
|
|
|
|
|
props.claimAmount.length ? props.claimAmount : props.approved
|
|
|
|
|
|
))
|
|
|
|
|
|
const activeSeries = computed(() => (
|
|
|
|
|
|
isCountMode.value ? claimCountSeries.value : claimAmountSeries.value
|
|
|
|
|
|
))
|
2026-06-03 15:46:56 +08:00
|
|
|
|
const amountCategorySeries = computed(() => {
|
|
|
|
|
|
if (isCountMode.value) {
|
|
|
|
|
|
return []
|
|
|
|
|
|
}
|
|
|
|
|
|
return (Array.isArray(props.categoryAmountSeries) ? props.categoryAmountSeries : [])
|
|
|
|
|
|
.filter((item) => Array.isArray(item.data) && item.data.some((value) => Number(value || 0) > 0))
|
|
|
|
|
|
.slice(0, 6)
|
|
|
|
|
|
})
|
|
|
|
|
|
const stackedAmountData = computed(() => props.labels.map((_, index) => [
|
|
|
|
|
|
index,
|
|
|
|
|
|
...amountCategorySeries.value.map((item) => Number(item.data?.[index] || 0))
|
|
|
|
|
|
]))
|
2026-06-02 16:22:59 +08:00
|
|
|
|
const activeColor = computed(() => (
|
|
|
|
|
|
isCountMode.value ? chartColors.value.primary : chartColors.value.blue
|
|
|
|
|
|
))
|
|
|
|
|
|
const legendLabel = computed(() => (
|
2026-06-03 15:46:56 +08:00
|
|
|
|
isCountMode.value ? '报销数量' : '报销金额'
|
2026-06-02 16:22:59 +08:00
|
|
|
|
))
|
2026-06-03 15:46:56 +08:00
|
|
|
|
const unitLabel = computed(() => (isCountMode.value ? '单位:单' : '单位:元'))
|
|
|
|
|
|
const legendItems = computed(() => {
|
|
|
|
|
|
if (amountCategorySeries.value.length) {
|
|
|
|
|
|
return amountCategorySeries.value.map((item, index) => ({
|
|
|
|
|
|
name: item.name || `费用类型 ${index + 1}`,
|
|
|
|
|
|
color: resolveCategoryColor(item, index),
|
|
|
|
|
|
title: `${item.name || `费用类型 ${index + 1}`} ${formatCurrency(item.total || 0)}`
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
return [{
|
|
|
|
|
|
name: legendLabel.value,
|
|
|
|
|
|
color: activeColor.value,
|
|
|
|
|
|
title: `${legendLabel.value} ${unitLabel.value}`
|
|
|
|
|
|
}]
|
|
|
|
|
|
})
|
2026-06-02 16:22:59 +08:00
|
|
|
|
const maxValue = computed(() => Math.max(...activeSeries.value.map((value) => Number(value || 0)), 1))
|
2026-06-03 15:46:56 +08:00
|
|
|
|
const stackedMaxValue = computed(() => {
|
|
|
|
|
|
if (!amountCategorySeries.value.length) {
|
|
|
|
|
|
return maxValue.value
|
|
|
|
|
|
}
|
|
|
|
|
|
const dailyTotals = props.labels.map((_, index) => amountCategorySeries.value
|
|
|
|
|
|
.reduce((sum, item) => sum + Number(item.data?.[index] || 0), 0))
|
|
|
|
|
|
return Math.max(...dailyTotals, 1)
|
|
|
|
|
|
})
|
2026-05-28 16:24:59 +08:00
|
|
|
|
const ariaLabel = computed(() =>
|
|
|
|
|
|
props.labels.map((label, index) => (
|
2026-06-02 16:22:59 +08:00
|
|
|
|
isCountMode.value
|
|
|
|
|
|
? `${label}报销${claimCountSeries.value[index] || 0}单`
|
|
|
|
|
|
: `${label}报销金额${formatCurrency(claimAmountSeries.value[index] || 0)}`
|
2026-06-03 15:46:56 +08:00
|
|
|
|
)).join(',')
|
2026-05-28 16:24:59 +08:00
|
|
|
|
)
|
2026-06-03 15:46:56 +08:00
|
|
|
|
const chartSeries = computed(() => {
|
|
|
|
|
|
if (!isCountMode.value && amountCategorySeries.value.length) {
|
|
|
|
|
|
return [{
|
|
|
|
|
|
name: '费用类型占比',
|
|
|
|
|
|
type: 'custom',
|
|
|
|
|
|
data: stackedAmountData.value,
|
|
|
|
|
|
renderItem: renderStackedAmountBar,
|
|
|
|
|
|
animationDelay: (index) => index * 18,
|
|
|
|
|
|
tooltip: {
|
|
|
|
|
|
formatter: (params) => formatStackedTooltip(params)
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
|
|
|
|
|
}
|
2026-05-01 00:39:24 +08:00
|
|
|
|
|
2026-06-03 15:46:56 +08:00
|
|
|
|
return [{
|
|
|
|
|
|
name: legendLabel.value,
|
|
|
|
|
|
type: isCountMode.value ? 'line' : 'bar',
|
|
|
|
|
|
data: activeSeries.value,
|
|
|
|
|
|
barWidth: 16,
|
|
|
|
|
|
smooth: isCountMode.value,
|
|
|
|
|
|
symbol: isCountMode.value ? 'circle' : 'none',
|
|
|
|
|
|
symbolSize: 7,
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
width: 2.5,
|
|
|
|
|
|
color: activeColor.value
|
|
|
|
|
|
},
|
|
|
|
|
|
itemStyle: {
|
|
|
|
|
|
color: isCountMode.value ? '#ffffff' : activeColor.value,
|
|
|
|
|
|
borderColor: activeColor.value,
|
|
|
|
|
|
borderWidth: isCountMode.value ? 2.5 : 0,
|
|
|
|
|
|
borderRadius: [4, 4, 0, 0]
|
|
|
|
|
|
},
|
|
|
|
|
|
areaStyle: {
|
|
|
|
|
|
opacity: isCountMode.value ? 1 : 0,
|
|
|
|
|
|
color: {
|
|
|
|
|
|
type: 'linear',
|
|
|
|
|
|
x: 0,
|
|
|
|
|
|
y: 0,
|
|
|
|
|
|
x2: 0,
|
|
|
|
|
|
y2: 1,
|
|
|
|
|
|
colorStops: [
|
|
|
|
|
|
{ offset: 0, color: toRgba(activeColor.value, 0.14) },
|
|
|
|
|
|
{ offset: 1, color: toRgba(activeColor.value, 0.02) }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
tooltip: {
|
|
|
|
|
|
valueFormatter: (value) => (
|
|
|
|
|
|
isCountMode.value ? `${Number(value || 0)} 单` : formatCurrency(value)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
|
|
|
|
|
})
|
2026-05-28 16:24:59 +08:00
|
|
|
|
const chartOptions = computed(() => ({
|
|
|
|
|
|
backgroundColor: 'transparent',
|
2026-05-28 22:33:53 +08:00
|
|
|
|
animation: true,
|
|
|
|
|
|
animationDuration: 1200,
|
|
|
|
|
|
animationDurationUpdate: 1200,
|
|
|
|
|
|
animationEasing: 'linear',
|
|
|
|
|
|
animationEasingUpdate: 'linear',
|
2026-05-28 16:24:59 +08:00
|
|
|
|
grid: {
|
2026-06-03 15:46:56 +08:00
|
|
|
|
top: 12,
|
2026-06-02 16:22:59 +08:00
|
|
|
|
right: 24,
|
2026-05-28 16:24:59 +08:00
|
|
|
|
bottom: 22,
|
|
|
|
|
|
left: 36,
|
|
|
|
|
|
containLabel: true
|
2026-04-29 23:36:18 +08:00
|
|
|
|
},
|
2026-05-28 16:24:59 +08:00
|
|
|
|
tooltip: {
|
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
|
confine: true,
|
|
|
|
|
|
appendToBody: true,
|
|
|
|
|
|
backgroundColor: 'rgba(255, 255, 255, 0.98)',
|
|
|
|
|
|
borderColor: 'rgba(148, 163, 184, 0.24)',
|
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
|
padding: [9, 10],
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
color: '#334155',
|
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
|
fontWeight: 700
|
2026-04-29 23:36:18 +08:00
|
|
|
|
},
|
2026-06-03 15:46:56 +08:00
|
|
|
|
extraCssText: 'border-radius:4px;box-shadow:0 12px 28px rgba(15,23,42,.12);',
|
|
|
|
|
|
formatter: (params) => formatTooltip(params)
|
2026-05-28 16:24:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
xAxis: {
|
|
|
|
|
|
type: 'category',
|
|
|
|
|
|
data: props.labels,
|
|
|
|
|
|
boundaryGap: true,
|
|
|
|
|
|
axisTick: { show: false },
|
|
|
|
|
|
axisLine: { lineStyle: { color: 'rgba(148, 163, 184, 0.28)' } },
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
fontWeight: 700
|
2026-04-29 23:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-06-02 16:22:59 +08:00
|
|
|
|
yAxis: {
|
|
|
|
|
|
type: 'value',
|
|
|
|
|
|
min: 0,
|
2026-06-03 15:46:56 +08:00
|
|
|
|
max: Math.ceil(stackedMaxValue.value * 1.18),
|
2026-06-02 16:22:59 +08:00
|
|
|
|
splitNumber: 5,
|
2026-06-03 15:46:56 +08:00
|
|
|
|
name: '',
|
2026-06-02 16:22:59 +08:00
|
|
|
|
axisLabel: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
fontWeight: 700,
|
|
|
|
|
|
formatter: (value) => (isCountMode.value ? `${Math.round(value)}` : formatAxisCurrency(value))
|
2026-05-28 16:24:59 +08:00
|
|
|
|
},
|
2026-06-02 16:22:59 +08:00
|
|
|
|
splitLine: { lineStyle: { color: 'rgba(226, 232, 240, 0.75)' } }
|
|
|
|
|
|
},
|
2026-06-03 15:46:56 +08:00
|
|
|
|
series: chartSeries.value
|
2026-05-28 16:24:59 +08:00
|
|
|
|
}))
|
2026-04-29 23:36:18 +08:00
|
|
|
|
|
2026-05-28 16:24:59 +08:00
|
|
|
|
useEcharts(chartElement, chartOptions)
|
2026-04-29 23:36:18 +08:00
|
|
|
|
|
2026-05-28 16:24:59 +08:00
|
|
|
|
function toRgba(color, alpha) {
|
|
|
|
|
|
const normalized = String(color || '').trim()
|
|
|
|
|
|
const hex = normalized.replace('#', '')
|
|
|
|
|
|
if (/^[\da-f]{6}$/i.test(hex)) {
|
|
|
|
|
|
const r = parseInt(hex.slice(0, 2), 16)
|
|
|
|
|
|
const g = parseInt(hex.slice(2, 4), 16)
|
|
|
|
|
|
const b = parseInt(hex.slice(4, 6), 16)
|
|
|
|
|
|
return `rgba(${r}, ${g}, ${b}, ${alpha})`
|
2026-04-29 23:36:18 +08:00
|
|
|
|
}
|
2026-05-28 16:24:59 +08:00
|
|
|
|
return `rgba(58, 124, 165, ${alpha})`
|
2026-04-29 23:36:18 +08:00
|
|
|
|
}
|
2026-06-02 16:22:59 +08:00
|
|
|
|
|
2026-06-03 15:46:56 +08:00
|
|
|
|
function resolveCategoryColor(item, index) {
|
|
|
|
|
|
const name = String(item?.name || '').trim()
|
|
|
|
|
|
const mapped = expenseCategoryColorMap.value[name]
|
|
|
|
|
|
if (mapped) {
|
|
|
|
|
|
return mapped
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fallback = fallbackSeriesColors.value[index % fallbackSeriesColors.value.length]
|
|
|
|
|
|
return resolveCssColor(item?.color, fallback)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderStackedAmountBar(params, api) {
|
|
|
|
|
|
const categoryIndex = Number(api.value(0))
|
|
|
|
|
|
const zeroPoint = api.coord([categoryIndex, 0])
|
|
|
|
|
|
const xCenter = zeroPoint[0]
|
|
|
|
|
|
const zeroY = zeroPoint[1]
|
|
|
|
|
|
const categoryWidth = api.size([1, 0])?.[0] || 32
|
|
|
|
|
|
const barWidth = Math.max(12, Math.min(24, categoryWidth * 0.48))
|
|
|
|
|
|
const barX = xCenter - barWidth / 2
|
|
|
|
|
|
let accumulated = 0
|
|
|
|
|
|
const values = amountCategorySeries.value.map((_, index) => Number(api.value(index + 1) || 0))
|
|
|
|
|
|
const lastVisibleIndex = values.reduce((last, value, index) => (value > 0 ? index : last), -1)
|
|
|
|
|
|
const children = []
|
|
|
|
|
|
let topY = zeroY
|
|
|
|
|
|
|
|
|
|
|
|
values.forEach((value, index) => {
|
|
|
|
|
|
if (value <= 0) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const lower = accumulated
|
|
|
|
|
|
const upper = accumulated + value
|
|
|
|
|
|
const lowerY = api.coord([categoryIndex, lower])[1]
|
|
|
|
|
|
const upperY = api.coord([categoryIndex, upper])[1]
|
|
|
|
|
|
const height = Math.max(1, lowerY - upperY)
|
|
|
|
|
|
topY = Math.min(topY, upperY)
|
|
|
|
|
|
accumulated = upper
|
|
|
|
|
|
children.push({
|
|
|
|
|
|
type: 'rect',
|
|
|
|
|
|
shape: {
|
|
|
|
|
|
x: barX,
|
|
|
|
|
|
y: upperY,
|
|
|
|
|
|
width: barWidth,
|
|
|
|
|
|
height,
|
|
|
|
|
|
r: index === lastVisibleIndex ? [4, 4, 0, 0] : 0
|
|
|
|
|
|
},
|
|
|
|
|
|
style: {
|
|
|
|
|
|
fill: resolveCategoryColor(amountCategorySeries.value[index], index)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (!children.length) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
type: 'group',
|
|
|
|
|
|
children: []
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const totalHeight = Math.max(1, zeroY - topY)
|
|
|
|
|
|
return {
|
|
|
|
|
|
type: 'group',
|
|
|
|
|
|
originX: xCenter,
|
|
|
|
|
|
originY: zeroY,
|
|
|
|
|
|
scaleY: 1,
|
|
|
|
|
|
enterFrom: {
|
|
|
|
|
|
scaleY: 0
|
|
|
|
|
|
},
|
|
|
|
|
|
transition: ['scaleY'],
|
|
|
|
|
|
clipPath: {
|
|
|
|
|
|
type: 'rect',
|
|
|
|
|
|
shape: {
|
|
|
|
|
|
x: barX,
|
|
|
|
|
|
y: topY,
|
|
|
|
|
|
width: barWidth,
|
|
|
|
|
|
height: totalHeight
|
|
|
|
|
|
},
|
|
|
|
|
|
enterFrom: {
|
|
|
|
|
|
shape: {
|
|
|
|
|
|
x: barX,
|
|
|
|
|
|
y: zeroY,
|
|
|
|
|
|
width: barWidth,
|
|
|
|
|
|
height: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
transition: ['shape']
|
|
|
|
|
|
},
|
|
|
|
|
|
children
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatTooltip(params) {
|
|
|
|
|
|
const items = Array.isArray(params) ? params : [params]
|
|
|
|
|
|
const first = items[0]
|
|
|
|
|
|
if (!first) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!isCountMode.value && amountCategorySeries.value.length) {
|
|
|
|
|
|
return formatStackedTooltip(first)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const index = Number(first.dataIndex || 0)
|
|
|
|
|
|
const label = props.labels[index] || first.axisValueLabel || first.name || ''
|
|
|
|
|
|
const value = isCountMode.value ? claimCountSeries.value[index] : activeSeries.value[index]
|
|
|
|
|
|
const displayValue = isCountMode.value ? `${Number(value || 0)} 单` : formatCurrency(value)
|
|
|
|
|
|
return `${label}<br/>${legendLabel.value}:${displayValue}`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatStackedTooltip(params) {
|
|
|
|
|
|
const index = Number(params?.data?.[0] ?? params?.dataIndex ?? 0)
|
|
|
|
|
|
const label = props.labels[index] || params?.axisValueLabel || ''
|
|
|
|
|
|
const rows = amountCategorySeries.value
|
|
|
|
|
|
.map((item, itemIndex) => ({
|
|
|
|
|
|
name: item.name || `费用类型 ${itemIndex + 1}`,
|
|
|
|
|
|
color: resolveCategoryColor(item, itemIndex),
|
|
|
|
|
|
value: Number(item.data?.[index] || 0)
|
|
|
|
|
|
}))
|
|
|
|
|
|
.filter((item) => item.value > 0)
|
|
|
|
|
|
const total = rows.reduce((sum, item) => sum + item.value, 0)
|
|
|
|
|
|
const details = rows.map((item) => (
|
|
|
|
|
|
`<span style="display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:6px;background:${item.color};"></span>${item.name}:${formatCurrency(item.value)}`
|
|
|
|
|
|
))
|
|
|
|
|
|
return [
|
|
|
|
|
|
label,
|
|
|
|
|
|
...details,
|
|
|
|
|
|
`合计:${formatCurrency(total)}`
|
|
|
|
|
|
].join('<br/>')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-02 16:22:59 +08:00
|
|
|
|
function formatCurrency(value) {
|
|
|
|
|
|
const number = Number(value || 0)
|
|
|
|
|
|
if (number >= 1000000) return `¥${(number / 1000000).toFixed(1)}M`
|
|
|
|
|
|
if (number >= 1000) return `¥${(number / 1000).toFixed(1)}K`
|
|
|
|
|
|
return `¥${Math.round(number)}`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatAxisCurrency(value) {
|
|
|
|
|
|
const number = Number(value || 0)
|
|
|
|
|
|
if (number >= 1000000) return `${(number / 1000000).toFixed(1)}M`
|
|
|
|
|
|
if (number >= 1000) return `${(number / 1000).toFixed(0)}K`
|
|
|
|
|
|
return `${Math.round(number)}`
|
|
|
|
|
|
}
|
2026-04-29 23:36:18 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.trend-chart {
|
|
|
|
|
|
height: 280px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-03 15:46:56 +08:00
|
|
|
|
.chart-toolbar {
|
|
|
|
|
|
min-height: 30px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-29 23:36:18 +08:00
|
|
|
|
.chart-legend {
|
2026-06-03 15:46:56 +08:00
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 0;
|
2026-04-29 23:36:18 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-06-03 15:46:56 +08:00
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 6px 12px;
|
2026-04-29 23:36:18 +08:00
|
|
|
|
color: #475569;
|
|
|
|
|
|
font-size: 12px;
|
2026-06-03 15:46:56 +08:00
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.legend-pill {
|
|
|
|
|
|
max-width: 132px;
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
color: #475569;
|
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
2026-04-29 23:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-legend i {
|
2026-06-03 15:46:56 +08:00
|
|
|
|
flex: 0 0 auto;
|
2026-04-29 23:36:18 +08:00
|
|
|
|
display: inline-block;
|
|
|
|
|
|
width: 8px;
|
|
|
|
|
|
height: 8px;
|
|
|
|
|
|
border-radius: 2px;
|
2026-06-03 15:46:56 +08:00
|
|
|
|
margin-right: 5px;
|
2026-04-29 23:36:18 +08:00
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-03 15:46:56 +08:00
|
|
|
|
.chart-unit {
|
|
|
|
|
|
flex: 0 0 auto;
|
|
|
|
|
|
padding: 2px 8px;
|
|
|
|
|
|
border: 1px solid #e2e8f0;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
background: #f8fafc;
|
|
|
|
|
|
color: #64748b;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-29 23:36:18 +08:00
|
|
|
|
.chart-body {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-height: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|