From ab9fb263ee01b569445cafc57e3afad5ac9b2daa Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 1 Dec 2026 16:09:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E6=9B=B4=E5=A4=9A=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=94=B6=E7=BA=B3=E9=A1=B9=E5=B1=95=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E6=A1=88=E5=B9=B6=E5=8E=BB=E6=8E=89=E6=82=AC=E6=B5=AE=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- packages/editor/src/layouts/NavMenuColumn.vue | 9 ++- .../tests/unit/layouts/NavMenuColumn.spec.ts | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/layouts/NavMenuColumn.vue b/packages/editor/src/layouts/NavMenuColumn.vue index 07a131f3..9d73ab52 100644 --- a/packages/editor/src/layouts/NavMenuColumn.vue +++ b/packages/editor/src/layouts/NavMenuColumn.vue @@ -112,10 +112,17 @@ const hiddenIndexSet = ref>(new Set()); const hasOverflow = computed(() => hiddenIndexSet.value.size > 0); // 更多菜单是纵向列表:分割线改成横线;收进去的首尾分割线没有分组意义,直接去掉。 +// 收进去的项统一展示文案:有 text 用 text,没有则用 tooltip,不再挂悬浮提示。 const overflowItems = computed(() => { const items = props.items .filter((_, index) => hiddenIndexSet.value.has(index)) - .map((item) => (item.type === 'divider' ? { ...item, direction: 'horizontal' as const } : item)); + .map((item) => { + if (item.type === 'divider') { + return { ...item, direction: 'horizontal' as const }; + } + if (item.type === 'component') return item; + return { ...item, text: item.text || item.tooltip, tooltip: undefined }; + }); let start = 0; let end = items.length; diff --git a/packages/editor/tests/unit/layouts/NavMenuColumn.spec.ts b/packages/editor/tests/unit/layouts/NavMenuColumn.spec.ts index 68681124..539c1311 100644 --- a/packages/editor/tests/unit/layouts/NavMenuColumn.spec.ts +++ b/packages/editor/tests/unit/layouts/NavMenuColumn.spec.ts @@ -23,6 +23,7 @@ vi.mock('@editor/components/ToolButton.vue', () => ({ ref: rootEl, class: ['tool-btn', (props.data as any)?.className, (props.data as any)?.type], 'data-direction': (props.data as any)?.direction || '', + 'data-tooltip': (props.data as any)?.tooltip || '', }, (props.data as any)?.text || '', ); @@ -415,6 +416,65 @@ describe('NavMenuColumn', () => { wrapper.unmount(); }); + test('更多菜单有 text 时展示 text,没有 text 时展示 tooltip', async () => { + const items = [ + { type: 'button', text: 'A' }, + { type: 'button', className: 'save', text: '保存', tooltip: '保存到本地' }, + { type: 'button', className: 'src', tooltip: '源码' }, + ]; + + const wrapper = mount(NavMenuColumn as any, { + props: { columnKey: 'right', items, width: 80 }, + attachTo: document.body, + }); + + const columnEl = wrapper.find('.m-editor-nav-menu-column').element as HTMLElement; + Object.defineProperty(columnEl, 'clientWidth', { configurable: true, get: () => 80 }); + + const moreEl = wrapper.find('.m-editor-nav-menu-more-wrapper').element as HTMLElement; + moreEl.getBoundingClientRect = () => ({ + width: 30, + height: 0, + top: 0, + left: 0, + right: 0, + bottom: 0, + x: 0, + y: 0, + toJSON: () => ({}), + }); + + wrapper.findAll('.tool-btn').forEach((b) => { + const el = b.element as HTMLElement; + el.getBoundingClientRect = () => ({ + width: 40, + height: 0, + top: 0, + left: 0, + right: 0, + bottom: 0, + x: 0, + y: 0, + toJSON: () => ({}), + }); + }); + + roCallbacks.forEach((cb) => cb()); + await flushRaf(); + await flushRaf(); + + const overflow = wrapper.find('.m-editor-nav-menu-overflow-list'); + expect(overflow.find('.save').text()).toBe('保存'); + expect(overflow.find('.save').attributes('data-tooltip')).toBe(''); + expect(overflow.find('.src').text()).toBe('源码'); + expect(overflow.find('.src').attributes('data-tooltip')).toBe(''); + + expect(wrapper.find('.m-editor-nav-menu-column > .save').attributes('data-tooltip')).toBe('保存到本地'); + expect(wrapper.find('.m-editor-nav-menu-column > .src').attributes('data-tooltip')).toBe('源码'); + + wrapper.unmount(); + }); + test('更多菜单首尾的分割线会被去掉,中间的分割线保留', async () => { const items = [ { type: 'button', text: 'A' },