From 3da5de8ff26e22877a99c8cb45da7a123a0b37f0 Mon Sep 17 00:00:00 2001 From: zq <136432190602163.com> Date: Fri, 18 Jul 2025 17:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=83=E5=B1=80=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=A7=E8=BE=B9=E6=A0=8F=E9=AB=98=E4=BA=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SliderMenu.vue | 3 +- src/components/SliderScond.vue | 48 ++- src/store/index.js | 4 +- src/views/agent/siteServiceAdd.vue | 829 ++++++++++++++++++++----------------- 4 files changed, 488 insertions(+), 396 deletions(-) diff --git a/src/components/SliderMenu.vue b/src/components/SliderMenu.vue index 0238e96..5846a99 100644 --- a/src/components/SliderMenu.vue +++ b/src/components/SliderMenu.vue @@ -282,4 +282,5 @@ export default { // .el-menu--collapse .el-submenu.is-opened > .el-menu { // opacity: 0; // height: 0; -// } \ No newline at end of file +// } + \ No newline at end of file diff --git a/src/components/SliderScond.vue b/src/components/SliderScond.vue index 64e55a4..31bee37 100644 --- a/src/components/SliderScond.vue +++ b/src/components/SliderScond.vue @@ -77,11 +77,23 @@ export default { GuipToolTip }, watch: { - menuList(newVal) { - let subtitle = this.renderKeyNew.subtitle; - this.activeFloor = newVal[this.curIndex]?.list?.[0][subtitle]; - this.componentsName = newVal[this.curIndex]?.list?.[0]?.componentsName || ''; - store.commit('SET_CURRENTMENUITEM', newVal[this.curIndex]?.list?.[0]); + menuList:{ + handler(newVal, oldVal) { + // 初次加载或强制刷新时,oldVal为空 + if (!oldVal || oldVal.length === 0) { + this.setDefaultActive(newVal); + return; + } + console.log(newVal,'newVal==='); + // 检查当前高亮的菜单项是否仍然存在于新的menuList中 + const currentItemExists = this.checkCurrentItem(newVal); + console.log(currentItemExists,'currentItemExists--'); + // 不存在默认高亮第一项 + if (!currentItemExists) { + this.setDefaultActive(newVal); + } + }, + immediate: true } }, mounted() { @@ -105,6 +117,32 @@ export default { } }, methods: { + checkCurrentItem(newMenuList) { + const subtitle = this.renderKeyNew.subtitle; + // 如果当前没有高亮的菜单项,返回 + if (!this.activeFloor) return false; + // 遍历新的menuList,先检查高亮的菜单项是否存在 + for (const item of newMenuList) { + if (item.list) { + const found = item.list.some(subItem => + subItem[subtitle] === this.activeFloor || + subItem.componentsName === this.activeFloor + ); + if (found) return true; + } + } + return false; + }, + setDefaultActive(menuList) { + // 设置默认高亮项 + if (menuList && menuList.length > 0 && menuList[0].list && menuList[0].list.length > 0) { + const subtitle = this.renderKeyNew.subtitle; + this.activeFloor = menuList[0].list[0][subtitle] || menuList[0].list[0]?.componentsName || ''; + this.componentsName = menuList[0].list[0]?.componentsName || ''; + store.commit('SET_CURRENTMENUITEM', menuList[0].list[0]); + this.curIndex = 0; + } + }, handleChange(val) { console.log("面板状态变化:", val); }, diff --git a/src/store/index.js b/src/store/index.js index f789862..49ce5d0 100755 --- a/src/store/index.js +++ b/src/store/index.js @@ -567,7 +567,7 @@ export default new Vuex.Store({ }, mutations: { SET_CURRENTMENUITEM(state,data){ - state.currentMenuItem = JSON.parse(JSON.stringify(data)); + state.currentMenuItem = data && JSON.parse(JSON.stringify(data)); }, SET_COMPONENTS_NAME(state,name){ state.componentsName = name; @@ -576,7 +576,7 @@ export default new Vuex.Store({ state.slidermenu = state[type] }, SET_SECOND_MENU(state,data){ - state.secondMenu = JSON.parse(JSON.stringify(data)) + state.secondMenu = data && JSON.parse(JSON.stringify(data)) }, SET_CUSTOMIZE(state,show) { state.customize = show diff --git a/src/views/agent/siteServiceAdd.vue b/src/views/agent/siteServiceAdd.vue index 290ecbf..6de22ea 100644 --- a/src/views/agent/siteServiceAdd.vue +++ b/src/views/agent/siteServiceAdd.vue @@ -1,209 +1,238 @@ \ No newline at end of file