feat: 侧边动态路由菜单支持参数

This commit is contained in:
郝先瑞
2024-05-24 18:17:01 +08:00
parent 1c4326fdfa
commit c5f7e4b081
4 changed files with 39 additions and 11 deletions

View File

@@ -362,6 +362,7 @@ export default defineMock([
icon: "", icon: "",
hidden: false, hidden: false,
roles: ["ADMIN"], roles: ["ADMIN"],
params: { type: "1" },
}, },
}, },
], ],

View File

@@ -1,5 +1,5 @@
<template> <template>
<component :is="type" v-bind="linkProps(to)"> <component :is="linkType" v-bind="linkProps(to)">
<slot></slot> <slot></slot>
</component> </component>
</template> </template>
@@ -14,20 +14,25 @@ import { isExternal } from "@/utils/index";
const props = defineProps({ const props = defineProps({
to: { to: {
type: String, type: Object,
required: true, required: true,
}, },
}); });
const isExternalLink = computed(() => isExternal(props.to)); const isExternalLink = computed(() => {
return isExternal(props.to.path || "");
const type = computed(() => {
return isExternalLink.value ? "a" : "router-link";
}); });
const linkProps = (to: string) => { const linkType = computed(() => (isExternalLink.value ? "a" : "router-link"));
return isExternalLink.value
? { href: to, target: "_blank", rel: "noopener noreferrer" } const linkProps = (to: any) => {
: { to }; if (isExternalLink.value) {
return {
href: to.path,
target: "_blank",
rel: "noopener noreferrer",
};
}
return { to: to };
}; };
</script> </script>

View File

@@ -8,7 +8,13 @@
!item.meta?.alwaysShow !item.meta?.alwaysShow
" "
> >
<AppLink v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)"> <AppLink
v-if="onlyOneChild.meta"
:to="{
path: resolvePath(onlyOneChild.path),
query: onlyOneChild.meta.params,
}"
>
<el-menu-item <el-menu-item
:index="resolvePath(onlyOneChild.path)" :index="resolvePath(onlyOneChild.path)"
:class="{ 'submenu-title-noDropdown': !isNest }" :class="{ 'submenu-title-noDropdown': !isNest }"

16
src/views/demo/other.vue Normal file
View File

@@ -0,0 +1,16 @@
<template>
<div>路由参数{{ query }}</div>
</template>
<script setup lang="ts">
defineOptions({
name: "Other",
inheritAttrs: false,
});
import { useRoute } from "vue-router";
// 获取query参数
const query = useRoute().query.type as string;
</script>
<style lang="scss" scoped></style>