4 天以前 b7eb1da8220f5b72f6891c3c6471ca386604cce4
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
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { onMounted, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { Card, RadioButton, RadioGroup } from 'ant-design-vue';
 
import { getBagCodeHomeTrend } from '#/api/mes/bag-code-home';
 
import { getBagCodeTrendChartOptions } from '../chart-options';
 
defineOptions({ name: 'BagCodeHomeTrendChart' });
 
const trendDays = ref(7); // 当前选中的天数范围
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
 
/** 加载袋码生成趋势数据并渲染图表 */
async function loadData() {
  const data = await getBagCodeHomeTrend(trendDays.value);
  const dates = data.map((d) => d.date.slice(5));
  const counts = data.map((d) => d.count);
  await renderEcharts(getBagCodeTrendChartOptions(dates, counts));
}
 
/** 切换天数范围 */
function handleDaysChange() {
  loadData();
}
 
onMounted(() => {
  loadData();
});
</script>
 
<template>
  <Card title="袋码生成趋势" class="h-full">
    <template #extra>
      <RadioGroup v-model:value="trendDays" size="small" @change="handleDaysChange">
        <RadioButton :value="7">近 7 天</RadioButton>
        <RadioButton :value="30">近 30 天</RadioButton>
      </RadioGroup>
    </template>
    <EchartsUI ref="chartRef" class="h-[320px] w-full" />
  </Card>
</template>