From 72249d5b2535e01b8074eb0d1b3fe325e0163626 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 20 五月 2026 15:57:13 +0800
Subject: [PATCH] 进销存pro 1.首页展示模块根据权限展示

---
 src/views/index.vue |  161 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 138 insertions(+), 23 deletions(-)

diff --git a/src/views/index.vue b/src/views/index.vue
index 3b9182b..67c20c4 100644
--- a/src/views/index.vue
+++ b/src/views/index.vue
@@ -18,7 +18,7 @@
       </div>
     </section>
 
-    <section class="top-row">
+    <section v-if="dashboardCards.length > 0" class="top-row">
       <div class="stats-grid">
         <article
           v-for="card in dashboardCards"
@@ -48,9 +48,9 @@
       </div>
     </section>
 
-    <section class="main-grid">
-      <div class="left-column">
-        <div class="cockpit-panel process-panel">
+    <section v-if="hasVisiblePanels" class="main-grid">
+      <div v-if="hasLeftPanels" class="left-column">
+        <div v-if="visiblePanels.process" class="cockpit-panel process-panel">
           <div class="panel-title-row">
             <div class="panel-title">宸ュ簭鏁版嵁鐢熶骇缁熻鏄庣粏</div>
             <div class="panel-actions">
@@ -109,7 +109,7 @@
           </div>
         </div>
 
-        <div class="cockpit-panel order-panel">
+        <div v-if="visiblePanels.order" class="cockpit-panel order-panel">
           <div class="panel-title-row">
             <div class="panel-title">鐢熶骇璁㈠崟杩涘害</div>
             <el-radio-group v-model="orderFilter" size="small">
@@ -148,7 +148,7 @@
           </el-table>
         </div>
 
-        <div class="cockpit-panel contract-panel">
+        <div v-if="visiblePanels.contract" class="cockpit-panel contract-panel">
             <div class="panel-title">瀹㈡埛鍚堝悓閲戦鍒嗘瀽</div>
             <div class="contract-summary">
               <div class="contract-card">
@@ -181,7 +181,7 @@
             </ul>
           </div>
 
-        <div class="cockpit-panel quality-panel">
+        <div v-if="visiblePanels.quality" class="cockpit-panel quality-panel">
             <div class="panel-title-row">
               <div class="panel-title">璐ㄩ噺缁熻</div>
               <el-radio-group v-model="qualityRange" size="small" @change="qualityStatisticsInfo">
@@ -209,8 +209,8 @@
           </div>
       </div>
 
-      <div class="right-column">
-        <div class="cockpit-panel todo-panel">
+      <div v-if="hasRightPanels" class="right-column">
+        <div v-if="visiblePanels.todo" class="cockpit-panel todo-panel">
           <div class="panel-title-row">
             <div class="panel-title">寰呭姙浜嬮」</div>
             <span class="panel-more">鏇村</span>
@@ -228,7 +228,7 @@
           <div v-else class="panel-empty">鏆傛棤鏁版嵁</div>
         </div>
 
-        <div class="cockpit-panel realtime-panel">
+        <div v-if="visiblePanels.realtime" class="cockpit-panel realtime-panel">
           <div class="panel-title-row">
             <div class="panel-title">鐢熶骇瀹炴椂鐪嬫澘</div>
             <span class="panel-more">鏇村</span>
@@ -252,7 +252,7 @@
           </div>
         </div>
 
-        <div class="cockpit-panel quick-panel">
+        <div v-if="visiblePanels.quick" class="cockpit-panel quick-panel">
           <div class="panel-title-row">
             <div class="panel-title">蹇嵎鍔熻兘</div>
           </div>
@@ -274,7 +274,7 @@
           </div>
         </div>
 
-        <div class="cockpit-panel plan-panel">
+        <div v-if="visiblePanels.plan" class="cockpit-panel plan-panel">
           <div class="panel-title-row">
             <div class="panel-title">浠婃棩鐢熶骇璁″垝</div>
             <span class="panel-more">{{ todayPlanList.length }}椤�</span>
@@ -293,7 +293,7 @@
           </ul>
         </div>
 
