diff --git a/packages/amis-core/src/store/table.ts b/packages/amis-core/src/store/table.ts index 89123a711..1305208c1 100644 --- a/packages/amis-core/src/store/table.ts +++ b/packages/amis-core/src/store/table.ts @@ -528,7 +528,8 @@ export const TableStore = iRendererStore exportExcelLoading: false, searchFormExpanded: false, // 用来控制搜索框是否展开了,那个自动根据 searchable 生成的表单 autoGenerateFilter lazyRenderAfter: 100, - tableLayout: 'auto' + tableLayout: 'auto', + theadHeight: 0 }) .views(self => { function getColumnsExceptBuiltinTypes() { @@ -1001,7 +1002,7 @@ export const TableStore = iRendererStore }, buildStyles(style: any) { - style = {...style}; + style = {...style, '--Table-thead-height': self.theadHeight + 'px'}; getFilteredColumns().forEach(column => { style[`--Table-column-${column.index}-width`] = @@ -1295,9 +1296,9 @@ export const TableStore = iRendererStore if (!table) { return; } - const cols = [].slice.call( - table.querySelectorAll(':scope>thead>tr>th[data-index]') - ); + const thead = table.querySelector(':scope>thead') as HTMLElement; + const cols = [].slice.call(thead.querySelectorAll('tr>th[data-index]')); + self.theadHeight = thead.offsetHeight; cols.forEach((col: HTMLElement) => { const index = parseInt(col.getAttribute('data-index')!, 10); const column = self.columns[index]; diff --git a/packages/amis-ui/scss/components/_table.scss b/packages/amis-ui/scss/components/_table.scss index 8ec35a319..95c280978 100644 --- a/packages/amis-ui/scss/components/_table.scss +++ b/packages/amis-ui/scss/components/_table.scss @@ -273,8 +273,12 @@ padding-top: 0; } - &--affixHeader > thead { - visibility: collapse; + &--affixHeader { + margin-top: calc(var(--Table-thead-height) * -1); + + > thead { + visibility: hidden; + } } &--withCombine { diff --git a/packages/amis/__tests__/event-action/renderers/__snapshots__/crud.test.tsx.snap b/packages/amis/__tests__/event-action/renderers/__snapshots__/crud.test.tsx.snap index 92e7c7509..c6ebf2d0f 100644 --- a/packages/amis/__tests__/event-action/renderers/__snapshots__/crud.test.tsx.snap +++ b/packages/amis/__tests__/event-action/renderers/__snapshots__/crud.test.tsx.snap @@ -28,7 +28,7 @@ exports[`doAction:crud reload 1`] = ` >
{ document.addEventListener('mousemove', this.handleColResizeMouseMove); document.addEventListener('mouseup', this.handleColResizeMouseUp); + + // 防止选中文本 + e.preventDefault(); + e.stopPropagation(); } // 垂直线拖拽移动