Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20220816 feature table #1316

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/table/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,19 @@ export default defineComponent({
const affixHeaderHeight = (this.affixHeaderRef?.getBoundingClientRect().height || 0) - IEHeaderWrap;
const affixHeaderWrapHeight = affixHeaderHeight - barWidth - borderWidth;
// 两类场景:1. 虚拟滚动,永久显示表头,直到表头消失在可视区域; 2. 表头吸顶,根据滚动情况判断是否显示吸顶表头
const headerOpacity = props.headerAffixedTop ? Number(this.showAffixHeader) : 1;
const headerOpacity = this.headerAffixedTop ? Number(this.showAffixHeader) : 1;
const affixHeaderWrapHeightStyle = {
width: `${this.tableWidth}px`,
height: `${affixHeaderWrapHeight}px`,
opacity: headerOpacity,
marginTop: onlyVirtualScrollBordered ? `${borderWidth}px` : 0,
};
// 多级表头左边线缺失
const affixedMultipleHeaderLeftBorder = this.bordered && this.isMultipleHeader ? 1 : 0;
const affixedLeftBorder = this.bordered ? 1 : 0;
const affixedHeader = Boolean((this.headerAffixedTop || this.isVirtual) && this.tableWidth) && (
<div
ref="affixHeaderRef"
style={{ width: `${this.tableWidth - affixedMultipleHeaderLeftBorder}px`, opacity: headerOpacity }}
style={{ width: `${this.tableWidth - affixedLeftBorder}px`, opacity: headerOpacity }}
class={['scrollbar', { [this.tableBaseClass.affixedHeaderElm]: this.headerAffixedTop || this.isVirtual }]}
>
<table class={this.tableElmClasses} style={{ ...this.tableElementStyles, width: `${this.tableElmWidth}px` }}>
Expand Down Expand Up @@ -383,7 +383,7 @@ export default defineComponent({
>
<div
ref="affixFooterRef"
style={{ width: `${this.tableWidth}px`, opacity: Number(this.showAffixFooter) }}
style={{ width: `${this.tableWidth - affixedLeftBorder}px`, opacity: Number(this.showAffixFooter) }}
class={['scrollbar', { [this.tableBaseClass.affixedFooterElm]: this.footerAffixedBottom || this.isVirtual }]}
>
<table class={this.tableElmClasses} style={{ ...this.tableElementStyles, width: `${this.tableElmWidth}px` }}>
Expand Down
20 changes: 10 additions & 10 deletions src/table/hooks/useFixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ComputedRef,
} from '@vue/composition-api';
import get from 'lodash/get';
import debounce from 'lodash/debounce';
import log from '../../_common/js/log';
import { ClassName, Styles } from '../../common';
import { BaseTableCol, TableRowData, TdBaseTableProps } from '../type';
Expand Down Expand Up @@ -302,11 +303,11 @@ export default function useFixed(
};

let shadowLastScrollLeft: number;
const updateColumnFixedShadow = (target: HTMLElement) => {
if (!isFixedColumn.value || !target) return;
const updateColumnFixedShadow = (target: HTMLElement, extra?: { skipScrollLimit?: boolean }) => {
if (!isFixedColumn || !target) return;
const { scrollLeft } = target;
// 只有左右滚动,需要更新固定列阴影
if (shadowLastScrollLeft === scrollLeft) return;
if (shadowLastScrollLeft === scrollLeft && (!extra || !extra.skipScrollLimit)) return;
shadowLastScrollLeft = scrollLeft;
const isShowRight = target.clientWidth + scrollLeft < target.scrollWidth;
showColumnShadow.left = scrollLeft > 0;
Expand Down Expand Up @@ -479,15 +480,15 @@ export default function useFixed(
{ immediate: true },
);

const refreshTable = () => {
const refreshTable = debounce(() => {
updateTableWidth();
updateFixedHeader();
updateThWidthListHandler();
if (isFixedColumn.value || isFixedHeader.value) {
updateFixedStatus();
updateColumnFixedShadow(tableContentRef.value);
updateColumnFixedShadow(tableContentRef.value, { skipScrollLimit: true });
}
};
}, 30);

const onResize = refreshTable;

Expand All @@ -501,15 +502,14 @@ export default function useFixed(
}
clearTimeout(timer);
});
if (isFixedColumn.value || isFixedHeader.value || !notNeedThWidthList.value) {
const isWatchResize = isFixedColumn.value || isFixedHeader.value || !notNeedThWidthList.value || !data.value.length;
if (isWatchResize) {
on(window, 'resize', onResize);
}
});

onBeforeMount(() => {
if (isFixedColumn.value || isFixedHeader.value || !notNeedThWidthList.value) {
off(window, 'resize', onResize);
}
off(window, 'resize', onResize);
});

const setData = (dataSource: TableRowData[]) => {
Expand Down