zs
2025-04-28 1f32ea02c1910c417f159cba81a296e66ae7484c
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
<template>
  <el-menu
    :default-active="defaultActive"
    class="cs-menu-vertical-demo"
    :collapse="isCollapse"
    active-text-color="#fff"
    background-color="#545c64"
    text-color="#fff"
    @select="handleSelected"
    @open="handleOpen"
    @close="handleClose"
  >
    <el-menu-item v-for="item in routes" :index="item.path">
      <div class="menu-li">
        <div class="icon">
          <img
            width="16"
            v-if="!item.icon.includes('icon-')"
            :src="
              item.icon.includes('icon-')
                ? item.icon
                : `../../../src/assets/svg/${item.icon}.svg`
            "
          />
          <i
            v-else-if="item.icon"
            :class="{
              iconfont: true,
              [item.icon]: true,
            }"
          ></i>
          <el-icon v-else><document /></el-icon>
        </div>
        {{ item.name }}
      </div>
    </el-menu-item>
  </el-menu>
</template>
 
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { Document, Menu as IconMenu } from '@element-plus/icons-vue'
import { routeInfo } from '@/router'
import { useRouter } from 'vue-router'
 
const router = useRouter()
 
const routes = computed(() => {
  return routeInfo.routes || []
})
const isCollapse = ref(true)
 
const defaultActive = computed(() => {
  return location.hash.split('#')[1]
})
 
const handleSelected = (index: string) => {
  router.push(index)
}
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>
 
<style lang="scss" scoped>
.cs-menu-vertical-demo {
  position: relative;
  width: 201px;
  height: 100%;
  background-color: #000000 !important;
  overflow-y: auto;
  // overflow-x: inherit;
 
  :deep(.is-active) {
    background-color: #292929;
    border-right: 5px solid #5a84ff;
  }
  :deep(.cs-menu-item) {
    &:hover {
      background-color: #292929;
    }
  }
}
 
.menu-li {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .icon {
    margin-right: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>