当菜单内容超长时(当前默认阈值8个字符),显示tooltip,暂时只修改了左侧菜单混合模式,其他未调整

This commit is contained in:
xiaocp2009 2025-09-29 10:11:04 +08:00
parent c70968ecd2
commit 9997fd7fa3

View File

@ -12,6 +12,8 @@ import { $t } from '@/locales';
import { useMenu, useMixMenuContext } from '../../../context';
import FirstLevelMenu from '../components/first-level-menu.vue';
import GlobalLogo from '../../global-logo/index.vue';
import { h } from 'vue';
import { NTooltip} from 'naive-ui';
defineOptions({
name: 'VerticalMixMenu'
@ -67,6 +69,50 @@ function updateExpandedKeys() {
expandedKeys.value = routeStore.getSelectedMenuKeyPath(selectedKey.value);
}
// Tooltip
const renderMenuLabel = (option: any) => {
if (option.children) {
return h('span', option.label);
}
const MAX_LENGTH = 8; // ,8Tooltip
const needsTooltip = option.label && option.label.length > MAX_LENGTH;
if (!needsTooltip) {
return h('span', {
style: {
display: 'inline-block',
maxWidth: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}
}, option.label);
}
return h(
NTooltip,
{
placement: 'right',// ,
trigger: 'hover',
style: { maxWidth: '300px' }
},
{
trigger: () => h('span', {
style: {
display: 'inline-block',
maxWidth: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
verticalAlign: 'bottom'
}
}, option.label),
default: () => option.label
}
);
};
watch(
() => route.name,
() => {
@ -116,6 +162,7 @@ watch(
:options="childLevelMenus"
:inverted="inverted"
:indent="18"
:render-label="renderMenuLabel"
@update:value="routerPushByKeyWithMetaQuery"
/>
</SimpleScrollbar>