From 90e4bec70b25194446b6b7c8453ac7c9dc32bff3 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 1 Sep 2026 15:09:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(form):=20=E9=81=BF=E5=85=8D=20Tooltip=20?= =?UTF-8?q?=E6=97=A0=E5=90=88=E6=B3=95=E8=A7=A6=E5=8F=91=E5=99=A8=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=20ElOnlyChild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对比模式删除按钮与表格未就绪时,ElTooltip 默认插槽会变成 Comment,触发 Element Plus 警告。 --- packages/design/src/Tooltip.vue | 36 +++++++++++++++++-- .../form/src/containers/GroupListItem.vue | 4 +-- packages/form/src/containers/table/Table.vue | 3 +- .../tests/unit/containers/GroupList.spec.ts | 8 ++++- .../form/tests/unit/containers/Table.spec.ts | 12 ++++++- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/packages/design/src/Tooltip.vue b/packages/design/src/Tooltip.vue index 6afbc530..2a3716fd 100644 --- a/packages/design/src/Tooltip.vue +++ b/packages/design/src/Tooltip.vue @@ -1,5 +1,11 @@ diff --git a/packages/form/src/containers/GroupListItem.vue b/packages/form/src/containers/GroupListItem.vue index 35582591..371f81f4 100644 --- a/packages/form/src/containers/GroupListItem.vue +++ b/packages/form/src/containers/GroupListItem.vue @@ -80,9 +80,9 @@ - + +
+ { expect(item.props('model')).toEqual({}); }); - test('对比模式隐藏底部操作栏与复制/移动按钮', async () => { + test('对比模式隐藏底部操作栏与复制/移动/删除按钮,且不触发 ElOnlyChild 警告', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); const wrapper = mountForm( compareConfig, { list: [{ text: 'a' }, { text: 'b' }] }, @@ -192,9 +193,14 @@ describe('GroupList container', () => { await nextTick(); await nextTick(); expect(wrapper.find('.m-fields-group-list-footer').exists()).toBe(false); + expect(wrapper.find('.delete-button').exists()).toBe(false); expect(wrapper.text()).not.toContain('复制'); expect(wrapper.text()).not.toContain('上移'); expect(wrapper.text()).not.toContain('下移'); + expect( + warn.mock.calls.some((args) => args.some((arg) => String(arg?.message ?? arg).includes('ElOnlyChild'))), + ).toBe(false); + warn.mockRestore(); }); }); diff --git a/packages/form/tests/unit/containers/Table.spec.ts b/packages/form/tests/unit/containers/Table.spec.ts index 81f17dff..62e20ddc 100644 --- a/packages/form/tests/unit/containers/Table.spec.ts +++ b/packages/form/tests/unit/containers/Table.spec.ts @@ -3,7 +3,7 @@ * * Copyright (C) 2025 Tencent. */ -import { describe, expect, test } from 'vitest'; +import { describe, expect, test, vi } from 'vitest'; import { nextTick } from 'vue'; import { mount } from '@vue/test-utils'; import ElementPlus from 'element-plus'; @@ -41,4 +41,14 @@ describe('Table container —— 对比模式', () => { await nextTick(); expect(wrapper.text()).not.toContain('清空'); }); + + test('model 为空时不渲染表格,且不触发 ElOnlyChild 警告', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + mountTable({ model: { list: undefined } }); + await nextTick(); + expect( + warn.mock.calls.some((args) => args.some((arg) => String(arg?.message ?? arg).includes('ElOnlyChild'))), + ).toBe(false); + warn.mockRestore(); + }); });