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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script lang="ts" setup>
import type { MesHomeApi } from '#/api/mes/home';
 
import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
 
import { Page } from '@vben/common-ui';
 
import { Col, Row } from 'ant-design-vue';
 
import { getHomeSummary } from '#/api/mes/home';
import { useHomeAccess } from '#/utils/use-home-access';
 
import {
  ALERT_MENUS,
  defaultSummary,
  HOME_BLOCK_MENUS,
  HOME_SHORTCUTS,
} from './data';
import AlertPanel from './modules/alert-panel.vue';
import KpiCards from './modules/kpi-cards.vue';
import ProductionTrend from './modules/production-trend.vue';
import Shortcuts from './modules/shortcuts.vue';
import WorkOrderChart from './modules/work-order-chart.vue';
 
const router = useRouter();
const summary = ref<MesHomeApi.Summary>(defaultSummary); // 首页汇总统计
 
// 首页模块跟随侧边栏菜单:菜单没开的模块整块不展示
const { canSeeMenu } = useHomeAccess();
/** 生产趋势(取自生产报工) */
const showTrend = computed(() => canSeeMenu(HOME_BLOCK_MENUS.feedback));
/** 待办与异常:任意一条的菜单开着就渲染这一列 */
const showAlert = computed(() => ALERT_MENUS.some((menu) => canSeeMenu(menu)));
/** 订单状态分布(取自生产订单) */
const showChart = computed(() => canSeeMenu(HOME_BLOCK_MENUS.workOrder));
/** 快捷入口:任意一个入口的菜单开着就渲染这一列 */
const showShortcuts = computed(() =>
  HOME_SHORTCUTS.some((item) => canSeeMenu(item.menu)),
);
 
/** 跳转到目标页面(按路由 name) */
function handleNavigate(name: string) {
  router.push({ name });
}
 
/** 加载首页汇总统计 */
async function loadSummary() {
  summary.value = await getHomeSummary();
}
 
onMounted(() => {
  loadSummary();
});
</script>
 
<template>
  <Page><!-- 第一行:核心 KPI 汇总卡片 -->
    <KpiCards :summary="summary" class="mb-4" @navigate="handleNavigate" />
 
    <!-- 第二行:生产趋势 + 待办异常 -->
    <Row v-if="showTrend || showAlert" :gutter="16" class="mb-4">
      <Col
        v-if="showTrend"
        :lg="showAlert ? 16 : 24"
        :md="24"
        :sm="24"
        :xl="showAlert ? 16 : 24"
        :xs="24"
        class="mb-4"
      >
        <ProductionTrend />
      </Col>
      <Col
        v-if="showAlert"
        :lg="showTrend ? 8 : 24"
        :md="24"
        :sm="24"
        :xl="showTrend ? 8 : 24"
        :xs="24"
        class="mb-4"
      >
        <AlertPanel :summary="summary" @navigate="handleNavigate" />
      </Col>
    </Row>
 
    <!-- 第三行:订单分布 + 快捷入口 -->
    <Row v-if="showChart || showShortcuts" :gutter="16">
      <Col
        v-if="showChart"
        :lg="showShortcuts ? 12 : 24"
        :md="24"
        :sm="24"
        :xl="showShortcuts ? 12 : 24"
        :xs="24"
        class="mb-4"
      >
        <WorkOrderChart />
      </Col>
      <Col
        v-if="showShortcuts"
        :lg="showChart ? 12 : 24"
        :md="24"
        :sm="24"
        :xl="showChart ? 12 : 24"
        :xs="24"
        class="mb-4"
      >
        <Shortcuts @navigate="handleNavigate" />
      </Col>
    </Row>
  </Page>
</template>