| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <template>
- <el-aside class="siderbar_container" :width="isCollapse ? '72px' : '190px'">
- <!-- <div @click="toggleCollapse" class="collapse_box">
- <img v-if="isCollapse" src="@/assets/icon/open.svg" alt="">
- <img v-else src="@/assets/icon/close.svg" alt="">
- </div> -->
- <el-menu :key="activeRoute" :collapse="isCollapse" router>
- <el-menu-item
- v-for="item in props.menuItems"
- :key="item.route"
- :index="item.route"
- :class="activeRoute == item.route ? 'is-active' : ''"
- >
- <template #default>
- <i v-if="item.icon" class="iconfont" :class="item.icon"></i>
- <component v-if="item.svgIcon" class="img_icon" :is="item.svgIcon" :style="{'--nav-color':item.route == activeRoute ? 'white' : ''}"></component>
- <img v-else-if="item.img" class="img_icon" :src="item.route == activeRoute ? item.imgLight : item.img" alt="">
- <span v-if="!isCollapse" style="position: relative;" >
- {{ item.title }}
- <span v-if="item.bubble && item.bubble !== 0" class="bubble">{{item.bubble}} </span>
- </span>
- </template>
- <template #title>
- <span v-if="isCollapse">{{ item.title }}</span>
- </template>
- </el-menu-item>
- </el-menu>
- </el-aside>
- </template>
- <script lang="ts">
- export default {
- name: 'SiderBar'
- }
- </script>
- <script lang="ts" setup>
- import { ref, watch, onMounted } from 'vue';
- import { useRoute } from 'vue-router'
- import router from '@/router';
- const route = useRoute()
- const activeRoute = ref(route.path)
- watch(() => route.path, (newVal) => {
- console.log('当前路由---',newVal)
- activeRoute.value = newVal
- })
- const isCollapse = ref(false)
- interface menuItem {
- title: string;
- icon: string;
- route: string;
- bubble:Number;
- img:String;
- imgLight:String;
- svgIcon:undefined;
- }
- const props = defineProps({
- menuItems:{
- required:true,
- type:Array<menuItem>
- }
- })
- const toggleCollapse = () => {
- isCollapse.value = !isCollapse.value
- }
- </script>
- <style lang="scss" scoped>
- .siderbar_container {
- // background: #fff;
- padding: 20px 0px 20px 20px;
- }
- .el-menu {
- width: 100%;
- border: none;
- border-radius: 10px;
- padding:10px 20px;
- }
- .el-menu-item {
- font-size: 16px;
- padding: 0;
- }
- .iconfont {
- margin-right: 5px;
- display: inline-block;
- color: #666666;
- font-size: 16px;
- }
- .img_icon{
- margin-right: 8px;
- width: 16px;
- height: 16px;
- }
- .collapse_box {
- padding-left: 10px;
- // text-align: center;
- }
- .el-menu.el-menu--vertical :deep(.el-menu-item) {
- height: 40px;
- margin: 10px 0;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 4px;
- .iconfont {
- margin-right: 8px;
- text-align: center;
- }
- }
- .el-menu--collapse .el-menu-item span {
- display: none;
- }
- .el-menu-item :deep(.el-menu-tooltip__trigger) {
- padding: 0 10px;
- }
- .el-menu-item {
- &.is-active,
- &.is-active:hover {
- font-weight: 600;
- background: #2E64FA;
- color: #fff;
- .iconfont {
- color: #fff;
- }
- }
- &:not(.is-active):hover {
- background: inherit;
- color: #2E64FA;
- .img_icon{
- --nav-color:#2E64FA;
- }
- .iconfont {
- color: #2E64FA;
- }
- }
- }
- .bubble{
- display: inline-block;
- position: absolute;
- top:10px;
- line-height: 20px;
- width: 20px;
- height: 20px;
- text-align: center;
- font-size: 12px;
- border-radius: 10px;
- background-color: #F56C6C;
- color: white;
- }
- </style>
|