Skip to content

Commit

Permalink
fix: 修复顶部菜单模式,菜单布局不生效 (fix vbenjs#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunHsl committed Oct 25, 2023
1 parent 2e5906a commit a433783
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions packages/layouts/src/components/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import { useI18n } from '@vben/locale'
import { REDIRECT_NAME } from '@vben/constants'
import { renderIcon } from '../index'
import { context } from '../../../bridge'
import type { RouteMeta } from 'vue-router'
const { Logo, useAppInject, useAppConfig } = context
const { Logo, useAppInject, useAppConfig, useMenuSetting } = context
import { getMenus, listenerRouteChange } from '@vben/router'
const { getIsMobile } = useAppInject()
const { menu, isMixSidebar, getCollapsedShowTitle, sidebar, isSidebar } =
useAppConfig()
const { getTopMenuAlign } = useMenuSetting()
const showSidebarLogo = computed(() => {
return unref(isSidebar) || unref(isMixSidebar)
})
Expand Down Expand Up @@ -72,7 +74,7 @@ async function handleMenuChange(route?: RouteLocationNormalizedLoaded) {
}
// 路由格式化
const routerToMenu = (item: RouteRecordItem) => {
const routerToMenu = (item: RouteRecordItem & RouteMeta) => {
const { name, children, meta, icon } = item
const title = t(meta.title as string)
return {
Expand Down Expand Up @@ -106,6 +108,7 @@ const routerToMenu = (item: RouteRecordItem) => {

<VbenScrollbar :class="bem('scrollbar')">
<VbenMenu
:class="getTopMenuAlign"
v-model:value="activeKey"
:options="menuList"
:collapsed="getMenuCollapsed"
Expand All @@ -120,6 +123,11 @@ const routerToMenu = (item: RouteRecordItem) => {
</VbenScrollbar>
</div>
</template>
<style>
div:has(> div[class='layout-menu']) {
flex: 1;
}
</style>

<style lang="less" scoped>
.layout-menu {
Expand All @@ -135,5 +143,21 @@ const routerToMenu = (item: RouteRecordItem) => {
flex: 1;
flex-basis: auto;
}
& .n-menu--horizontal {
width: 100%;
&.start {
justify-content: flex-start;
}
&.center {
justify-content: center;
}
&.end {
justify-content: flex-end;
}
}
}
</style>

0 comments on commit a433783

Please sign in to comment.