fix: 🐛 补充 basePath 父级路径
Former-commit-id: cce921b52b3f93fb9be8d9619c788a5b1b585fe9
This commit is contained in:
@@ -5,6 +5,9 @@ import { useSettingsStore } from "@/store/modules/settings";
|
|||||||
import { useAppStore } from "@/store/modules/app";
|
import { useAppStore } from "@/store/modules/app";
|
||||||
import variables from "@/styles/variables.module.scss";
|
import variables from "@/styles/variables.module.scss";
|
||||||
|
|
||||||
|
import path from "path-browserify";
|
||||||
|
import { isExternal } from "@/utils/index";
|
||||||
|
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const currRoute = useRoute();
|
const currRoute = useRoute();
|
||||||
@@ -17,7 +20,29 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
type: Array<any>,
|
type: Array<any>,
|
||||||
},
|
},
|
||||||
|
basePath: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析路径
|
||||||
|
*
|
||||||
|
* @param routePath 路由路径
|
||||||
|
*/
|
||||||
|
function resolvePath(routePath: string) {
|
||||||
|
if (isExternal(routePath)) {
|
||||||
|
return routePath;
|
||||||
|
}
|
||||||
|
if (isExternal(props.basePath)) {
|
||||||
|
return props.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完整路径 = 父级路径(/level/level_3) + 路由路径
|
||||||
|
const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<el-menu
|
<el-menu
|
||||||
@@ -34,7 +59,7 @@ const props = defineProps({
|
|||||||
v-for="route in menuList"
|
v-for="route in menuList"
|
||||||
:key="route.path"
|
:key="route.path"
|
||||||
:item="route"
|
:item="route"
|
||||||
:base-path="route.path"
|
:base-path="resolvePath(route.path)"
|
||||||
:is-collapse="!appStore.sidebar.opened"
|
:is-collapse="!appStore.sidebar.opened"
|
||||||
/>
|
/>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ function hasOneShowingChild(children = [], parent: any) {
|
|||||||
// 2:如果无子路由, 复制当前路由信息作为其子路由,满足只拥有一个子路由的条件,所以返回 true
|
// 2:如果无子路由, 复制当前路由信息作为其子路由,满足只拥有一个子路由的条件,所以返回 true
|
||||||
if (showingChildren.length === 0) {
|
if (showingChildren.length === 0) {
|
||||||
onlyOneChild.value = { ...parent, path: "", noShowingChildren: true };
|
onlyOneChild.value = { ...parent, path: "", noShowingChildren: true };
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -71,6 +72,7 @@ function resolvePath(routePath: string) {
|
|||||||
if (isExternal(props.basePath)) {
|
if (isExternal(props.basePath)) {
|
||||||
return props.basePath;
|
return props.basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 完整路径 = 父级路径(/level/level_3) + 路由路径
|
// 完整路径 = 父级路径(/level/level_3) + 路由路径
|
||||||
const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径
|
const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径
|
||||||
return fullPath;
|
return fullPath;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ watch(
|
|||||||
>
|
>
|
||||||
<logo v-if="sidebarLogo" :collapse="!appStore.sidebar.opened" />
|
<logo v-if="sidebarLogo" :collapse="!appStore.sidebar.opened" />
|
||||||
<el-scrollbar v-if="showContent">
|
<el-scrollbar v-if="showContent">
|
||||||
<LeftMenu :menu-list="permissionStore.routes" />
|
<LeftMenu :menu-list="permissionStore.routes" base-path="" />
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
<NavRight v-if="layout === 'top'" />
|
<NavRight v-if="layout === 'top'" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,12 +38,11 @@ watch(
|
|||||||
mixLeftMenu.value = item.children || [];
|
mixLeftMenu.value = item.children || [];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(" mixLeftMenu.value ", mixLeftMenu.value);
|
if (mixLeftMenu.value) {
|
||||||
// if (mixLeftMenu.value.length) {
|
router.push({
|
||||||
// router.push({
|
path: mixLeftMenu.value[0].path,
|
||||||
// path: mixLeftMenu.value[0].path,
|
});
|
||||||
// });
|
}
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: true,
|
||||||
@@ -94,7 +93,8 @@ function handleOutsideClick() {
|
|||||||
<template v-if="layout === 'mix'">
|
<template v-if="layout === 'mix'">
|
||||||
<div class="mix-wrap">
|
<div class="mix-wrap">
|
||||||
<!-- :menu-list="mixLeftMenu -->
|
<!-- :menu-list="mixLeftMenu -->
|
||||||
<LeftMenu :menu-list="permissionStore.routes" />
|
<!-- :menu-list="permissionStore.routes -->
|
||||||
|
<LeftMenu :menu-list="mixLeftMenu" :base-path="activeTopMenu" />
|
||||||
<Main />
|
<Main />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user