From bad2bc143be3f8ddb93a1c9f984127b3ccf43e8f Mon Sep 17 00:00:00 2001 From: lkk <364857242@qq.com> Date: 星期一, 31 三月 2025 17:47:14 +0800 Subject: [PATCH] 11 --- src/layout/components/Sidebar/index.vue | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index 1d23080..78374dd 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -2,9 +2,8 @@ <div :class="{'has-logo':showLogo}" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }"> <logo v-if="showLogo" :collapse="isCollapse" /> <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"> - <!-- :default-openeds="['/tijian']" --> + <!-- :default-openeds="['/tijian']" :default-openeds="defaultOpeneds" --> <el-menu - :default-active="activeMenu" :collapse="isCollapse" :background-color="settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground" @@ -19,6 +18,7 @@ :key="route.path + index" :item="route" :base-path="route.path" + :arrIndex="route.path" /> </el-menu> </el-scrollbar> @@ -26,6 +26,7 @@ </template> <script> +import { getRouters } from '@/api/menu' import { mapGetters, mapState } from "vuex"; import Logo from "./Logo"; import SidebarItem from "./SidebarItem"; @@ -33,18 +34,27 @@ export default { components: { SidebarItem, Logo }, + data() { + return { + defaultActive: [], + defaultOpeneds: [], + activeMenu: '', + }; + }, computed: { ...mapState(["settings"]), ...mapGetters(["sidebarRouters", "sidebar"]), - activeMenu() { - const route = this.$route; - const { meta, path } = route; - // if set path, the sidebar will highlight the path you set - if (meta.activeMenu) { - return meta.activeMenu; - } - return path; - }, + + // activeMenu() { + // const route = this.$route; + // const { meta, path } = route; + // console.log(meta,path) + // // if set path, the sidebar will highlight the path you set + // if (meta.activeMenu) { + // return meta.activeMenu; + // } + // return path; + // }, showLogo() { return this.$store.state.settings.sidebarLogo; }, @@ -54,6 +64,18 @@ isCollapse() { return !this.sidebar.opened; } - } + }, + created() { + this.route(); + }, + methods: { + route(){ + getRouters().then(res => { + this.defaultActive = res.data + // this.defaultOpeneds = [this.defaultActive[0].path,this.defaultActive[0].path+"/"+this.defaultActive[0].children[0].path] + this.activeMenu = this.defaultActive[0].path+"/"+this.defaultActive[0].children[0].path+"/"+this.defaultActive[0].children[0].children[0].path + }) + }, + }, }; </script> -- Gitblit v1.8.0