From 3c7399c25c0f35c8aa7cb6af1935e31d1a3f0102 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期二, 02 六月 2026 17:43:50 +0800
Subject: [PATCH] 新增智能电表、空调管理

---
 admin/src/components/common/Menu.vue |   49 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/admin/src/components/common/Menu.vue b/admin/src/components/common/Menu.vue
index 75a48d1..6690926 100644
--- a/admin/src/components/common/Menu.vue
+++ b/admin/src/components/common/Menu.vue
@@ -27,33 +27,50 @@
 import { mapState } from 'vuex'
 import MenuItems from './MenuItems'
 import Scrollbar from './Scrollbar'
+import { findMenuByUrl, getOpenMenuIndexes } from '@/utils/menu'
 export default {
   name: 'Menu',
   components: { Scrollbar, MenuItems },
   computed: {
     ...mapState(['menuData']),
     // 閫変腑鐨勮彍鍗昳ndex
-    activeIndex() {
-      let path = this.$route.path
-      if (path.endsWith('/')) {
-        path = path.substring(0, path.length - 1)
-      }
-      const menuConfig = this.__getMenuConfig(path, 'index', this.menuData.list)
-      if (menuConfig == null) {
-        return null
-      } else {
-        this.$store.commit('pushtags', menuConfig)
-      }
-      return menuConfig.index
+    activeIndex () {
+      const menuConfig = findMenuByUrl(this.$route.path, this.menuData.list)
+      return menuConfig ? menuConfig.index : null
     },
     // 榛樿灞曞紑鐨勮彍鍗昳ndex
-    defaultOpeneds() {
-      // return this.menuData.list.map(menu => menu.index)
-      
-      return [this.menuData.list[0].index]
+    defaultOpeneds () {
+      const openeds = getOpenMenuIndexes(this.$route.path, this.menuData.list)
+      if (openeds.length > 0) {
+        return openeds
+      }
+      return this.menuData.list.length > 0 ? [this.menuData.list[0].index] : []
+    }
+  },
+  watch: {
+    '$route': {
+      handler () {
+        this.syncMenuState()
+      },
+      immediate: true
     }
   },
   methods: {
+    syncMenuState () {
+      const menuConfig = findMenuByUrl(this.$route.path, this.menuData.list)
+      if (menuConfig) {
+        this.$store.commit('pushtags', menuConfig)
+      }
+      this.$nextTick(() => {
+        const menuRef = this.$refs.menu
+        if (!menuRef) {
+          return
+        }
+        getOpenMenuIndexes(this.$route.path, this.menuData.list).forEach(index => {
+          menuRef.open(index)
+        })
+      })
+    },
     // 澶勭悊鑿滃崟閫変腑
     handleSelect(menuIndex) {
       const menuConfig = this.__getMenuConfig(menuIndex, 'index', this.menuData.list)

--
Gitblit v1.9.3