2020-12-31 11:47:52 +08:00
|
|
|
|
<template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<el-menu
|
|
|
|
|
router
|
2022-11-29 22:03:40 +08:00
|
|
|
|
:default-active="state.defaultActive"
|
2021-03-15 12:44:58 +08:00
|
|
|
|
background-color="transparent"
|
2022-11-29 22:03:40 +08:00
|
|
|
|
:collapse="state.isCollapse"
|
2021-03-15 12:44:58 +08:00
|
|
|
|
:unique-opened="getThemeConfig.isUniqueOpened"
|
|
|
|
|
:collapse-transition="false"
|
2024-12-26 19:12:44 +08:00
|
|
|
|
:default-openeds="defaultOpeneds"
|
2021-03-15 12:44:58 +08:00
|
|
|
|
>
|
2024-12-26 19:12:44 +08:00
|
|
|
|
<!-- <template v-for="val in menuLists">
|
2021-08-29 18:45:29 +08:00
|
|
|
|
<el-sub-menu :index="val.path" v-if="val.children && val.children.length > 0" :key="val.path">
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<template #title>
|
2021-12-04 13:32:14 +08:00
|
|
|
|
<SvgIcon :name="val.meta.icon" />
|
2021-04-01 11:13:38 +08:00
|
|
|
|
<span>{{ $t(val.meta.title) }}</span>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</template>
|
|
|
|
|
<SubItem :chil="val.children" />
|
2021-08-29 18:45:29 +08:00
|
|
|
|
</el-sub-menu>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<template v-else>
|
|
|
|
|
<el-menu-item :index="val.path" :key="val.path">
|
|
|
|
|
<SvgIcon :name="val.meta.icon" />
|
|
|
|
|
<template #title v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)">
|
|
|
|
|
<span>{{ $t(val.meta.title) }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
<template #title v-else>
|
2022-11-16 15:34:23 +08:00
|
|
|
|
<a class="w100" @click.prevent="onALinkClick(val)">{{ $t(val.meta.title) }}</a>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
</template>
|
2024-12-26 19:12:44 +08:00
|
|
|
|
</template> -->
|
|
|
|
|
|
|
|
|
|
<el-sub-menu :index="index.toString()" v-for="(item,index) in menuLists" :key="index" >
|
|
|
|
|
<template #title>
|
|
|
|
|
<span>{{ item.modulename }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
<el-menu-item-group>
|
|
|
|
|
<font-awesome-icon :icon="['fas',item.actions[0].icon]" size="lg" class="edtIcon" />
|
|
|
|
|
<el-menu-item :index="item1.link" v-for="(item1, index1) in item.actions" :key="index1">
|
|
|
|
|
<SvgIcon :name="item1.icon" />
|
|
|
|
|
{{ item1.actionname }}
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
</el-menu-item-group>
|
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-menu>
|
2020-12-31 11:47:52 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
2022-11-29 22:03:40 +08:00
|
|
|
|
<script setup lang="ts" name="navMenuVertical">
|
2024-12-26 19:12:44 +08:00
|
|
|
|
import { defineAsyncComponent, reactive, computed, onMounted, watch,ref ,onBeforeMount} from 'vue';
|
2022-11-29 22:03:40 +08:00
|
|
|
|
import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
|
|
import { useThemeConfig } from '/@/stores/themeConfig';
|
2022-11-29 22:03:40 +08:00
|
|
|
|
import other from '/@/utils/other';
|
2024-12-26 19:12:44 +08:00
|
|
|
|
import {useMenuApi} from '/@/api/menu'
|
2022-04-18 19:14:38 +08:00
|
|
|
|
|
2022-11-29 22:03:40 +08:00
|
|
|
|
// 引入组件
|
|
|
|
|
const SubItem = defineAsyncComponent(() => import('/@/layout/navMenu/subItem.vue'));
|
|
|
|
|
|
|
|
|
|
// 定义父组件传过来的值
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
// 菜单列表
|
|
|
|
|
menuList: {
|
|
|
|
|
type: Array<RouteRecordRaw>,
|
|
|
|
|
default: () => [],
|
2021-03-15 12:44:58 +08:00
|
|
|
|
},
|
2020-12-31 11:47:52 +08:00
|
|
|
|
});
|
2022-11-29 22:03:40 +08:00
|
|
|
|
|
|
|
|
|
// 定义变量内容
|
|
|
|
|
const storesThemeConfig = useThemeConfig();
|
|
|
|
|
const { themeConfig } = storeToRefs(storesThemeConfig);
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const state = reactive({
|
|
|
|
|
// 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
|
|
|
|
defaultActive: route.meta.isDynamic ? route.meta.isDynamicPath : route.path,
|
|
|
|
|
isCollapse: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取父级菜单数据
|
|
|
|
|
const menuLists = computed(() => {
|
2024-12-26 19:12:44 +08:00
|
|
|
|
return props.menuList || [];
|
2022-11-29 22:03:40 +08:00
|
|
|
|
});
|
|
|
|
|
// 获取布局配置信息
|
|
|
|
|
const getThemeConfig = computed(() => {
|
|
|
|
|
return themeConfig.value;
|
|
|
|
|
});
|
2024-12-26 19:12:44 +08:00
|
|
|
|
// 默认全展开的实现
|
|
|
|
|
// const defaultOpeneds = computed(() => {
|
|
|
|
|
// if (menuLists.value.length === 0) {
|
|
|
|
|
// console.log(111111111111);
|
|
|
|
|
// return []; // 没有菜单时返回空数组
|
|
|
|
|
// }
|
|
|
|
|
// console.log(22222222222);
|
|
|
|
|
|
|
|
|
|
// return menuLists.value.map((_, index) => index.toString());
|
|
|
|
|
// });
|
|
|
|
|
const defaultOpeneds = ref<string[]>([]);
|
|
|
|
|
|
|
|
|
|
|
2022-11-29 22:03:40 +08:00
|
|
|
|
// 菜单高亮(详情时,父级高亮)
|
|
|
|
|
const setParentHighlight = (currentRoute: RouteToFrom) => {
|
|
|
|
|
const { path, meta } = currentRoute;
|
|
|
|
|
const pathSplit = meta?.isDynamic ? meta.isDynamicPath!.split('/') : path!.split('/');
|
|
|
|
|
if (pathSplit.length >= 4 && meta?.isHide) return pathSplit.splice(0, 3).join('/');
|
|
|
|
|
else return path;
|
|
|
|
|
};
|
|
|
|
|
// 打开外部链接
|
|
|
|
|
const onALinkClick = (val: RouteItem) => {
|
|
|
|
|
other.handleOpenLink(val);
|
|
|
|
|
};
|
2024-12-26 19:12:44 +08:00
|
|
|
|
|
2022-11-29 22:03:40 +08:00
|
|
|
|
// 页面加载时
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
state.defaultActive = setParentHighlight(route);
|
2024-12-26 19:12:44 +08:00
|
|
|
|
// 每次加载页面,初始化默认展开项
|
|
|
|
|
// const storedOpeneds = localStorage.getItem('defaultOpeneds');
|
|
|
|
|
// if (storedOpeneds) {
|
|
|
|
|
// console.log('Loaded from localStorage:', JSON.parse(storedOpeneds));
|
|
|
|
|
// } else {
|
|
|
|
|
// // 如果没有存储记录,设置为全部展开
|
|
|
|
|
// localStorage.setItem('defaultOpeneds', JSON.stringify(defaultOpeneds.value));
|
|
|
|
|
// }
|
2022-11-29 22:03:40 +08:00
|
|
|
|
});
|
|
|
|
|
// 路由更新时
|
|
|
|
|
onBeforeRouteUpdate((to) => {
|
|
|
|
|
// 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
|
|
|
|
state.defaultActive = setParentHighlight(to);
|
|
|
|
|
const clientWidth = document.body.clientWidth;
|
|
|
|
|
if (clientWidth < 1000) themeConfig.value.isCollapse = false;
|
|
|
|
|
});
|
|
|
|
|
// 设置菜单的收起/展开
|
|
|
|
|
watch(
|
2023-03-26 17:43:05 +08:00
|
|
|
|
() => themeConfig.value.isCollapse,
|
|
|
|
|
(isCollapse) => {
|
|
|
|
|
document.body.clientWidth <= 1000 ? (state.isCollapse = false) : (state.isCollapse = isCollapse);
|
2022-11-29 22:03:40 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true,
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-12-26 19:12:44 +08:00
|
|
|
|
// // 监听默认展开状态,并存储到 localStorage
|
|
|
|
|
// // 保存状态到 localStorage,每次更改时更新存储
|
|
|
|
|
// watch(defaultOpeneds, (newVal) => {
|
|
|
|
|
// localStorage.setItem('defaultOpeneds', JSON.stringify(newVal));
|
|
|
|
|
// });
|
|
|
|
|
// 监控 props 的变化,确保 defaultOpeneds 始终正确
|
|
|
|
|
watch(
|
|
|
|
|
() => props.menuList,
|
|
|
|
|
(newMenuList) => {
|
|
|
|
|
defaultOpeneds.value = newMenuList.map((_, index) => index.toString());
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true,
|
|
|
|
|
deep: true,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2020-12-31 11:47:52 +08:00
|
|
|
|
</script>
|
2025-01-06 12:21:01 +08:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
|
|
::v-deep .el-menu-item-group__title{
|
|
|
|
|
padding :0px 0px 0px ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|