feat: 可配置首页菜单显示与隐藏 (#539)

* feat: 可配置首页显示与隐藏
This commit is contained in:
RealityBoy
2023-05-05 22:55:12 +08:00
committed by GitHub
parent d49b23e8f9
commit 9d0c3f305d
19 changed files with 4850 additions and 2053 deletions

View File

@@ -1,5 +1,6 @@
<script setup lang="ts">
import { isEqual } from "@pureadmin/utils";
import { routerArrays } from "@/layout/types";
import { transformI18n } from "@/plugins/i18n";
import { ref, watch, onMounted, toRaw } from "vue";
import { getParentPaths, findRouteByPath } from "@/router/utils";
@@ -10,14 +11,9 @@ const route = useRoute();
const levelList = ref([]);
const router = useRouter();
const routes: any = router.options.routes;
const { VITE_HIDE_HOME } = import.meta.env;
const multiTags: any = useMultiTagsStoreHook().multiTags;
const isDashboard = (route: RouteLocationMatched): boolean | string => {
const name = route && (route.name as string);
if (!name) return false;
return name.trim().toLocaleLowerCase() === "Welcome".toLocaleLowerCase();
};
const getBreadcrumb = (): void => {
// 当前路由信息
let currentRoute;
@@ -35,7 +31,7 @@ const getBreadcrumb = (): void => {
}
});
} else {
currentRoute = findRouteByPath(router.currentRoute.value.path, multiTags);
currentRoute = findRouteByPath(router.currentRoute.value.path, routes);
}
// 当前路由的父级路径组成的数组
const parentRoutes = getParentPaths(
@@ -53,15 +49,7 @@ const getBreadcrumb = (): void => {
if (currentRoute?.path !== "/welcome") matched.push(currentRoute);
if (!isDashboard(matched[0])) {
matched = [
{
path: "/welcome",
parentPath: "/",
meta: { title: "menus.hshome" }
} as unknown as RouteLocationMatched
].concat(matched);
}
if (VITE_HIDE_HOME === "false") matched = routerArrays.concat(matched);
matched.forEach((item, index) => {
if (currentRoute?.query || currentRoute?.params) return;

View File

@@ -19,7 +19,7 @@ const {
title,
routers,
logout,
backHome,
backTopMenu,
onPanel,
menuSelect,
username,
@@ -45,7 +45,7 @@ watch(
v-loading="usePermissionStoreHook().wholeMenus.length === 0"
class="horizontal-header"
>
<div class="horizontal-header-left" @click="backHome">
<div class="horizontal-header-left" @click="backTopMenu">
<img src="/logo.svg" alt="logo" />
<span>{{ title }}</span>
</div>

View File

@@ -1,4 +1,5 @@
<script setup lang="ts">
import { getTopMenu } from "@/router/utils";
import { useNav } from "@/layout/hooks/useNav";
const props = defineProps({
@@ -6,6 +7,7 @@ const props = defineProps({
});
const { title } = useNav();
const topPath = getTopMenu().path;
</script>
<template>
@@ -16,7 +18,7 @@ const { title } = useNav();
key="props.collapse"
:title="title"
class="sidebar-logo-link"
to="/"
:to="topPath"
>
<img src="/logo.svg" alt="logo" />
<span class="sidebar-title">{{ title }}</span>
@@ -26,7 +28,7 @@ const { title } = useNav();
key="expand"
:title="title"
class="sidebar-logo-link"
to="/"
:to="topPath"
>
<img src="/logo.svg" alt="logo" />
<span class="sidebar-title">{{ title }}</span>

View File

@@ -1,8 +1,8 @@
<script setup lang="ts">
import path from "path";
import { getConfig } from "@/config";
import { menuType } from "../../types";
import extraIcon from "./extraIcon.vue";
import { childrenType } from "../../types";
import { useNav } from "@/layout/hooks/useNav";
import { transformI18n } from "@/plugins/i18n";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
@@ -17,7 +17,7 @@ const { layout, isCollapse, tooltipEffect, getDivStyle } = useNav();
const props = defineProps({
item: {
type: Object as PropType<childrenType>
type: Object as PropType<menuType>
},
isNest: {
type: Boolean,
@@ -112,7 +112,7 @@ const expandCloseIcon = computed(() => {
};
});
const onlyOneChild: childrenType = ref(null);
const onlyOneChild: menuType = ref(null);
// 存放菜单是否存在showTooltip属性标识
const hoverMenuMap = new WeakMap();
// 存储菜单文本dom元素
@@ -149,10 +149,7 @@ function overflowSlice(text, item?: any) {
return newText;
}
function hasOneShowingChild(
children: childrenType[] = [],
parent: childrenType
) {
function hasOneShowingChild(children: menuType[] = [], parent: menuType) {
const showingChildren = children.filter((item: any) => {
onlyOneChild.value = item;
return true;