gaoluyang
4 天以前 8151c3253dc287a79914bc08414af17dfb380c96
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 { computed, onMounted, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { Card } from 'ant-design-vue';
 
import { getWorkOrderStatusDistribution } from '#/api/mes/home';
 
import { useHomeAccess } from '#/utils/use-home-access';
 
import { getWorkOrderStatusChartOptions } from '../chart-options';
import { HOME_BLOCK_MENUS, WORK_ORDER_STATUS_COLOR_MAP } from '../data';
 
defineOptions({ name: 'MesHomeWorkOrderChart' });
 
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const { canSeeMenu } = useHomeAccess();
 
/** 菜单没开就不展示、不请求 */
const showChart = computed(() => canSeeMenu(HOME_BLOCK_MENUS.workOrder));
 
/** 加载订单状态分布数据并渲染饼图 */
async function loadData() {
  if (!showChart.value) return;
  const data = await getWorkOrderStatusDistribution();
  const chartData = data.map((d) => ({
    itemStyle: { color: WORK_ORDER_STATUS_COLOR_MAP[d.status] || '#409EFF' },
    name: d.statusName,
    value: d.count,
  }));
  await renderEcharts(getWorkOrderStatusChartOptions(chartData));
}
 
onMounted(() => {
  loadData();
});
</script>
 
<template>
  <Card v-if="showChart" title="订单状态分布" class="h-full">
    <EchartsUI ref="chartRef" class="h-[280px] w-full" />
  </Card>
</template>