<script setup lang="ts">
import { computed } from 'vue';
import { openMenuTab } from '../../../utils/menuTab';
import { useMenuStore, type TreeMenuItem } from '../../../stores/menu';
import { renderMenuTitle } from 'cube-front/core/utils/menuHelpers';
import TextOverflow from '../../../components/TextOverflow.vue';
const menuStore = useMenuStore();
const parentMenu = computed(() => {
return menuStore.activeMenu?.parentMenu;
});
/** 点击菜单处理 */
const handleMenuClick = (menu: TreeMenuItem) => {
openMenuTab({
url: menu.path,
title: menu.name,
});
menuStore.setActiveMenu(menu);
};
function isMenuActive(menu: TreeMenuItem) {
return menu.path === menuStore.activeMenu?.path;
}
</script>
<template>
<div class="sider">
<!-- 菜单容器 -->
<div class="menuContainer">
<!-- 一级菜单名,带图标 -->
<div class="title">
<!-- <Icon v-if="parentMenu?.icon" :type="parentMenu.icon" /> -->
<span>{{ parentMenu?.title }}</span>
</div>
<!-- 二级菜单名 -->
<div
v-for="item in parentMenu?.children"
:key="item.name"
:class="['menuName', isMenuActive(item) && 'active']"
@click="() => handleMenuClick(item)"
>
<TextOverflow
:text="renderMenuTitle(item)"
tooltip-placement="right"
class="menu-title-text"
/>
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
.sider {
width: 100%;
height: 100%;
background-color: #e9f6fe;
.menuContainer {
height: 100%;
overflow-y: auto;
/* 完全隐藏滚动条 */
scrollbar-width: none;
-ms-overflow-style: none;
&::-webkit-scrollbar {
width: 0;
height: 0;
display: none;
}
/* 悬浮时可使用滚动,但保持滚动条隐藏 */
&:hover {
overflow-y: auto;
}
.title {
display: flex;
justify-content: center;
align-items: center;
font-weight: 600;
font-size: 14px;
color: #86909c;
margin-bottom: 16px;
span {
margin-left: 4px;
}
}
.menuName {
height: 32px;
font-weight: 600;
font-size: 14px;
// color: #1D2129;
color: #6d6f72;
line-height: 20px;
margin: 0 8px 4px 8px;
padding: 6px 0 6px 20px;
text-align: left;
user-select: none;
cursor: pointer;
.menu-title-text {
/* 继承菜单项样式 */
width: 100%;
}
&:hover {
color: #007fff;
}
}
.active {
background: rgba(255, 255, 255, 0.7);
border-radius: 8px;
color: #007fff;
box-shadow: 0px 2px 8px 0px rgba(92, 173, 255, 0.1);
}
}
}
</style>
|