|
@@ -1,37 +1,43 @@
|
|
<template>
|
|
<template>
|
|
- <el-menu
|
|
|
|
- router
|
|
|
|
- :default-active="state.defaultActive"
|
|
|
|
- background-color="transparent"
|
|
|
|
- :collapse="state.isCollapse"
|
|
|
|
- :unique-opened="getThemeConfig.isUniqueOpened"
|
|
|
|
- :collapse-transition="false"
|
|
|
|
- class="font-medium"
|
|
|
|
- >
|
|
|
|
- <template v-for="val in menuLists">
|
|
|
|
- <el-sub-menu :index="val.path" v-if="val.children && val.children.length > 0" :key="val.path">
|
|
|
|
- <template #title>
|
|
|
|
- <SvgIcon :name="val.meta.icon" />
|
|
|
|
- <span>{{ $t(val.meta.title) }}</span>
|
|
|
|
- </template>
|
|
|
|
- <SubItem :chil="val.children" />
|
|
|
|
- </el-sub-menu>
|
|
|
|
- <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>
|
|
|
|
- <a class="w100" @click.prevent="onALinkClick(val)">{{ $t(val.meta.title) }}</a>
|
|
|
|
- </template>
|
|
|
|
- </el-menu-item>
|
|
|
|
- </template>
|
|
|
|
- </template>
|
|
|
|
- </el-menu>
|
|
|
|
|
|
+ <el-menu
|
|
|
|
+ :collapse="state.isCollapse"
|
|
|
|
+ :collapse-transition="false"
|
|
|
|
+ :default-active="state.defaultActive"
|
|
|
|
+ :unique-opened="getThemeConfig.isUniqueOpened"
|
|
|
|
+ background-color="transparent"
|
|
|
|
+ class="font-medium"
|
|
|
|
+ router
|
|
|
|
+ >
|
|
|
|
+ <template v-for="val in menuLists">
|
|
|
|
+ <!-- 可展开菜单 -->
|
|
|
|
+ <el-sub-menu v-if="val.children && val.children.length > 0" :key="val.path" :index="val.path" class="custom-menu">
|
|
|
|
+ <template #title>
|
|
|
|
+ <SvgIcon :name="val.meta.icon"/>
|
|
|
|
+ <span>{{ $t(val.meta.title) }}</span>
|
|
|
|
+ </template>
|
|
|
|
+ <SubItem :chil="val.children"/>
|
|
|
|
+ </el-sub-menu>
|
|
|
|
+
|
|
|
|
+ <template v-else>
|
|
|
|
+ <div class="rounded-md">
|
|
|
|
+ <div class="menu-hover w-full">
|
|
|
|
+ <el-menu-item :key="val.path" :index="val.path">
|
|
|
|
+ <SvgIcon :name="val.meta.icon"/>
|
|
|
|
+ <template v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)" #title>
|
|
|
|
+ <span>{{ $t(val.meta.title) }}</span>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else #title>
|
|
|
|
+ <a class="w100" @click.prevent="onALinkClick(val)">{{ $t(val.meta.title) }}</a>
|
|
|
|
+ </template>
|
|
|
|
+ </el-menu-item>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
|
|
+ </template>
|
|
|
|
+ </el-menu>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
-<script setup lang="ts" name="navMenuVertical">
|
|
|
|
|
|
+<script lang="ts" name="navMenuVertical" setup>
|
|
import { defineAsyncComponent, reactive, computed, onMounted, watch } from 'vue';
|
|
import { defineAsyncComponent, reactive, computed, onMounted, watch } from 'vue';
|
|
import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router';
|
|
import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router';
|
|
import { storeToRefs } from 'pinia';
|
|
import { storeToRefs } from 'pinia';
|
|
@@ -43,11 +49,11 @@ const SubItem = defineAsyncComponent(() => import('/@/layout/navMenu/subItem.vue
|
|
|
|
|
|
// 定义父组件传过来的值
|
|
// 定义父组件传过来的值
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
- // 菜单列表
|
|
|
|
- menuList: {
|
|
|
|
- type: Array<RouteRecordRaw>,
|
|
|
|
- default: () => [],
|
|
|
|
- },
|
|
|
|
|
|
+ // 菜单列表
|
|
|
|
+ menuList: {
|
|
|
|
+ type: Array<RouteRecordRaw>,
|
|
|
|
+ default: () => []
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
// 定义变量内容
|
|
// 定义变量内容
|
|
@@ -55,49 +61,59 @@ const storesThemeConfig = useThemeConfig();
|
|
const { themeConfig } = storeToRefs(storesThemeConfig);
|
|
const { themeConfig } = storeToRefs(storesThemeConfig);
|
|
const route = useRoute();
|
|
const route = useRoute();
|
|
const state = reactive({
|
|
const state = reactive({
|
|
- // 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
|
|
|
- defaultActive: route.meta.isDynamic ? route.meta.isDynamicPath : route.path,
|
|
|
|
- isCollapse: false,
|
|
|
|
|
|
+ // 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
|
|
|
+ defaultActive: route.meta.isDynamic ? route.meta.isDynamicPath : route.path,
|
|
|
|
+ isCollapse: false
|
|
});
|
|
});
|
|
|
|
|
|
// 获取父级菜单数据
|
|
// 获取父级菜单数据
|
|
const menuLists = computed(() => {
|
|
const menuLists = computed(() => {
|
|
- return <RouteItems>props.menuList;
|
|
|
|
|
|
+ return <RouteItems>props.menuList;
|
|
});
|
|
});
|
|
// 获取布局配置信息
|
|
// 获取布局配置信息
|
|
const getThemeConfig = computed(() => {
|
|
const getThemeConfig = computed(() => {
|
|
- return themeConfig.value;
|
|
|
|
|
|
+ return themeConfig.value;
|
|
});
|
|
});
|
|
// 菜单高亮(详情时,父级高亮)
|
|
// 菜单高亮(详情时,父级高亮)
|
|
const setParentHighlight = (currentRoute: RouteToFrom) => {
|
|
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 { 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) => {
|
|
const onALinkClick = (val: RouteItem) => {
|
|
- other.handleOpenLink(val);
|
|
|
|
|
|
+ other.handleOpenLink(val);
|
|
};
|
|
};
|
|
// 页面加载时
|
|
// 页面加载时
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- state.defaultActive = setParentHighlight(route);
|
|
|
|
|
|
+ state.defaultActive = setParentHighlight(route);
|
|
});
|
|
});
|
|
// 路由更新时
|
|
// 路由更新时
|
|
onBeforeRouteUpdate((to) => {
|
|
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;
|
|
|
|
|
|
+ // 修复: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(
|
|
watch(
|
|
- themeConfig.value,
|
|
|
|
- () => {
|
|
|
|
- document.body.clientWidth <= 1000 ? (state.isCollapse = false) : (state.isCollapse = themeConfig.value.isCollapse);
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- immediate: true,
|
|
|
|
- }
|
|
|
|
|
|
+ themeConfig.value,
|
|
|
|
+ () => {
|
|
|
|
+ document.body.clientWidth <= 1000 ? (state.isCollapse = false) : (state.isCollapse = themeConfig.value.isCollapse);
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ immediate: true
|
|
|
|
+ }
|
|
);
|
|
);
|
|
</script>
|
|
</script>
|
|
|
|
+
|
|
|
|
+<style scoped>
|
|
|
|
+.menu-hover:hover {
|
|
|
|
+ background-color: #F2F3F5;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+:deep(.custom-menu) {
|
|
|
|
+ --el-menu-hover-bg-color: #F2F3F5;
|
|
|
|
+}
|
|
|
|
+</style>
|