-        <div class="cockpit-panel receipt-panel">
+        <div v-if="visiblePanels.receipt" class="cockpit-panel receipt-panel">
           <div class="panel-title">鍥炴涓庡紑绁ㄥ垎鏋�</div>
           <Echarts
             :options="chartBaseOptions"
@@ -309,6 +309,10 @@
         </div>
 
       </div>
+    </section>
+
+    <section v-else class="cockpit-panel empty-home-panel">
+      褰撳墠璐﹀彿娌℃湁鍙睍绀虹殑棣栭〉妯″潡
     </section>
 
     <el-dialog v-model="processDialogVisible" title="閫夋嫨宸ュ簭" width="500px" append-to-body>
@@ -757,6 +761,7 @@
     subValue: formatNumber(businessInfo.value.monthSaleHaveMoney),
     trend: `鍗犳瘮 ${ratioText(businessInfo.value.monthSaleHaveMoney, businessInfo.value.monthSaleMoney)}`,
     icon: DataLine,
+    visible: visibleModules.value.sales,
   },
   {
     key: "purchase",
@@ -770,6 +775,7 @@
       businessInfo.value.monthPurchaseMoney
     )}`,
     icon: ShoppingCartFull,
+    visible: visibleModules.value.procurement,
   },
   {
     key: "inventory",
@@ -780,6 +786,7 @@
     subValue: formatNumber(businessInfo.value.todayInventoryNum),
     trend: "搴撳瓨缁撴瀯鎸佺画浼樺寲",
     icon: Box,
+    visible: visibleModules.value.inventory,
   },
   {
     key: "production",
@@ -790,8 +797,9 @@
     subValue: formatNumber(processTotals.value.scrap),
     trend: `鑹巼 ${ratioText(processTotals.value.output, processTotals.value.input)}`,
     icon: Operation,
+    visible: visibleModules.value.production,
   },
-]);
+].filter((item) => item.visible));
 
 const productionOrders = ref([
   {
@@ -921,6 +929,12 @@
 ];
 
 const normalizeMenuTitle = (title) => String(title || "").replace(/\s+/g, "").trim();
+const normalizeRoutePath = (path) =>
+  String(path || "")
+    .trim()
+    .replace(/\/+/g, "/")
+    .replace(/\/$/, "")
+    .toLowerCase();
 
 const resolveRoutePath = (route, parentPath = "") => {
   const currentPath = String(route?.path || "").trim();
@@ -940,7 +954,7 @@
     if (title && fullPath && !String(route.redirect || "").includes("noRedirect")) {
       items.push({
         title: normalizeMenuTitle(title),
-        path: fullPath,
+        path: normalizeRoutePath(fullPath),
       });
     }
     if (Array.isArray(route.children) && route.children.length > 0) {
@@ -959,6 +973,86 @@
         : permissionStore.routes;
   return collectAccessibleRoutes(routePool || []);
 });
+
+const moduleAccessConfig = {
+  sales: {
+    titles: ["閿�鍞鐞�", "閿�鍞彴璐�"],
+    pathPrefixes: ["/salesmanagement"],
+  },
+  procurement: {
+    titles: ["閲囪喘绠$悊", "閲囪喘鍙拌处"],
+    pathPrefixes: ["/procurementmanagement"],
+  },
+  inventory: {
+    titles: ["搴撳瓨绠$悊"],
+    pathPrefixes: ["/inventorymanagement"],
+  },
+  production: {
+    titles: ["鐢熶骇绠$悊", "涓荤敓浜ц鍒�", "鐢熶骇璁㈠崟", "鐢熶骇鎶ュ伐"],
+    pathPrefixes: ["/productionmanagement", "/productionplan"],
+  },
+  quality: {
+    titles: ["璐ㄩ噺绠$悊"],
+    pathPrefixes: ["/qualitymanagement"],
+  },
+  equipment: {
+    titles: ["璁惧绠$悊", "璁惧鍙拌处"],
+    pathPrefixes: ["/equipmentmanagement"],
+  },
+  personnel: {
+    titles: ["浜轰簨绠$悊", "鍛樺伐鍙拌处", "鍦ㄨ亴鍛樺伐鍙拌处"],
+    pathPrefixes: ["/personnelmanagement"],
+  },
+  approval: {
+    titles: ["鍗忓悓瀹℃壒", "寰呭姙浜嬮」"],
+    pathPrefixes: ["/collaborativeapproval"],
+  },
+  finance: {
+    titles: ["璐㈠姟绠$悊", "璐㈠姟鍒嗘瀽", "鍥炴绠$悊", "寮�绁ㄧ鐞�"],
+    pathPrefixes: ["/financesuite", "/financialmanagement"],
+  },
+};
+
+const hasModuleAccess = (config) =>
+  accessibleMenuRoutes.value.some((route) => {
+    const matchedTitle = (config.titles || []).some((title) => route.title === normalizeMenuTitle(title));
+    const matchedPath = (config.pathPrefixes || []).some(
+      (prefix) => route.path === prefix || route.path.startsWith(`${prefix}/`)
+    );
+    return matchedTitle || matchedPath;
+  });
+
+const visibleModules = computed(() => ({
+  sales: hasModuleAccess(moduleAccessConfig.sales),
+  procurement: hasModuleAccess(moduleAccessConfig.procurement),
+  inventory: hasModuleAccess(moduleAccessConfig.inventory),
+  production: hasModuleAccess(moduleAccessConfig.production),
+  quality: hasModuleAccess(moduleAccessConfig.quality),
+  equipment: hasModuleAccess(moduleAccessConfig.equipment),
+  personnel: hasModuleAccess(moduleAccessConfig.personnel),
+  approval: hasModuleAccess(moduleAccessConfig.approval),
+  finance: hasModuleAccess(moduleAccessConfig.finance),
+}));
+
+const visiblePanels = computed(() => ({
+  process: visibleModules.value.production,
+  order: visibleModules.value.production,
+  contract: visibleModules.value.sales,
+  quality: visibleModules.value.quality,
+  todo: visibleModules.value.approval,
+  realtime: visibleModules.value.production,
+  quick: quickEntries.value.length > 0,
+  plan: visibleModules.value.production,
+  receipt: visibleModules.value.sales || visibleModules.value.finance,
+}));
+
+const hasLeftPanels = computed(
+  () => visiblePanels.value.process || visiblePanels.value.order || visiblePanels.value.contract || visiblePanels.value.quality
+);
+const hasRightPanels = computed(
+  () => visiblePanels.value.todo || visiblePanels.value.realtime || visiblePanels.value.quick || visiblePanels.value.plan || visiblePanels.value.receipt
+);
+const hasVisiblePanels = computed(() => hasLeftPanels.value || hasRightPanels.value);
 
 const quickEntries = computed(() =>
   quickEntryConfigs
@@ -1147,14 +1241,26 @@
 onMounted(() => {
   updateNowTime();
   clockTimer = setInterval(updateNowTime, 1000);
-  getBusinessData();
-  analysisCustomer();
-  todoInfoS();
-  statisticsReceivable();
-  qualityStatisticsInfo();
-  getAmountHalfYearNum();
-  getProcessList();
-  refreshProcessStats();
+  if (dashboardCards.value.length > 0) {
+    getBusinessData();
+  }
+  if (visiblePanels.value.contract) {
+    analysisCustomer();
+  }
+  if (visiblePanels.value.todo) {
+    todoInfoS();
+  }
+  if (visiblePanels.value.quality) {
+    qualityStatisticsInfo();
+  }
+  if (visiblePanels.value.receipt) {
+    statisticsReceivable();
+    getAmountHalfYearNum();
+  }
+  if (visiblePanels.value.process) {
+    getProcessList();
+    refreshProcessStats();
+  }
 });
 
 onUnmounted(() => {
@@ -1503,6 +1609,15 @@
   color: var(--text-tertiary);
 }
 
+.empty-home-panel {
+  min-height: 220px;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  color: #64748b;
+  font-size: 14px;
+}
+
 .main-grid {
   display: grid;
   grid-template-columns: minmax(0, 1fr) 400px;

--
Gitblit v1.9.3