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

@@ -13,6 +13,7 @@ import {
} from "vue-router";
import {
ascending,
getTopMenu,
initRouter,
isOneOfArray,
getHistoryMode,
@@ -96,6 +97,8 @@ export function resetRouter() {
/** 路由白名单 */
const whiteList = ["/login"];
const { VITE_HIDE_HOME } = import.meta.env;
router.beforeEach((to: toRouteType, _from, next) => {
if (to.meta?.keepAlive) {
handleAliveRoute(to, "add");
@@ -125,6 +128,10 @@ router.beforeEach((to: toRouteType, _from, next) => {
if (to.meta?.roles && !isOneOfArray(to.meta?.roles, userInfo?.roles)) {
next({ path: "/error/403" });
}
// 开启隐藏首页后在浏览器地址栏手动输入首页welcome路由则跳转到404页面
if (VITE_HIDE_HOME === "true" && to.fullPath === "/welcome") {
next({ path: "/error/404" });
}
if (_from?.name) {
// name为超链接
if (externalLink) {
@@ -146,6 +153,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
path,
router.options.routes[0].children
);
getTopMenu(true);
// query、params模式路由传参数的标签页不在此处处理
if (route && route.meta?.title) {
useMultiTagsStoreHook().handleTags("push", {

View File

@@ -1,5 +1,6 @@
import { $t } from "@/plugins/i18n";
import { home } from "@/router/enums";
const { VITE_HIDE_HOME } = import.meta.env;
const Layout = () => import("@/layout/index.vue");
export default {
@@ -18,7 +19,8 @@ export default {
name: "Welcome",
component: () => import("@/views/welcome/index.vue"),
meta: {
title: $t("menus.hshome")
title: $t("menus.hshome"),
showLink: VITE_HIDE_HOME === "true" ? false : true
}
}
]

View File

@@ -16,8 +16,7 @@ export default [
path: "/redirect",
component: Layout,
meta: {
icon: "homeFilled",
title: $t("menus.hshome"),
title: $t("status.hsLoad"),
showLink: false,
rank: 102
},

View File

@@ -17,8 +17,10 @@ import {
isIncludeAllChildren
} from "@pureadmin/utils";
import { getConfig } from "@/config";
import { menuType } from "@/layout/types";
import { buildHierarchyTree } from "@/utils/tree";
import { sessionKey, type DataInfo } from "@/utils/auth";
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
import { usePermissionStoreHook } from "@/store/modules/permission";
const IFrame = () => import("@/layout/frameView.vue");
// https://cn.vitejs.dev/guide/features.html#glob-import
@@ -351,12 +353,20 @@ function hasAuth(value: string | Array<string>): boolean {
return isAuths ? true : false;
}
/** 获取所有菜单中的第一个菜单(顶级菜单)*/
function getTopMenu(tag = false): menuType {
const topMenu = usePermissionStoreHook().wholeMenus[0]?.children[0];
tag && useMultiTagsStoreHook().handleTags("push", topMenu);
return topMenu;
}
export {
hasAuth,
getAuths,
ascending,
filterTree,
initRouter,
getTopMenu,
addPathMatch,
isOneOfArray,
getHistoryMode,