2026-04-29 23:36:18 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="trend-chart">
|
|
|
|
|
|
<div class="chart-legend">
|
2026-06-02 16:22:59 +08:00
|
|
|
|
<span><i :style="{ background: activeColor }"></i>{{ legendLabel }}</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'
|
|
|
|
|
|
import { BarChart as EChartsBarChart, LineChart as EChartsLineChart } from 'echarts/charts'
|
|
|
|
|
|
import { GridComponent, TooltipComponent } from 'echarts/components'
|
|
|
|
|
|
import { use } from 'echarts/core'
|
|
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
|
|
|
|
|
|
|
|
import { useEcharts } from '../../composables/useEcharts.js'
|
2026-05-27 09:17:57 +08:00
|
|
|
|
import { useThemeColors } from '../../composables/useThemeColors.js'
|
2026-04-29 23:36:18 +08:00
|
|
|
|
|
2026-05-28 16:24:59 +08:00
|
|
|
|
use([GridComponent, TooltipComponent, EChartsBarChart, 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: () => [] },
|
|
|
|
|
|
applications: { type: Array, default: () => [] },
|
|
|
|
|
|
approved: { type: Array, default: () => [] },
|
|
|
|
|
|
avgHours: { 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()
|
|
|
|
|
|
const chartColors = computed(() => ({
|
|
|
|
|
|
primary: themeColors.value.chartPrimary,
|
2026-06-02 16:22:59 +08:00
|
|
|
|
blue: themeColors.value.chartBlue
|
2026-05-27 09:17:57 +08:00
|
|
|
|
}))
|
2026-06-02 16:22:59 +08:00
|
|
|
|
const isCountMode = computed(() => props.mode === 'count')
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
))
|
|
|
|
|
|
const activeColor = computed(() => (
|
|
|
|
|
|
isCountMode.value ? chartColors.value.primary : chartColors.value.blue
|
|
|
|
|
|
))
|
|
|
|
|
|
const legendLabel = computed(() => (
|
|
|
|
|
|
isCountMode.value ? '报销数量(单)' : '报销金额(元)'
|
|
|
|
|
|
))
|
|
|
|
|
|
const maxValue = computed(() => Math.max(...activeSeries.value.map((value) => Number(value || 0)), 1))
|
2026-05-01 00:39:24 +08:00
|
|
|
|
|
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-05-28 16:24:59 +08:00
|
|
|
|
)).join(';')
|
|
|
|
|
|
)
|
2026-05-01 00:39:24 +08:00
|
|
|
|
|
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: {
|
|
|
|
|
|
top: 18,
|
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-05-28 16:24:59 +08:00
|
|
|
|
extraCssText: 'border-radius:4px;box-shadow:0 12px 28px rgba(15,23,42,.12);'
|
|
|
|
|
|
},
|
|
|
|
|
|
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,
|
|
|
|
|
|
max: Math.ceil(maxValue.value * 1.2),
|
|
|
|
|
|
splitNumber: 5,
|
|
|
|
|
|
name: isCountMode.value ? '单' : '元',
|
|
|
|
|
|
nameTextStyle: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
fontWeight: 700
|
2026-05-28 16:24:59 +08:00
|
|
|
|
},
|
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)' } }
|
|
|
|
|
|
},
|
|
|
|
|
|
series: [
|
2026-05-28 16:24:59 +08:00
|
|
|
|
{
|
2026-06-02 16:22:59 +08:00
|
|
|
|
name: legendLabel.value,
|
|
|
|
|
|
type: isCountMode.value ? 'line' : 'bar',
|
|
|
|
|
|
data: activeSeries.value,
|
|
|
|
|
|
barWidth: 16,
|
|
|
|
|
|
smooth: isCountMode.value,
|
|
|
|
|
|
symbol: isCountMode.value ? 'circle' : 'none',
|
2026-05-28 16:24:59 +08:00
|
|
|
|
symbolSize: 7,
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
width: 2.5,
|
2026-06-02 16:22:59 +08:00
|
|
|
|
color: activeColor.value
|
2026-05-28 16:24:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
itemStyle: {
|
2026-06-02 16:22:59 +08:00
|
|
|
|
color: isCountMode.value ? '#ffffff' : activeColor.value,
|
|
|
|
|
|
borderColor: activeColor.value,
|
|
|
|
|
|
borderWidth: isCountMode.value ? 2.5 : 0,
|
|
|
|
|
|
borderRadius: [4, 4, 0, 0]
|
2026-05-28 16:24:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
areaStyle: {
|
2026-06-02 16:22:59 +08:00
|
|
|
|
opacity: isCountMode.value ? 1 : 0,
|
2026-05-28 16:24:59 +08:00
|
|
|
|
color: {
|
|
|
|
|
|
type: 'linear',
|
|
|
|
|
|
x: 0,
|
|
|
|
|
|
y: 0,
|
|
|
|
|
|
x2: 0,
|
|
|
|
|
|
y2: 1,
|
|
|
|
|
|
colorStops: [
|
2026-06-02 16:22:59 +08:00
|
|
|
|
{ offset: 0, color: toRgba(activeColor.value, 0.14) },
|
|
|
|
|
|
{ offset: 1, color: toRgba(activeColor.value, 0.02) }
|
2026-05-28 16:24:59 +08:00
|
|
|
|
]
|
|
|
|
|
|
}
|
2026-06-02 16:22:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
tooltip: {
|
|
|
|
|
|
valueFormatter: (value) => (
|
|
|
|
|
|
isCountMode.value ? `${Number(value || 0)} 单` : formatCurrency(value)
|
|
|
|
|
|
)
|
2026-04-29 23:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-legend {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
color: #475569;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-legend i {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
width: 8px;
|
|
|
|
|
|
height: 8px;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
margin-right: 4px;
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-body {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-height: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|