gaoluyang
2026-10-16 caddfd7efaabf86eb2348ae33d9b7a2281a2b167
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
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { computed, onMounted, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { Card, RadioButton, RadioGroup } from 'ant-design-vue';
 
import { getProductionTrend } from '#/api/mes/home';
 
import { useHomeAccess } from '#/utils/use-home-access';
 
import { getProductionTrendChartOptions } from '../chart-options';
import { HOME_BLOCK_MENUS } from '../data';
 
defineOptions({ name: 'MesHomeProductionTrend' });
 
const trendDays = ref(7); // 当前选中的天数范围
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const { canSeeMenu } = useHomeAccess();
 
/** 生产趋势取自生产报工,报工菜单没开就不展示、不请求 */
const showTrend = computed(() => canSeeMenu(HOME_BLOCK_MENUS.feedback));
 
/** 加载生产趋势数据并渲染图表 */
async function loadData() {
  if (!showTrend.value) return;
  const data = await getProductionTrend(trendDays.value);
  const dates = data.map((d) => d.date.slice(5));
  const quantities = data.map((d) => d.quantity);
  const qualified = data.map((d) => d.qualifiedQuantity);
  const unqualified = data.map((d) => d.unqualifiedQuantity);
  await renderEcharts(
    getProductionTrendChartOptions(dates, quantities, qualified, unqualified),
  );
}
 
/** 切换天数范围 */
function handleDaysChange() {
  loadData();
}
 
onMounted(() => {
  loadData();
});
</script>
 
<template>
  <Card v-if="showTrend" 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>