gaoluyang
6 天以前 f7072c928b7cb9c8ae3bdba00e6c046e3f6f1c34
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<script lang="ts" setup>
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 { defaultSummary } from './data';
import AiInsights from './modules/ai-insights.vue';
import AlertPanel from './modules/alert-panel.vue';
import BizCards from './modules/biz-cards.vue';
import KpiCards from './modules/kpi-cards.vue';
import ProductionTrend from './modules/production-trend.vue';
import QuickActions from './modules/quick-actions.vue';
import WarehouseHrCards from './modules/warehouse-hr-cards.vue';
 
defineOptions({ name: 'DashboardAnalytics' });
 
const router = useRouter();
const summary = ref(defaultSummary);
const { canNavigate, canSeeMenu, canViewHome } = useHomeAccess();
 
// 首页模块跟随侧边栏菜单:菜单没开的模块整块不展示
/** MES 生产 KPI:任意一张卡的菜单开着就渲染整行 */
const showKpi = computed(
  () =>
    canViewHome.value &&
    ['MesProWorkOrder', 'MesProFeedback', 'MesQcIqc', 'MesDvMachinery'].some(
      (name) => canSeeMenu(name),
    ),
);
/** AI 智能分析:AI 模块的菜单开着才渲染 */
const showAiInsights = computed(
  () => canViewHome.value && canSeeMenu('AiChat'),
);
/** 生产趋势:数据来自生产报工 */
const showTrend = computed(
  () => canViewHome.value && canSeeMenu('MesProFeedback'),
);
/** 工单状态分布:数据来自生产订单 */
const showWorkOrderStatus = computed(
  () => canViewHome.value && canSeeMenu('MesProWorkOrder'),
);
 
const greeting = computed(() => {
  const hour = new Date().getHours();
  if (hour < 6) return '夜深了';
  if (hour < 9) return '早上好';
  if (hour < 12) return '上午好';
  if (hour < 14) return '中午好';
  if (hour < 18) return '下午好';
  return '晚上好';
});
 
const today = computed(() => {
  const d = new Date();
  const weekNames = ['日', '一', '二', '三', '四', '五', '六'];
  return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日 星期${weekNames[d.getDay()]}`;
});
 
function handleNavigate(name: string) {
  if (!canNavigate(name)) return;
  router.push({ name });
}
 
async function loadSummary() {
  if (!canViewHome.value) return;
  summary.value = await getHomeSummary();
}
 
onMounted(() => {
  loadSummary();
});
</script>
 
<template>
  <Page auto-content-height>
    <!-- 欢迎栏 -->
    <div class="glass-card mb-6 flex items-center justify-between rounded-2xl p-6">
      <div>
        <h1 class="bg-gradient-to-r from-blue-600 via-purple-600 to-pink-500 bg-clip-text text-2xl font-bold text-transparent dark:from-blue-400 dark:via-purple-400 dark:to-pink-400">
          {{ greeting }},欢迎回来
        </h1>
        <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">{{ today }}</p>
      </div>
      <div class="hidden items-center gap-2 sm:flex">
        <div class="flex items-center gap-1.5 rounded-full bg-emerald-50 px-3 py-1.5 text-xs font-medium text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-400">
          <span class="relative flex size-2">
            <span class="absolute inline-flex size-full animate-ping rounded-full bg-emerald-400 opacity-75" />
            <span class="relative inline-flex size-2 rounded-full bg-emerald-500" />
          </span>
          系统运行中
        </div>
      </div>
    </div>
 
    <!-- MES 生产 KPI -->
    <KpiCards v-if="showKpi" :summary="summary" @navigate="handleNavigate" />
 
    <!-- ERP/WMS/BPM 经营 KPI -->
    <BizCards @navigate="handleNavigate" />
 
    <!-- 仓储物流 / 人力资源业务概览(菜单没开的整组不展示) -->
    <WarehouseHrCards @navigate="handleNavigate" />
 
    <!-- AI 智能分析 -->
    <AiInsights
      v-if="showAiInsights"
      :active-order-count="summary.workOrderActiveCount"
      @navigate="handleNavigate"
    />
 
    <!-- 生产趋势 + 预警面板 -->
    <Row v-if="showTrend || showWorkOrderStatus" :gutter="16" class="mb-4">
      <Col
        v-if="showTrend"
        :lg="showWorkOrderStatus ? 14 : 24"
        :md="24"
        :sm="24"
        :xl="showWorkOrderStatus ? 14 : 24"
        :xs="24"
        class="mb-4"
      >
        <div class="glass-card rounded-2xl p-5">
          <h3 class="mb-4 text-base font-semibold text-gray-800 dark:text-gray-100">
            生产趋势(近7天)
          </h3>
          <ProductionTrend />
        </div>
      </Col>
      <Col
        v-if="showWorkOrderStatus"
        :lg="showTrend ? 10 : 24"
        :md="24"
        :sm="24"
        :xl="showTrend ? 10 : 24"
        :xs="24"
        class="mb-4"
      >
        <AlertPanel
          :repair-active-count="summary.repairActiveCount"
          @navigate="handleNavigate"
        />
      </Col>
    </Row>
 
    <!-- 快捷操作 -->
    <Row :gutter="16" class="mb-4">
      <Col :span="24">
        <QuickActions @navigate="handleNavigate" />
      </Col>
    </Row>
  </Page>
</template>
 
<style scoped>
.glass-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.8), rgba(255,255,255,0.5));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow:
    0 8px 32px rgba(0,0,0,0.04),
    0 2px 8px rgba(0,0,0,0.02),
    inset 0 1px 0 rgba(255,255,255,0.8);
}
 
.dark .glass-card {
  background: linear-gradient(135deg, rgba(30,30,50,0.7), rgba(20,20,40,0.5));
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow:
    0 8px 32px rgba(0,0,0,0.3),
    0 2px 8px rgba(0,0,0,0.2),
    inset 0 1px 0 rgba(255,255,255,0.05);
}
</style>