liu
2026-09-29 982c97ab82f3beb1b4febcf014562eda34b9fc05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { EChartsOption } from '@vben/plugins/echarts';
 
import type { ArchiveStatApi } from '#/api/archive/stat';
 
/** 顶部统计卡片 */
export interface StatCard {
  key: keyof ArchiveStatApi.StatOverview;
  label: string;
  color: string;
}
 
export const STAT_CARDS: StatCard[] = [
  { key: 'totalCount', label: '档案总数', color: '#1677ff' },
  { key: 'inStockCount', label: '在库档案', color: '#52c41a' },
  { key: 'borrowedCount', label: '借出中档案', color: '#faad14' },
  { key: 'overdueCount', label: '逾期未还', color: '#ff4d4f' },
];
 
/** 通用饼图配置 */
export function buildPieOption(
  title: string,
  rows: { name: string; value: number }[],
): EChartsOption {
  return {
    title: { text: title, left: 'center', textStyle: { fontSize: 14 } },
    tooltip: { trigger: 'item' },
    legend: { orient: 'vertical', left: 'left', top: 'middle' },
    series: [
      {
        name: title,
        type: 'pie',
        radius: ['40%', '65%'],
        center: ['60%', '55%'],
        data: rows,
        emphasis: {
          itemStyle: { shadowBlur: 10, shadowColor: 'rgba(0, 0, 0, 0.5)' },
        },
      },
    ],
  };
}
 
/** 通用柱状图配置 */
export function buildBarOption(
  title: string,
  rows: { name: string; value: number }[],
): EChartsOption {
  return {
    title: { text: title, left: 'center', textStyle: { fontSize: 14 } },
    tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
    grid: { left: 20, right: 20, bottom: 20, containLabel: true },
    xAxis: {
      type: 'category',
      data: rows.map((item) => item.name),
      axisTick: { alignWithLabel: true },
    },
    yAxis: { type: 'value', minInterval: 1 },
    series: [
      {
        name: title,
        type: 'bar',
        barMaxWidth: 48,
        data: rows.map((item) => item.value),
        label: { show: true, position: 'top' },
      },
    ],
  };
}