fix: 修复顶栏多出一个...的问题
This commit is contained in:
parent
8c2ce8587d
commit
0ccd6dc750
|
|
@ -37,7 +37,7 @@
|
||||||
const menuComponent = computed(() => {
|
const menuComponent = computed(() => {
|
||||||
if (
|
if (
|
||||||
props.routerInfo.children &&
|
props.routerInfo.children &&
|
||||||
props.routerInfo.children.filter((item) => !item.hidden).length
|
props.routerInfo.children?.filter((item) => !item.hidden).length
|
||||||
) {
|
) {
|
||||||
return AsyncSubmenu
|
return AsyncSubmenu
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="bg-white h-[calc(100%-4px)] text-slate-700 dark:text-slate-300 mx-2 dark:bg-slate-900 flex items-center w-[calc(100vw-600px)] overflow-auto"
|
class="bg-white h-[calc(100%-4px)] text-slate-700 dark:text-slate-300 mx-2 dark:bg-slate-900 flex items-center w-[calc(100vw-600px)] overflow-auto"
|
||||||
|
ref="menuContainer"
|
||||||
>
|
>
|
||||||
<el-menu
|
<el-menu
|
||||||
:default-active="active"
|
:default-active="active"
|
||||||
mode="horizontal"
|
mode="horizontal"
|
||||||
class="border-r-0 w-full flex gap-1 items-center box-border h-[calc(100%-1px)]"
|
class="border-r-0 w-full flex gap-1 items-center box-border h-[calc(100%-1px)]"
|
||||||
unique-opened
|
unique-opened
|
||||||
|
:ellipsis="shouldEllipsis"
|
||||||
@select="selectMenuItem"
|
@select="selectMenuItem"
|
||||||
|
ref="menuRef"
|
||||||
>
|
>
|
||||||
<template v-for="item in routerStore.asyncRouters[0].children">
|
<template v-for="item in routerStore.asyncRouters[0].children">
|
||||||
<aside-component
|
<aside-component
|
||||||
|
|
@ -23,7 +26,7 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import AsideComponent from '@/view/layout/aside/asideComponent/index.vue'
|
import AsideComponent from '@/view/layout/aside/asideComponent/index.vue'
|
||||||
import { ref, provide, watchEffect } from 'vue'
|
import { ref, provide, watchEffect, onMounted, nextTick } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useRouterStore } from '@/pinia/modules/router'
|
import { useRouterStore } from '@/pinia/modules/router'
|
||||||
import { useAppStore } from '@/pinia'
|
import { useAppStore } from '@/pinia'
|
||||||
|
|
@ -39,6 +42,26 @@
|
||||||
const routerStore = useRouterStore()
|
const routerStore = useRouterStore()
|
||||||
const isCollapse = ref(false)
|
const isCollapse = ref(false)
|
||||||
const active = ref('')
|
const active = ref('')
|
||||||
|
const menuRef = ref(null)
|
||||||
|
const menuContainer = ref(null)
|
||||||
|
const shouldEllipsis = ref(false)
|
||||||
|
|
||||||
|
// 计算是否需要启用省略功能
|
||||||
|
const calculateEllipsis = async () => {
|
||||||
|
await nextTick()
|
||||||
|
if (!menuRef.value || !menuContainer.value) return
|
||||||
|
|
||||||
|
const menuItems = menuRef.value.$el.querySelectorAll('.el-menu-item, .el-sub-menu')
|
||||||
|
let totalWidth = 0
|
||||||
|
|
||||||
|
menuItems.forEach(item => {
|
||||||
|
totalWidth += item.offsetWidth
|
||||||
|
})
|
||||||
|
|
||||||
|
const containerWidth = menuContainer.value.offsetWidth
|
||||||
|
shouldEllipsis.value = totalWidth > containerWidth
|
||||||
|
}
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (route.name === 'Iframe') {
|
if (route.name === 'Iframe') {
|
||||||
active.value = decodeURIComponent(route.query.url)
|
active.value = decodeURIComponent(route.query.url)
|
||||||
|
|
@ -53,10 +76,24 @@
|
||||||
} else {
|
} else {
|
||||||
isCollapse.value = false
|
isCollapse.value = false
|
||||||
}
|
}
|
||||||
|
// 设备变化时重新计算
|
||||||
|
calculateEllipsis()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 当路由变化时重新计算
|
||||||
|
watchEffect(() => {
|
||||||
|
if (route.name) {
|
||||||
|
nextTick(calculateEllipsis)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
provide('isCollapse', isCollapse)
|
provide('isCollapse', isCollapse)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
calculateEllipsis()
|
||||||
|
window.addEventListener('resize', calculateEllipsis)
|
||||||
|
})
|
||||||
|
|
||||||
const selectMenuItem = (index) => {
|
const selectMenuItem = (index) => {
|
||||||
const query = {}
|
const query = {}
|
||||||
const params = {}
|
const params = {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue