From 074bcb8394fab66ce531c219e1e7de7c142ff2d5 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 29 五月 2026 11:07:10 +0800
Subject: [PATCH] 新增智能电表、空调管理
---
admin/src/components/common/Menu.vue | 50 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/admin/src/components/common/Menu.vue b/admin/src/components/common/Menu.vue
index 0b0df39..6690926 100644
--- a/admin/src/components/common/Menu.vue
+++ b/admin/src/components/common/Menu.vue
@@ -27,34 +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)
- }
- // console.log(menuConfig.index);
- 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