fix: 修复路由显示和权限管理问题
- 修复父级路由页面缺少router-view导致子路由无法显示的问题 - 修复getAllMenus接口只返回根路由的问题,现在返回所有路由(包括子路由) - 修复权限管理页面菜单树构建逻辑,正确识别父子关系 - 将所有有子路由的父级index.vue改为只包含<router-view /> 修改的文件: - backend: RouteController.java, RouteService.java - frontend: application/index.vue, device/index.vue, my-application/index.vue, my-device/index.vue, screen/index.vue, system/index.vue, user-manage/index.vue, user-manage/permission/index.vue
This commit is contained in:
parent
b92e1119ae
commit
d92f6e4d8c
@ -49,7 +49,7 @@ public class RouteController {
|
||||
@GetMapping("/getAllMenus")
|
||||
public Result<List<MenuRoute>> getAllMenus() {
|
||||
try {
|
||||
List<MenuRoute> menus = routeService.getConstantRoutes();
|
||||
List<MenuRoute> menus = routeService.getAllRoutes();
|
||||
return Result.success(menus);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
|
||||
@ -149,6 +149,38 @@ public class RouteService {
|
||||
return routeMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
|
||||
public List<MenuRoute> getAllRoutes() {
|
||||
// 获取所有启用的路由
|
||||
LambdaQueryWrapper<Route> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Route::getStatus, 1)
|
||||
.orderByAsc(Route::getOrderNum);
|
||||
List<Route> routes = routeMapper.selectList(wrapper);
|
||||
|
||||
// 转换为 MenuRoute,但不构建树结构,返回扁平列表
|
||||
return routes.stream().map(route -> {
|
||||
MenuRoute menuRoute = new MenuRoute();
|
||||
menuRoute.setId(route.getRouteId());
|
||||
menuRoute.setName(route.getName());
|
||||
menuRoute.setPath(route.getPath());
|
||||
menuRoute.setComponent(route.getComponent());
|
||||
|
||||
try {
|
||||
if (route.getMeta() != null && !route.getMeta().isEmpty()) {
|
||||
Map<String, Object> meta = objectMapper.readValue(
|
||||
route.getMeta(),
|
||||
new TypeReference<Map<String, Object>>() {}
|
||||
);
|
||||
meta.remove("roles");
|
||||
menuRoute.setMeta(meta);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
menuRoute.setMeta(new HashMap<>());
|
||||
}
|
||||
|
||||
return menuRoute;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<MenuRoute> convertToMenuRoutes(List<Route> routes) {
|
||||
System.out.println("=== 开始构建路由树 ===");
|
||||
System.out.println("输入路由数量: " + routes.size());
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="使用申请" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">使用申请主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="设备管理" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">设备管理主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="设备申请" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">设备申请主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="我的设备" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">我的设备主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="屏幕监控" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">屏幕监控主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="系统设置" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<p class="text-gray-500">系统设置主页面</p>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<n-card title="用户管理" :bordered="false" class="h-full rounded-8px shadow-sm">
|
||||
<n-alert type="info" title="用户管理">
|
||||
管理系统用户、角色和权限
|
||||
</n-alert>
|
||||
</n-card>
|
||||
</div>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@ -138,28 +138,38 @@ const menuTree = computed(() => {
|
||||
const tree: Menu[] = [];
|
||||
const map: Record<string, Menu> = {};
|
||||
|
||||
// 第一遍:创建所有节点的映射
|
||||
menus.value.forEach(menu => {
|
||||
map[menu.name] = { ...menu, children: [] };
|
||||
});
|
||||
|
||||
// 第二遍:建立父子关系
|
||||
menus.value.forEach(menu => {
|
||||
const node = map[menu.name];
|
||||
|
||||
// 如果路由名称包含下划线,说明是子路由
|
||||
if (menu.name.includes('_')) {
|
||||
const parentName = menu.name.split('_')[0];
|
||||
// 获取最后一个下划线之前的部分作为父路由名称
|
||||
const lastUnderscoreIndex = menu.name.lastIndexOf('_');
|
||||
const parentName = menu.name.substring(0, lastUnderscoreIndex);
|
||||
const parent = map[parentName];
|
||||
|
||||
if (parent) {
|
||||
if (!parent.children) {
|
||||
parent.children = [];
|
||||
}
|
||||
parent.children.push(node);
|
||||
} else {
|
||||
// 如果找不到父路由,作为根节点
|
||||
tree.push(node);
|
||||
}
|
||||
} else {
|
||||
// 没有下划线的是根路由
|
||||
tree.push(node);
|
||||
}
|
||||
});
|
||||
|
||||
// 清理空的 children 数组
|
||||
const cleanTree = (nodes: Menu[]) => {
|
||||
return nodes.map(node => {
|
||||
if (node.children && node.children.length === 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user