From f56d41d87f6b126812bd8eb08be9e662a2834871 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期五, 30 十月 2026 18:39:03 +0800
Subject: [PATCH] feat(dashboard): BI 看板新增出勤指标与库存采购,优化全看板自适应

---
 src/views/dashboard/analytics/modules/hr-stock-cards.vue |  243 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/views/dashboard/analytics/modules/quick-actions.vue  |    4 
 src/views/dashboard/analytics/modules/kpi-cards.vue      |    6 
 src/views/dashboard/analytics/index.vue                  |   10 +
 src/views/dashboard/analytics/modules/biz-cards.vue      |    8 
 5 files changed, 259 insertions(+), 12 deletions(-)

diff --git a/src/views/dashboard/analytics/index.vue b/src/views/dashboard/analytics/index.vue
index 90988e2..a0792a0 100644
--- a/src/views/dashboard/analytics/index.vue
+++ b/src/views/dashboard/analytics/index.vue
@@ -13,6 +13,7 @@
 import AiInsights from './modules/ai-insights.vue';
 import AlertPanel from './modules/alert-panel.vue';
 import BizCards from './modules/biz-cards.vue';
+import HrStockCards from './modules/hr-stock-cards.vue';
 import KpiCards from './modules/kpi-cards.vue';
 import ProductionTrend from './modules/production-trend.vue';
 import QuickActions from './modules/quick-actions.vue';
@@ -58,7 +59,7 @@
 <template>
   <Page auto-content-height>
     <!-- 娆㈣繋鏍� -->
-    <div class="glass-card mb-6 flex items-center justify-between rounded-2xl p-6">
+    <div class="glass-card mb-6 flex flex-col gap-3 rounded-2xl p-5 sm:flex-row sm:items-center sm:justify-between sm: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 }}锛屾杩庡洖鏉�
@@ -82,6 +83,9 @@
     <!-- ERP/WMS/BPM 缁忚惀 KPI -->
     <BizCards @navigate="handleNavigate" />
 
+    <!-- 鍑哄嫟鎸囨爣 + 搴撳瓨閲囪喘 -->
+    <HrStockCards class="mb-4 block" @navigate="handleNavigate" />
+
     <!-- AI 鏅鸿兘鍒嗘瀽 -->
     <AiInsights
       v-if="canViewHome && canNavigate('MesProWorkOrder') && isAiEnable()"
@@ -91,7 +95,7 @@
 
     <!-- 鐢熶骇瓒嬪娍 + 棰勮闈㈡澘 -->
     <Row v-if="canViewHome" :gutter="16" class="mb-4">
-      <Col :lg="14" :md="24" :sm="24" :xl="14" :xs="24" class="mb-4">
+      <Col :xs="24" :sm="24" :md="24" :lg="14" :xl="14" :xxl="14" 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澶╋級
@@ -99,7 +103,7 @@
           <ProductionTrend />
         </div>
       </Col>
-      <Col :lg="10" :md="24" :sm="24" :xl="10" :xs="24" class="mb-4">
+      <Col :xs="24" :sm="24" :md="24" :lg="10" :xl="10" :xxl="10" class="mb-4">
         <AlertPanel
           :repair-active-count="summary.repairActiveCount"
           @navigate="handleNavigate"
diff --git a/src/views/dashboard/analytics/modules/biz-cards.vue b/src/views/dashboard/analytics/modules/biz-cards.vue
index 5fc8ff1..cbd5d09 100644
--- a/src/views/dashboard/analytics/modules/biz-cards.vue
+++ b/src/views/dashboard/analytics/modules/biz-cards.vue
@@ -96,7 +96,7 @@
 <template>
   <Row v-if="canViewPurchase || canViewSale || canViewStock || canViewBpmTodo" :gutter="16">
     <!-- 閲囪喘璁㈠崟 -->
-    <Col v-if="canViewPurchase" :lg="6" :md="12" :sm="12" :xl="6" :xs="24" class="mb-4">
+    <Col v-if="canViewPurchase" :xs="24" :sm="12" :md="12" :lg="6" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group cursor-pointer overflow-hidden rounded-2xl border-0"
         :style="tiltStyle('purchase')"
@@ -123,7 +123,7 @@
     </Col>
 
     <!-- 閿�鍞鍗� -->
