2024-10-23 09:55:22 +00:00
|
|
|
|
<template>
|
2025-03-06 00:50:58 +00:00
|
|
|
|
<el-aside :width="sideWidth + 'px'" style="max-height: 200vh; min-height: 100vh; position: sticky; bottom: 0; left: 0; height: auto; background-color: rgb(170, 113, 81); box-shadow: rgba(0, 21, 155, 0.35) 2px 0 6px" >
|
2024-10-23 09:55:22 +00:00
|
|
|
|
<el-aside :style="AsideObj">
|
2025-03-03 12:50:33 +00:00
|
|
|
|
<el-menu
|
|
|
|
|
background-color="rgb(170, 113, 81)"
|
|
|
|
|
:collapse="isCollapse"
|
|
|
|
|
:collapse-transition="false"
|
|
|
|
|
text-color="#fff"
|
|
|
|
|
router
|
|
|
|
|
active-text-color="#ffd04b"
|
2025-03-04 00:00:00 +00:00
|
|
|
|
:default-openeds="['0']"
|
2025-03-06 00:50:58 +00:00
|
|
|
|
unique-opened
|
2025-03-03 12:50:33 +00:00
|
|
|
|
>
|
2025-03-06 00:50:58 +00:00
|
|
|
|
<div style="height: 80px; color: white; font-weight: bold;
|
|
|
|
|
display: flex; align-items: center; justify-content: center">
|
|
|
|
|
<img src="https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FypVcAOGV-Snipaste_2024-10-11_15-03-12.png" alt="" style="height: 30px">
|
|
|
|
|
<span style="margin-left: 5px" v-show="isShow">泠泷水月阁管理系统</span>
|
|
|
|
|
</div>
|
2025-03-03 12:50:33 +00:00
|
|
|
|
<!-- 遍历 menuRoutes,动态渲染菜单项 -->
|
|
|
|
|
<template v-for="(item, index) in menuRoutes">
|
|
|
|
|
<!-- 如果有子路由,使用 el-sub-menu -->
|
|
|
|
|
<el-sub-menu
|
|
|
|
|
v-if="item.children && item.children.length"
|
|
|
|
|
:key="index"
|
|
|
|
|
:index="index + ''"
|
|
|
|
|
>
|
|
|
|
|
<template #title>
|
|
|
|
|
<el-icon>
|
|
|
|
|
<component :is="iconComponents[item.meta.icon]"></component>
|
|
|
|
|
</el-icon>
|
|
|
|
|
<span>{{ item.meta.title }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
<!-- 二级菜单 -->
|
2025-03-06 00:50:58 +00:00
|
|
|
|
<template v-for="(item2, index2) in item.children" :key="index2">
|
|
|
|
|
<el-menu-item
|
|
|
|
|
v-if="!item2.meta?.hidden"
|
|
|
|
|
:index="item2.path"
|
|
|
|
|
:class="$route.path === item2.path ? 'is-active' : 'no-active'">
|
2025-03-03 12:50:33 +00:00
|
|
|
|
<template #title>
|
|
|
|
|
<el-icon>
|
|
|
|
|
<component
|
|
|
|
|
:is="iconComponents[item2.meta.icon]"
|
|
|
|
|
></component>
|
|
|
|
|
</el-icon>
|
|
|
|
|
{{ item2.meta.title }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-menu-item>
|
2025-03-06 00:50:58 +00:00
|
|
|
|
</template>
|
2025-03-03 12:50:33 +00:00
|
|
|
|
</el-sub-menu>
|
2025-03-06 00:50:58 +00:00
|
|
|
|
|
2025-03-03 12:50:33 +00:00
|
|
|
|
<!-- 如果没有子路由,使用 el-menu-item 代码备用,谨防路由被修改-->
|
|
|
|
|
<!-- <el-menu-item
|
|
|
|
|
v-else
|
|
|
|
|
:index="item.path"
|
|
|
|
|
:class="$route.path === item.path ? 'is-active' : ''"
|
|
|
|
|
>
|
|
|
|
|
<el-icon>
|
|
|
|
|
<component :is="iconComponents[item.meta.icon]"></component>
|
|
|
|
|
</el-icon>
|
|
|
|
|
<span>{{ item.meta.title }}</span>
|
|
|
|
|
</el-menu-item> -->
|
|
|
|
|
</template>
|
2024-10-23 09:55:22 +00:00
|
|
|
|
</el-menu>
|
|
|
|
|
</el-aside>
|
|
|
|
|
</el-aside>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-03-03 12:50:33 +00:00
|
|
|
|
<script setup >
|
|
|
|
|
import {ref ,computed } from 'vue'
|
2024-10-23 09:55:22 +00:00
|
|
|
|
import { defineProps } from 'vue';
|
|
|
|
|
import emitter from '@/utils/emitter'
|
2025-03-03 12:50:33 +00:00
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
import {
|
|
|
|
|
House,
|
|
|
|
|
User,
|
|
|
|
|
Location,
|
|
|
|
|
Histogram,
|
|
|
|
|
DataAnalysis,
|
|
|
|
|
Menu,
|
|
|
|
|
Switch,
|
|
|
|
|
Edit,
|
|
|
|
|
Camera,
|
|
|
|
|
Calendar,
|
|
|
|
|
Box,
|
|
|
|
|
Upload,
|
|
|
|
|
Postcard,
|
|
|
|
|
TakeawayBox,
|
|
|
|
|
Files,
|
|
|
|
|
DataBoard,
|
|
|
|
|
MessageBox,
|
|
|
|
|
Discount,
|
|
|
|
|
Notification,
|
|
|
|
|
Tickets,
|
|
|
|
|
Money
|
|
|
|
|
} from "@element-plus/icons-vue";
|
2024-10-23 09:55:22 +00:00
|
|
|
|
defineProps(['send-data'])
|
|
|
|
|
|
|
|
|
|
const showLog = ref(true)
|
|
|
|
|
const isCollapse = ref(false)
|
|
|
|
|
const isShow = ref(true)
|
2025-02-20 13:50:31 +00:00
|
|
|
|
const sideWidth = ref(250)
|
2024-10-23 09:55:22 +00:00
|
|
|
|
const AsideObj = ref({
|
2025-02-20 13:50:31 +00:00
|
|
|
|
width: '250px'
|
2024-10-23 09:55:22 +00:00
|
|
|
|
})
|
|
|
|
|
|
2025-03-03 12:50:33 +00:00
|
|
|
|
emitter.on('Aside', (value) => {
|
2024-10-23 09:55:22 +00:00
|
|
|
|
showLog.value = value
|
|
|
|
|
if(showLog.value){
|
|
|
|
|
AsideObj.value.width = '64px'
|
|
|
|
|
isCollapse.value = true
|
|
|
|
|
isShow.value = false
|
|
|
|
|
sideWidth.value = 64
|
|
|
|
|
}else{
|
2025-02-20 13:50:31 +00:00
|
|
|
|
AsideObj.value.width = '250px'
|
2024-10-23 09:55:22 +00:00
|
|
|
|
isCollapse.value = false
|
|
|
|
|
isShow.value = true
|
2025-02-20 13:50:31 +00:00
|
|
|
|
sideWidth.value = 250
|
2024-10-23 09:55:22 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-03 12:50:33 +00:00
|
|
|
|
//动态路由导航
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
console.log('router--->',router.options.routes);
|
|
|
|
|
|
|
|
|
|
// 创建图标映射表
|
|
|
|
|
const iconComponents = {
|
|
|
|
|
House,
|
|
|
|
|
User,
|
|
|
|
|
Location,
|
|
|
|
|
Histogram,
|
|
|
|
|
DataAnalysis,
|
|
|
|
|
Menu,
|
|
|
|
|
Switch,
|
|
|
|
|
Edit,
|
|
|
|
|
Camera,
|
|
|
|
|
Calendar,
|
|
|
|
|
Box,
|
|
|
|
|
Upload,
|
|
|
|
|
Postcard,
|
|
|
|
|
TakeawayBox,
|
|
|
|
|
Files,
|
|
|
|
|
DataBoard,
|
|
|
|
|
MessageBox,
|
|
|
|
|
Discount,
|
|
|
|
|
Notification,
|
|
|
|
|
Tickets,
|
|
|
|
|
Money
|
|
|
|
|
// 添加其他图标组件映射
|
|
|
|
|
};
|
|
|
|
|
// 过滤掉不需要展示的路由,并调整 layout 的子路由
|
|
|
|
|
const menuRoutes = computed(() => {
|
|
|
|
|
// 获取所有路由
|
|
|
|
|
const routes = router.options.routes;
|
|
|
|
|
// 过滤掉不需要展示的路由并展开 layout 子路由
|
|
|
|
|
const adjustedRoutes = routes.flatMap((route) => {
|
|
|
|
|
// 隐藏 'layout' 路由但展示其子路由作为一级路由
|
2025-03-04 00:00:00 +00:00
|
|
|
|
if (route.path === '/' && route.children) {
|
2025-03-03 12:50:33 +00:00
|
|
|
|
return route.children.map((child) => ({
|
|
|
|
|
...child,
|
|
|
|
|
path: child.path,
|
|
|
|
|
meta: child.meta,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// 如果路由设置为隐藏,则跳过
|
2025-03-04 00:00:00 +00:00
|
|
|
|
if (route.meta?.hidden ) {
|
|
|
|
|
console.log('11',route.children);
|
2025-03-03 12:50:33 +00:00
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return route;
|
|
|
|
|
});
|
|
|
|
|
console.log('adj--->',adjustedRoutes);
|
|
|
|
|
return adjustedRoutes;
|
|
|
|
|
});
|
|
|
|
|
console.log('menuRoutes--->',menuRoutes.value);
|
2024-10-23 09:55:22 +00:00
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<style scoped>
|
2025-03-03 12:50:33 +00:00
|
|
|
|
.is-active {
|
|
|
|
|
color: #ffd04b;
|
|
|
|
|
}
|
|
|
|
|
.no-active {
|
|
|
|
|
color: #ffffff;
|
|
|
|
|
}
|
2025-03-06 00:50:58 +00:00
|
|
|
|
.el-menu--horizontal {
|
|
|
|
|
--el-menu-horizontal-height: 2000px;
|
|
|
|
|
}
|
2024-10-23 09:55:22 +00:00
|
|
|
|
</style>
|