ke_junjie
2025-06-04 bb6e2230bb8ded3c5546bc4e4c282ee343754475
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!--  -->
<template>
  <div>
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <div class="heard pointer" @click="homeclick">
        <img :class="{ isimg: isCollapse }" class="heard-img" src="../../../assets/heard/heard.jpg" alt="" />
      </div>
      <el-menu
        :default-active="activeMenu"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :unique-opened="true"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        :collapse="isCollapse"
        mode="vertical"
        router
      >
        <sidebar-item v-for="route in routes" :key="route.path" :itemRoute="route" />
      </el-menu>
    </el-scrollbar>
  </div>
</template>
 
<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
//例如:import 《组件名称》 from '《组件路径》';
import { mapGetters } from 'vuex';
import variables from '@/styles/variables.scss';
import { getStorage, setStorage } from '@/utils/sessionStorage';
import SidebarItem from './SidebarItem';
 
export default {
  //name放入模板名,方便在其他地方引用
  name: '',
  //import引入的组件需要注入到对象中才能使用
  components: { SidebarItem },
  data() {
    //这里存放数据
    return {};
  },
  //监听属性 类似于data概念
  computed: {
    ...mapGetters(['sidebar']),
    variables() {
      return variables;
    },
    routes() {
      let baseRoute = this.$store.state.permission.routes;
      if (baseRoute.length > 13) {
        return baseRoute[13].children;
      }
    },
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      console.log(route);
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
 
      return path;
    },
    // activeMenu() {
 
    //   return this.$route.matched[1].path;
    // },
    isCollapse() {
      return this.sidebar;
    }
  },
  //生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  //生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {},
  //方法集合
  methods: {
    //跳转首页
    homeclick() {
      // const { href } = this.$router.resolve({
      //   path: '/home'
      // });
      // window.open(href, '_blank');
    }
  },
  //监控data中的数据变化
  watch: {},
  //如果页面有keep-alive缓存功能,这个函数会触发
  activated() {}
};
</script>
<style lang="scss" scoped>
/* @import url(); 引入公共css类 */
.heard {
  text-align: center;
  padding: 20px 0px;
  background-color: #3a405a;
  border-bottom: 1px solid rgb(72, 94, 122);
  .heard-img {
    width: 60px;
    height: 60px;
    border-radius: 30px;
    transition: all 1s ease 0s;
  }
  .isimg {
    width: 24px;
    height: 24px;
    border-radius: 15px;
  }
}
</style>