-    <Col v-if="canViewSale" :lg="6" :md="12" :sm="12" :xl="6" :xs="24" class="mb-4">
+    <Col v-if="canViewSale" :xs="24" :sm="12" :md="12" :lg="6" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group cursor-pointer overflow-hidden rounded-2xl border-0"
         :style="tiltStyle('sale')"
@@ -150,7 +150,7 @@
     </Col>
 
     <!-- 鐗╂枡搴撳瓨 -->
-    <Col v-if="canViewStock" :lg="6" :md="12" :sm="12" :xl="6" :xs="24" class="mb-4">
+    <Col v-if="canViewStock" :xs="24" :sm="12" :md="12" :lg="6" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group cursor-pointer overflow-hidden rounded-2xl border-0"
         :style="tiltStyle('stock')"
@@ -177,7 +177,7 @@
     </Col>
 
     <!-- BPM 寰呭姙 -->
-    <Col v-if="canViewBpmTodo" :lg="6" :md="12" :sm="12" :xl="6" :xs="24" class="mb-4">
+    <Col v-if="canViewBpmTodo" :xs="24" :sm="12" :md="12" :lg="6" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group cursor-pointer overflow-hidden rounded-2xl border-0"
         :style="tiltStyle('bpm')"
diff --git a/src/views/dashboard/analytics/modules/hr-stock-cards.vue b/src/views/dashboard/analytics/modules/hr-stock-cards.vue
new file mode 100644
index 0000000..c96f4d0
--- /dev/null
+++ b/src/views/dashboard/analytics/modules/hr-stock-cards.vue
@@ -0,0 +1,243 @@
+<script lang="ts" setup>
+import { computed, onMounted, ref } from 'vue';
+
+import { CountTo } from '@vben/common-ui';
+import { IconifyIcon } from '@vben/icons';
+
+import { Col, Progress, Row, Tooltip } from 'ant-design-vue';
+
+import { getAttendanceSummaryPage } from '#/api/hrm/attendance/summary';
+import { getMaterialStockPage } from '#/api/mes/wm/materialstock';
+import { getPurchaseOrderPage } from '#/api/erp/purchase/order';
+
+import { useHomeAccess } from '../use-home-access';
+
+defineOptions({ name: 'DashboardHrStockCards' });
+
+const emit = defineEmits<{ navigate: [name: string] }>();
+
+const { canNavigate, canQuery } = useHomeAccess();
+const canViewHr = computed(() => canQuery('hrm:attendance-summary:query') || canQuery('hrm:attendance-record:query'));
+const canViewStock = computed(() => canQuery('mes:wm-material-stock:query') && canNavigate('MesWmMaterialStock'));
+const canViewPurchase = computed(() => canQuery('erp:purchase-order:query') && canNavigate('ErpPurchaseOrder'));
+
+// ========== 鍑哄嫟鎸囨爣 ==========
+const hrLoading = ref(false);
+const headCount = ref(0);
+const actualDaysAvg = ref(0);
+const attendanceRate = ref(0);
+const lateCount = ref(0);
+const absentCount = ref(0);
+const leaveHours = ref(0);
+
+function currentYearMonth() {
+  const d = new Date();
+  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
+}
+
+async function loadAttendance() {
+  if (!canViewHr.value) return;
+  hrLoading.value = true;
+  try {
+    const res = await getAttendanceSummaryPage({
+      pageNo: 1,
+      pageSize: 500,
+      yearMonth: currentYearMonth(),
+    } as any);
+    const list = res?.list ?? [];
+    headCount.value = res?.total ?? list.length;
+    if (list.length > 0) {
+      let workSum = 0, actualSum = 0, late = 0, absent = 0, leave = 0;
+      for (const r of list) {
+        workSum += Number(r.workDays ?? 0);
+        actualSum += Number(r.actualDays ?? 0);
+        late += Number(r.lateCount ?? 0);
+        absent += Number(r.absentCount ?? 0);
+        leave += Number(r.leaveHours ?? 0);
+      }
+      actualDaysAvg.value = workSum > 0 ? Number((actualSum / list.length).toFixed(1)) : 0;
+      attendanceRate.value = workSum > 0 ? Math.min(100, Math.round((actualSum / workSum) * 100)) : 0;
+      lateCount.value = late;
+      absentCount.value = absent;
+      leaveHours.value = Number(leave.toFixed(1));
+    }
+  } catch { /* 蹇界暐 */ } finally { hrLoading.value = false; }
+}
+
+// ========== 搴撳瓨閲囪喘 ==========
+const stockLoading = ref(false);
+const stockKinds = ref(0);
+const stockAvailable = ref(0);
+const purchaseCount = ref(0);
+const purchasePending = ref(0);
+
+async function loadStock() {
+  if (!canViewStock.value) return;
+  stockLoading.value = true;
+  try {
+    const res = await getMaterialStockPage({ pageNo: 1, pageSize: 500 } as any);
+    const list = res?.list ?? [];
+    stockKinds.value = res?.total ?? list.length;
+    stockAvailable.value = Number(list.reduce((s: number, r: any) => s + Number(r.availableQuantity ?? 0), 0).toFixed(0));
+  } catch { /* 蹇界暐 */ } finally { stockLoading.value = false; }
+}
+
+async function loadPurchase() {
+  if (!canViewPurchase.value) return;
+  try {
+    const res = await getPurchaseOrderPage({ pageNo: 1, pageSize: 1 } as any);
+    purchaseCount.value = res?.total ?? 0;
+    // 寰呭鎵规暟閲忥紙鐘舵�� 10 = 瀹℃壒涓紝鎸� yudao ERP 绾﹀畾锛�
+    const pending = await getPurchaseOrderPage({ pageNo: 1, pageSize: 1, status: 10 } as any);
+    purchasePending.value = pending?.total ?? 0;
+  } catch { /* 蹇界暐 */ }
+}
+
+function goto(name: string) {
+  if (canNavigate(name)) emit('navigate', name);
+}
+
+onMounted(() => {
+  loadAttendance();
+  loadStock();
+  loadPurchase();
+});
+</script>
+
+<template>
+  <Row :gutter="[16, 16]">
+    <!-- ============ 鍑哄嫟鎸囨爣 ============ -->
+    <Col v-if="canViewHr" :xs="24" :sm="24" :md="24" :lg="12" :xl="12" :xxl="12">
+      <div class="glass-card h-full overflow-hidden rounded-2xl p-5">
+        <div class="mb-4 flex items-center justify-between">
+          <div class="flex items-center gap-2">
+            <div class="flex size-9 items-center justify-center rounded-lg bg-gradient-to-br from-violet-500 to-purple-400 shadow-md shadow-violet-500/25">
+              <IconifyIcon class="size-5 text-white" icon="lucide:user-check" />
+            </div>
+            <div>
+              <h3 class="text-base font-semibold text-gray-800 dark:text-gray-100">鍑哄嫟鎸囨爣</h3>
+              <p class="text-xs text-gray-400">鏈湀鑰冨嫟姹囨��</p>
+            </div>
+          </div>
+          <a-spin v-if="hrLoading" :size="16" />
+        </div>
+
+        <div class="mb-4 flex items-center gap-5">
+          <Progress
+            type="circle"
+            :percent="attendanceRate"
+            :size="88"
+            :stroke-color="{ '0%': '#8b5cf6', '100%': '#c084fc' }"
+          />
+          <div class="min-w-0 flex-1">
+            <div class="text-xs text-gray-500 dark:text-gray-400">鍑哄嫟鐜�</div>
+            <div class="mt-1 text-sm text-gray-600 dark:text-gray-300">
+              鍦ㄥ唽 <span class="font-semibold text-violet-600 dark:text-violet-400">{{ headCount }}</span> 浜�
+              路 浜哄潎鍑哄嫟 <span class="font-semibold text-violet-600 dark:text-violet-400">{{ actualDaysAvg }}</span> 澶�
+            </div>
+          </div>
+        </div>
+
+        <div class="grid grid-cols-2 gap-3 sm:grid-cols-4">
+          <Tooltip title="鏈湀杩熷埌娆℃暟鍚堣">
+            <div class="rounded-xl bg-amber-50/70 p-3 text-center dark:bg-amber-500/10">
+              <div class="text-lg font-bold text-amber-600 dark:text-amber-400">
+                <CountTo :end-val="lateCount" :duration="1000" />
+              </div>
+              <div class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">杩熷埌</div>
+            </div>
+          </Tooltip>
+          <Tooltip title="鏈湀缂哄崱娆℃暟鍚堣">
+            <div class="rounded-xl bg-rose-50/70 p-3 text-center dark:bg-rose-500/10">
+              <div class="text-lg font-bold text-rose-600 dark:text-rose-400">
+                <CountTo :end-val="absentCount" :duration="1000" />
+              </div>
+              <div class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">缂哄崱</div>
+            </div>
+          </Tooltip>
+          <Tooltip title="鏈湀璇峰亣宸ユ椂鍚堣">
+            <div class="rounded-xl bg-sky-50/70 p-3 text-center dark:bg-sky-500/10">
+              <div class="text-lg font-bold text-sky-600 dark:text-sky-400">
+                <CountTo :end-val="leaveHours" :duration="1000" :decimals="1" />
+              </div>
+              <div class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">璇峰亣(h)</div>
+            </div>
+          </Tooltip>
+          <Tooltip title="浜哄潎鍑哄嫟澶╂暟">
+            <div class="rounded-xl bg-emerald-50/70 p-3 text-center dark:bg-emerald-500/10">
+              <div class="text-lg font-bold text-emerald-600 dark:text-emerald-400">
+                <CountTo :end-val="actualDaysAvg" :duration="1000" :decimals="1" />
+              </div>
+              <div class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">鍑哄嫟(澶�)</div>
+            </div>
+          </Tooltip>
+        </div>
+      </div>
+    </Col>
+
+    <!-- ============ 搴撳瓨閲囪喘 ============ -->
+    <Col v-if="canViewStock || canViewPurchase" :xs="24" :sm="24" :md="24" :lg="12" :xl="12" :xxl="12">
+      <div class="glass-card h-full overflow-hidden rounded-2xl p-5">
+        <div class="mb-4 flex items-center justify-between">
+          <div class="flex items-center gap-2">
+            <div class="flex size-9 items-center justify-center rounded-lg bg-gradient-to-br from-cyan-500 to-teal-400 shadow-md shadow-cyan-500/25">
+              <IconifyIcon class="size-5 text-white" icon="lucide:package" />
+            </div>
+            <div>
+              <h3 class="text-base font-semibold text-gray-800 dark:text-gray-100">搴撳瓨閲囪喘</h3>
+              <p class="text-xs text-gray-400">浠撳偍涓庨噰璐瑙�</p>
+            </div>
+          </div>
+          <a-spin v-if="stockLoading" :size="16" />
+        </div>
+
+        <Row :gutter="[12, 12]">
+          <Col v-if="canViewStock" :xs="12" :sm="12" :md="12" :lg="12" :xl="12" class="cursor-pointer" @click="goto('MesWmMaterialStock')">
+            <div class="rounded-xl bg-cyan-50/70 p-4 transition hover:bg-cyan-100/70 dark:bg-cyan-500/10">
+              <div class="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
+                <IconifyIcon class="size-4 text-cyan-500" icon="lucide:boxes" /> 搴撳瓨鍝佺
+              </div>
+              <div class="mt-1 text-2xl font-bold text-cyan-600 dark:text-cyan-400">
+                <CountTo :end-val="stockKinds" :duration="1000" />
+              </div>
+              <div class="text-xs text-gray-400">绱鍦ㄥ簱鐗╂枡琛�</div>
+            </div>
+          </Col>
+          <Col v-if="canViewStock" :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
+            <div class="rounded-xl bg-teal-50/70 p-4 dark:bg-teal-500/10">
+              <div class="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
+                <IconifyIcon class="size-4 text-teal-500" icon="lucide:warehouse" /> 鍙敤鏁伴噺
+              </div>
+              <div class="mt-1 text-2xl font-bold text-teal-600 dark:text-teal-400">
+                <CountTo :end-val="stockAvailable" :duration="1000" />
+              </div>
+              <div class="text-xs text-gray-400">鎵i櫎鍐荤粨涓庡崰鐢�</div>
+            </div>
+          </Col>
+          <Col v-if="canViewPurchase" :xs="12" :sm="12" :md="12" :lg="12" :xl="12" class="cursor-pointer" @click="goto('ErpPurchaseOrder')">
+            <div class="rounded-xl bg-indigo-50/70 p-4 transition hover:bg-indigo-100/70 dark:bg-indigo-500/10">
+              <div class="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
+                <IconifyIcon class="size-4 text-indigo-500" icon="lucide:shopping-cart" /> 閲囪喘璁㈠崟
+              </div>
+              <div class="mt-1 text-2xl font-bold text-indigo-600 dark:text-indigo-400">
+                <CountTo :end-val="purchaseCount" :duration="1000" />
+              </div>
+              <div class="text-xs text-gray-400">绱璁㈠崟绗旀暟</div>
+            </div>
+          </Col>
+          <Col v-if="canViewPurchase" :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
+            <div class="rounded-xl bg-orange-50/70 p-4 dark:bg-orange-500/10">
+              <div class="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
+                <IconifyIcon class="size-4 text-orange-500" icon="lucide:clock" /> 寰呭鎵�
+              </div>
+              <div class="mt-1 text-2xl font-bold text-orange-600 dark:text-orange-400">
+                <CountTo :end-val="purchasePending" :duration="1000" />
+              </div>
+              <div class="text-xs text-gray-400">瀹℃壒涓殑閲囪喘鍗�</div>
+            </div>
+          </Col>
+        </Row>
+      </div>
+    </Col>
+  </Row>
+</template>
diff --git a/src/views/dashboard/analytics/modules/kpi-cards.vue b/src/views/dashboard/analytics/modules/kpi-cards.vue
index 055f8f6..5e18646 100644
--- a/src/views/dashboard/analytics/modules/kpi-cards.vue
+++ b/src/views/dashboard/analytics/modules/kpi-cards.vue
@@ -111,7 +111,7 @@
 <template>
   <Row :gutter="16">
     <!-- 鐢熶骇璁㈠崟 -->
