3 天以前 10dd6590cea8f20eff21025ee71c8a614a48cdb7
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
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { ref, watch } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { Card } from 'ant-design-vue';
 
import { getTraceConsumerScanTrend } from '#/api/mes/trace-consumer-scan';
 
import { getScanTrendChartOptions } from '../chart-options';
 
defineOptions({ name: 'MesTraceConsumerScanTrendChart' });
 
const props = defineProps<{
  startTime?: string;
  endTime?: string;
}>();
 
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
 
/** 加载趋势数据并渲染折线图 */
async function loadData() {
  const data = await getTraceConsumerScanTrend(props.startTime, props.endTime);
  const dates = data.map((d) => d.date.slice(5)); // yyyy-MM-dd -> MM-dd
  const totals = data.map((d) => d.total);
  const success = data.map((d) => d.success);
  const failed = data.map((d) => d.failed);
  await renderEcharts(getScanTrendChartOptions(dates, totals, success, failed));
}
 
watch(
  () => [props.startTime, props.endTime],
  () => {
    loadData();
  },
  { immediate: true },
);
</script>
 
<template>
  <Card title="扫码访问趋势" class="h-full">
    <EchartsUI ref="chartRef" class="h-[320px] w-full" />
  </Card>
</template>