style:新增登录界面 完善api请求逻辑
This commit is contained in:
@@ -9,25 +9,19 @@
|
||||
@select="handleMenuSelect"
|
||||
router
|
||||
>
|
||||
<template v-for="item in menuList" :key="item.path">
|
||||
<template v-for="item in menuList" :key="`${item.path}-${item.meta?.title}`">
|
||||
<el-sub-menu v-if="item.children && item.children.length > 0">
|
||||
<template #title>
|
||||
<el-icon>
|
||||
<location />
|
||||
</el-icon>
|
||||
<el-icon v-if="item.meta?.icon"><component :is="item.meta.icon" /></el-icon>
|
||||
<span>{{ item.meta.title }}</span>
|
||||
</template>
|
||||
<el-menu-item :index="`${item.path}/${row.path}`" v-for="(row,key) in item.children" :key="key">
|
||||
<el-icon>
|
||||
<location />
|
||||
</el-icon>
|
||||
<el-menu-item :index="resolvePath(item.path, row.path)" v-for="(row,key) in item.children" :key="resolvePath(item.path, row.path)">
|
||||
<el-icon v-if="row.meta?.icon"><component :is="row.meta.icon" /></el-icon>
|
||||
<template #title>{{ row.meta.title }}</template>
|
||||
</el-menu-item>
|
||||
</el-sub-menu>
|
||||
<el-menu-item v-else :index="item.path">
|
||||
<el-icon>
|
||||
<location />
|
||||
</el-icon>
|
||||
<el-icon v-if="item.meta?.icon"><component :is="item.meta.icon" /></el-icon>
|
||||
<template #title>{{ item.meta.title }}</template>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
@@ -37,6 +31,7 @@
|
||||
<script setup lang="ts">
|
||||
import { Location } from '@element-plus/icons-vue'
|
||||
defineOptions({ name: "standardMenu" })
|
||||
const route = useRoute();
|
||||
|
||||
const {mode="vertical",menuList,isCollapse,activeMenu} = defineProps<{
|
||||
mode?: 'vertical' | 'horizontal'
|
||||
@@ -51,9 +46,30 @@ const emit = defineEmits<{
|
||||
|
||||
const activeIndex = computed(() => {
|
||||
// 如果传入了 activeMenu,使用它;否则使用默认值
|
||||
return activeMenu || '1-1'
|
||||
return activeMenu || route.path
|
||||
})
|
||||
|
||||
/**
|
||||
* 智能拼接路径
|
||||
* @param parentPath 父级路径
|
||||
* @param childPath 子级路径
|
||||
*/
|
||||
const resolvePath = (parentPath: string, childPath: string) => {
|
||||
// 1. 如果子路径是绝对路径(以 / 开头),直接返回子路径
|
||||
if (childPath.startsWith('/')) {
|
||||
return childPath;
|
||||
}
|
||||
|
||||
// 2. 移除父路径末尾的斜杠
|
||||
const parent = parentPath.endsWith('/') ? parentPath.slice(0, -1) : parentPath;
|
||||
|
||||
// 3. 移除子路径开头的斜杠(虽然第一步已经过滤了,但为了健壮性保留)
|
||||
const child = childPath.startsWith('/') ? childPath.slice(1) : childPath;
|
||||
|
||||
// 4. 返回拼接后的路径
|
||||
return `${parent}/${child}`;
|
||||
};
|
||||
|
||||
// 处理菜单选中事件
|
||||
const handleMenuSelect = (index: string) => {
|
||||
// 如果是水平模式(顶部菜单),触发选中事件
|
||||
|
||||
Reference in New Issue
Block a user