-    <Col :lg="6" :md="12" :sm="12" :xl="4" :xs="24" class="mb-4">
+    <Col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group h-full overflow-hidden rounded-2xl border-0"
         :class="{ 'cursor-pointer': canNavigate('MesProWorkOrder') }"
@@ -143,7 +143,7 @@
     </Col>
 
     <!-- 浠婃棩浜ч噺 -->
-    <Col :lg="6" :md="12" :sm="12" :xl="4" :xs="24" class="mb-4">
+    <Col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group h-full overflow-hidden rounded-2xl border-0"
         :class="{ 'cursor-pointer': canNavigate('MesProFeedback') }"
@@ -225,7 +225,7 @@
     </Col>
 
     <!-- 璁惧杩愯鐜� -->
-    <Col :lg="6" :md="12" :sm="12" :xl="4" :xs="24" class="mb-4">
+    <Col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" :xxl="6" class="mb-4">
       <div
         class="glass-tilt group h-full overflow-hidden rounded-2xl border-0"
         :class="{ 'cursor-pointer': canNavigate('MesDvMachinery') }"
diff --git a/src/views/dashboard/analytics/modules/quick-actions.vue b/src/views/dashboard/analytics/modules/quick-actions.vue
index d7cc976..dc056a1 100644
--- a/src/views/dashboard/analytics/modules/quick-actions.vue
+++ b/src/views/dashboard/analytics/modules/quick-actions.vue
@@ -37,7 +37,7 @@
 <template>
   <div v-if="accessibleActions.length" class="glass-card rounded-2xl p-5">
     <h3 class="mb-4 text-sm font-semibold text-gray-800 dark:text-gray-100">蹇嵎鎿嶄綔</h3>
-    <div class="grid grid-cols-4 gap-3 sm:grid-cols-8">
+    <div class="grid grid-cols-3 gap-2 sm:grid-cols-4 sm:gap-3 md:grid-cols-6 lg:grid-cols-8">
       <div
         v-for="action in accessibleActions"
         :key="action.route"
@@ -45,7 +45,7 @@
         @click="emit('navigate', action.route)"
       >
         <div
-          class="flex size-10 items-center justify-center rounded-xl bg-gradient-to-br transition-shadow duration-300 group-hover:shadow-lg"
+          class="flex size-9 items-center justify-center rounded-xl bg-gradient-to-br transition-shadow duration-300 group-hover:shadow-lg sm:size-10"
           :class="[action.gradient, action.shadow]"
         >
           <IconifyIcon :icon="action.icon" class="size-5 text-white" />

--
Gitblit v1.9.3