Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Jul 9, 2024
1 parent c16972a commit f372fb7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 59 deletions.
126 changes: 72 additions & 54 deletions src/layout/components/components/children-banner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,86 @@
- @Link https://gitee.com/xmo/mineadmin-vue
-->
<template>
<a-layout-content class="sys-menus">
<a-menu ref="MaMenuRef" mode="horizontal" class="layout-banner-menu hidden lg:flex" :popup-max-height="360"
:selected-keys="actives">
<template v-for="menu in modelValue" :key="menu.id">
<template v-if="!menu.meta.hidden">
<template v-if="! menu.children || menu.children.length === 0">
<a-layout-content class="sys-menus">
<a-menu
ref="MaMenuRef"
mode="horizontal"
class="layout-banner-menu hidden lg:flex"
:popup-max-height="360"
:selected-keys="actives"
>
<template v-for="menu in modelValue" :key="menu.id">
<template v-if="!menu.meta.hidden">
<template v-if="!menu.children || menu.children.length === 0">
<!-- 没有子菜单的进入 -->
<a-menu-item :key="menu.name" @click="routerPush(menu)">
<template #icon v-if="menu.meta.icon">
<component :is="menu.meta.icon" :class="menu.meta.icon.indexOf('ma') > 0 ? 'icon' : ''" />
<component
:is="menu.meta.icon"
:class="menu.meta.icon.indexOf('ma') > 0 ? 'icon' : ''"
/>
</template>
{{ appStore.i18n ? ( $t(`menus.${menu.name}`).indexOf('.') > 0 ? menu.meta.title : $t(`menus.${menu.name}`) ) : menu.meta.title }}
{{
appStore.i18n
? $t(`menus.${menu.name}`).indexOf(".") > 0
? menu.meta.title
: $t(`menus.${menu.name}`)
: menu.meta.title
}}
</a-menu-item>
</template>
<!-- 有子菜单的进入 -->
<template v-else>
<SubMenu :menu-info="menu" />
</template>
</template>
</template>
</a-menu>
</a-layout-content>
</template>
<script setup>
import { ref, watch, onMounted } from 'vue'
import { useTagStore, useAppStore } from '@/store'
import { useRouter, useRoute } from 'vue-router'
import SubMenu from './sub-menu.vue'
defineProps({ modelValue: Array })
const router = useRouter()
const emits = defineEmits(['go'])
const appStore = useAppStore()
const tagStore = useTagStore()
const route = useRoute()
const actives = ref([])
onMounted(() => {
actives.value = [route.name]
})

watch(() => route, v => {
actives.value = [v.name]
}, { deep: true })
const routerPush = (menu) => {
if (menu.meta && menu.meta.type === 'L') {
window.open(menu.path)
} else if (menu.redirect) {
router.push(menu.redirect)
} else {
router.push(menu.path)
tagStore.addTag({ name: menu.name, title: menu.meta.title, path: menu.path })
}
}

</script>

<style>
.sys-menus .icon {
width: 1em;
height: 1em;
}

.arco-menu-selected .icon {
fill: rgb(var(--primary-6));
}
</style>
</template>
</a-menu>
</a-layout-content>
</template>
<script setup>
import { ref, watch, onMounted } from "vue";
import { useTagStore, useAppStore } from "@/store";
import { useRouter, useRoute } from "vue-router";
import SubMenu from "./sub-menu.vue";
defineProps({ modelValue: Array });
const router = useRouter();
const emits = defineEmits(["go"]);
const appStore = useAppStore();
const tagStore = useTagStore();
const route = useRoute();
const actives = ref([]);
onMounted(() => {
actives.value = [route.name];
});

watch(
() => route,
(v) => {
actives.value = [v.name];
},
{ deep: true }
);

const routerPush = (menu) => {
if (menu.meta && menu.meta.type === 'L') {
window.open(menu.path)
} else if (menu.path && menu.component) {
router.push(menu.path)
tagStore.addTag({ name: menu.name, title: menu.meta.title, path: menu.path })
} else {
console.warn('菜单未配置组件或者path')
}
}
</script>

<style>
.sys-menus .icon {
width: 1em;
height: 1em;
}

.arco-menu-selected .icon {
fill: rgb(var(--primary-6));
}
</style>
4 changes: 3 additions & 1 deletion src/layout/components/components/children-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
const routerPush = (menu) => {
if (menu.meta && menu.meta.type === 'L') {
window.open(menu.path)
}else {
} else if (menu.path && menu.component) {
router.push(menu.path)
tagStore.addTag({ name: menu.name, title: menu.meta.title, path: menu.path })
} else {
console.warn('菜单未配置组件或者path')
}
}
</script>
Expand Down
8 changes: 4 additions & 4 deletions src/layout/components/components/sub-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<component :is="menuInfo.meta.icon" :class="menuInfo.meta.icon.indexOf('ma') > 0 ? 'icon' : ''" />
</template>
<template v-for="item in menuInfo.children" :key="item.id">
<template v-if="!item.children|| item.children.length === 0">
<template v-if="!item.children || item.children.length === 0">
<a-menu-item :key="item.name" @click="routerPush(item)">
<template #icon v-if="item.meta.icon">
<component :is="item.meta.icon" :class="menuInfo.meta.icon.indexOf('ma') > 0 ? 'icon' : ''" />
Expand All @@ -42,11 +42,11 @@
const routerPush = (menu) => {
if (menu.meta && menu.meta.type === 'L') {
window.open(menu.path)
} else if (menu.redirect) {
router.push(menu.redirect)
} else {
} else if (menu.path && menu.component) {
router.push(menu.path)
tagStore.addTag({ name: menu.name, title: menu.meta.title, path: menu.path })
} else {
console.warn('菜单未配置组件或者path')
}
}
</script>
Expand Down

0 comments on commit f372fb7

Please sign in to comment.