gaoluyang
2026-10-16 caddfd7efaabf86eb2348ae33d9b7a2281a2b167
src/views/dashboard/analytics/index.vue
@@ -4,9 +4,11 @@
import { Page } from '@vben/common-ui';
import { Card, Col, Row } from 'ant-design-vue';
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';
@@ -15,11 +17,35 @@
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();
@@ -38,10 +64,12 @@
});
function handleNavigate(name: string) {
  if (!canNavigate(name)) return;
  router.push({ name });
}
async function loadSummary() {
  if (!canViewHome.value) return;
  summary.value = await getHomeSummary();
}
@@ -72,20 +100,32 @@
    </div>
    <!-- MES 生产 KPI -->
    <KpiCards :summary="summary" @navigate="handleNavigate" />
    <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 :gutter="16" class="mb-4">
      <Col :lg="14" :md="24" :sm="24" :xl="14" :xs="24" class="mb-4">
    <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天)
@@ -93,9 +133,16 @@
          <ProductionTrend />
        </div>
      </Col>
      <Col :lg="10" :md="24" :sm="24" :xl="10" :xs="24" class="mb-4">
      <Col
        v-if="showWorkOrderStatus"
        :lg="showTrend ? 10 : 24"
        :md="24"
        :sm="24"
        :xl="showTrend ? 10 : 24"
        :xs="24"
        class="mb-4"
      >
        <AlertPanel
          :andon-active-count="summary.andonActiveCount"
          :repair-active-count="summary.repairActiveCount"
          @navigate="handleNavigate"
        />