refactor(router): 优化路由配置,隐藏非必要动态路由
Some checks failed
Lint Code / Lint Code (push) Failing after 3m48s
Some checks failed
Lint Code / Lint Code (push) Failing after 3m48s
- mock数据中只返回项目管理和系统管理路由,去除其他动态路由 - 限制自动导入的路由模块,仅包含项目管理、系统管理和剩余路由 - 首页重定向到项目管理首页,隐藏首页菜单链接显示 - 更新首页路由元信息,确保不显示首页链接
This commit is contained in:
@@ -1,277 +1,7 @@
|
||||
// 模拟后端动态生成路由
|
||||
import { defineFakeRoute } from "vite-plugin-fake-server/client";
|
||||
import { monitor, permission, frame, tabs } from "@/router/enums";
|
||||
|
||||
/**
|
||||
* roles:页面级别权限,这里模拟二种 "admin"、"common"
|
||||
* admin:管理员角色
|
||||
* common:普通角色
|
||||
*/
|
||||
const systemMonitorRouter = {
|
||||
path: "/monitor",
|
||||
meta: {
|
||||
icon: "ep:monitor",
|
||||
title: "menus.pureSysMonitor",
|
||||
rank: monitor
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/monitor/online-user",
|
||||
component: "monitor/online/index",
|
||||
name: "OnlineUser",
|
||||
meta: {
|
||||
icon: "ri:user-voice-line",
|
||||
title: "menus.pureOnlineUser",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/monitor/login-logs",
|
||||
component: "monitor/logs/login/index",
|
||||
name: "LoginLog",
|
||||
meta: {
|
||||
icon: "ri:window-line",
|
||||
title: "menus.pureLoginLog",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/monitor/operation-logs",
|
||||
component: "monitor/logs/operation/index",
|
||||
name: "OperationLog",
|
||||
meta: {
|
||||
icon: "ri:history-fill",
|
||||
title: "menus.pureOperationLog",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/monitor/system-logs",
|
||||
component: "monitor/logs/system/index",
|
||||
name: "SystemLog",
|
||||
meta: {
|
||||
icon: "ri:file-search-line",
|
||||
title: "menus.pureSystemLog",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const permissionRouter = {
|
||||
path: "/permission",
|
||||
meta: {
|
||||
title: "menus.purePermission",
|
||||
icon: "ep:lollipop",
|
||||
rank: permission
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/permission/page/index",
|
||||
name: "PermissionPage",
|
||||
meta: {
|
||||
title: "menus.purePermissionPage",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/permission/button",
|
||||
meta: {
|
||||
title: "menus.purePermissionButton",
|
||||
roles: ["admin", "common"]
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/permission/button/router",
|
||||
component: "permission/button/index",
|
||||
name: "PermissionButtonRouter",
|
||||
meta: {
|
||||
title: "menus.purePermissionButtonRouter",
|
||||
auths: [
|
||||
"permission:btn:add",
|
||||
"permission:btn:edit",
|
||||
"permission:btn:delete"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/permission/button/login",
|
||||
component: "permission/button/perms",
|
||||
name: "PermissionButtonLogin",
|
||||
meta: {
|
||||
title: "menus.purePermissionButtonLogin"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const frameRouter = {
|
||||
path: "/iframe",
|
||||
meta: {
|
||||
icon: "ri:links-fill",
|
||||
title: "menus.pureExternalPage",
|
||||
rank: frame
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/iframe/embedded",
|
||||
meta: {
|
||||
title: "menus.pureEmbeddedDoc"
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/iframe/colorhunt",
|
||||
name: "FrameColorHunt",
|
||||
meta: {
|
||||
title: "menus.pureColorHuntDoc",
|
||||
frameSrc: "https://colorhunt.co/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/uigradients",
|
||||
name: "FrameUiGradients",
|
||||
meta: {
|
||||
title: "menus.pureUiGradients",
|
||||
frameSrc: "https://uigradients.com/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/ep",
|
||||
name: "FrameEp",
|
||||
meta: {
|
||||
title: "menus.pureEpDoc",
|
||||
frameSrc: "https://element-plus.org/zh-CN/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/tailwindcss",
|
||||
name: "FrameTailwindcss",
|
||||
meta: {
|
||||
title: "menus.pureTailwindcssDoc",
|
||||
frameSrc: "https://tailwindcss.com/docs/installation",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/vue3",
|
||||
name: "FrameVue",
|
||||
meta: {
|
||||
title: "menus.pureVueDoc",
|
||||
frameSrc: "https://cn.vuejs.org/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/vite",
|
||||
name: "FrameVite",
|
||||
meta: {
|
||||
title: "menus.pureViteDoc",
|
||||
frameSrc: "https://cn.vitejs.dev/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/pinia",
|
||||
name: "FramePinia",
|
||||
meta: {
|
||||
title: "menus.purePiniaDoc",
|
||||
frameSrc: "https://pinia.vuejs.org/zh/index.html",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/iframe/vue-router",
|
||||
name: "FrameRouter",
|
||||
meta: {
|
||||
title: "menus.pureRouterDoc",
|
||||
frameSrc: "https://router.vuejs.org/zh/",
|
||||
keepAlive: true,
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/iframe/external",
|
||||
meta: {
|
||||
title: "menus.pureExternalDoc"
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/external",
|
||||
name: "https://pure-admin.cn/",
|
||||
meta: {
|
||||
title: "menus.pureExternalLink",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/pureUtilsLink",
|
||||
name: "https://pure-admin-utils.netlify.app/",
|
||||
meta: {
|
||||
title: "menus.pureUtilsLink",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const tabsRouter = {
|
||||
path: "/tabs",
|
||||
meta: {
|
||||
icon: "ri:bookmark-2-line",
|
||||
title: "menus.pureTabs",
|
||||
rank: tabs
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/tabs/index",
|
||||
name: "Tabs",
|
||||
meta: {
|
||||
title: "menus.pureTabs",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
// query 传参模式
|
||||
{
|
||||
path: "/tabs/query-detail",
|
||||
name: "TabQueryDetail",
|
||||
meta: {
|
||||
// 不在menu菜单中显示
|
||||
showLink: false,
|
||||
activePath: "/tabs/index",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
},
|
||||
// params 传参模式
|
||||
{
|
||||
path: "/tabs/params-detail/:id",
|
||||
component: "params-detail",
|
||||
name: "TabParamsDetail",
|
||||
meta: {
|
||||
// 不在menu菜单中显示
|
||||
showLink: false,
|
||||
activePath: "/tabs/index",
|
||||
roles: ["admin", "common"]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// 只保留项目管理、系统管理,不返回其他动态路由
|
||||
export default defineFakeRoute([
|
||||
{
|
||||
url: "/get-async-routes",
|
||||
@@ -280,7 +10,7 @@ export default defineFakeRoute([
|
||||
return {
|
||||
code: 0,
|
||||
message: "操作成功",
|
||||
data: [systemMonitorRouter, permissionRouter, frameRouter, tabsRouter]
|
||||
data: []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,16 @@ import {
|
||||
multipleTabsKey
|
||||
} from "@/utils/auth";
|
||||
|
||||
/** 自动导入全部静态路由,无需再手动引入!匹配 src/router/modules 目录(任何嵌套级别)中具有 .ts 扩展名的所有文件,除了 remaining.ts 文件
|
||||
* 如何匹配所有文件请看:https://github.com/mrmlnc/fast-glob#basic-syntax
|
||||
* 如何排除文件请看:https://cn.vitejs.dev/guide/features.html#negative-patterns
|
||||
/** 只导入项目管理、系统管理和剩余路由模块
|
||||
* 其他路由模块已隐藏
|
||||
*/
|
||||
const modules: Record<string, any> = import.meta.glob(
|
||||
["./modules/**/*.ts", "!./modules/**/remaining.ts"],
|
||||
[
|
||||
"./modules/project.ts",
|
||||
"./modules/system.ts",
|
||||
"./modules/home.ts",
|
||||
"!./modules/**/remaining.ts"
|
||||
],
|
||||
{
|
||||
eager: true
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
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 {
|
||||
path: "/",
|
||||
name: "Home",
|
||||
component: Layout,
|
||||
redirect: "/welcome",
|
||||
redirect: "/project/index",
|
||||
meta: {
|
||||
icon: "ep/home-filled",
|
||||
title: $t("menus.pureHome"),
|
||||
rank: home
|
||||
rank: home,
|
||||
showLink: false
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
component: () => import("@/views/welcome/index.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureHome"),
|
||||
showLink: VITE_HIDE_HOME === "true" ? false : true
|
||||
showLink: false
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -25,7 +25,7 @@ export default {
|
||||
meta: {
|
||||
title: "项目详情",
|
||||
showLink: false,
|
||||
activePath: "/project"
|
||||
activePath: "/project/index"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -421,61 +421,6 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<div class="project-detail w-full" :style="marginStyle">
|
||||
<!-- 边距设置按钮 -->
|
||||
<el-popover placement="bottom-end" :width="200" trigger="click">
|
||||
<template #reference>
|
||||
<el-button link class="margin-setting-btn" title="边距设置">
|
||||
<component :is="useRenderIcon('ri/layout-line')" />
|
||||
</el-button>
|
||||
</template>
|
||||
<div class="margin-setting-panel">
|
||||
<div class="setting-title">页面边距设置 (px)</div>
|
||||
<div class="setting-item">
|
||||
<span>上边距</span>
|
||||
<el-input-number
|
||||
v-model="marginSettings.top"
|
||||
:min="0"
|
||||
:max="100"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<span>右边距</span>
|
||||
<el-input-number
|
||||
v-model="marginSettings.right"
|
||||
:min="0"
|
||||
:max="200"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<span>下边距</span>
|
||||
<el-input-number
|
||||
v-model="marginSettings.bottom"
|
||||
:min="0"
|
||||
:max="100"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<span>左边距</span>
|
||||
<el-input-number
|
||||
v-model="marginSettings.left"
|
||||
:min="0"
|
||||
:max="200"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="marginSettings = { top: 16, right: 80, bottom: 16, left: 16 }"
|
||||
>
|
||||
恢复默认
|
||||
</el-button>
|
||||
</div>
|
||||
</el-popover>
|
||||
|
||||
<!-- 顶部导航 -->
|
||||
<div class="flex-bc mb-4">
|
||||
<div class="flex items-center gap-3">
|
||||
|
||||
Reference in New Issue
Block a user