mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 11:58:10 +08:00
This reverts commit f81d18c7c8
.
This commit is contained in:
parent
55b638befb
commit
045a35016c
@ -961,9 +961,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
> .#{$ns}Table-fixedTop {
|
> .#{$ns}Table-fixedTop {
|
||||||
.#{$ns}Table-fixedTop-shadow {
|
display: none;
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
> .#{$ns}Table-footToolbar {
|
> .#{$ns}Table-footToolbar {
|
||||||
|
@ -616,7 +616,6 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const {autoFillHeight, classPrefix: ns} = this.props;
|
|
||||||
const currentNode = findDOMNode(this) as HTMLElement;
|
const currentNode = findDOMNode(this) as HTMLElement;
|
||||||
// 获取小于所有子元素高度之和的父元素
|
// 获取小于所有子元素高度之和的父元素
|
||||||
let parent: HTMLElement | Window | null = getScrollParent(
|
let parent: HTMLElement | Window | null = getScrollParent(
|
||||||
@ -643,11 +642,6 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
|
|
||||||
this.affixDetect();
|
this.affixDetect();
|
||||||
parent.addEventListener('scroll', this.affixDetect);
|
parent.addEventListener('scroll', this.affixDetect);
|
||||||
if (autoFillHeight) {
|
|
||||||
document
|
|
||||||
.querySelector<HTMLElement>(`.${ns}Table-content`)!
|
|
||||||
.addEventListener('scroll', this.affixDetect);
|
|
||||||
}
|
|
||||||
window.addEventListener('resize', this.affixDetect);
|
window.addEventListener('resize', this.affixDetect);
|
||||||
this.updateAutoFillHeight();
|
this.updateAutoFillHeight();
|
||||||
window.addEventListener('resize', this.updateAutoFillHeight);
|
window.addEventListener('resize', this.updateAutoFillHeight);
|
||||||
@ -822,15 +816,10 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
const {formItem, autoFillHeight, classPrefix: ns} = this.props;
|
const {formItem} = this.props;
|
||||||
|
|
||||||
const parent = this.parentNode;
|
const parent = this.parentNode;
|
||||||
parent && parent.removeEventListener('scroll', this.affixDetect);
|
parent && parent.removeEventListener('scroll', this.affixDetect);
|
||||||
if (autoFillHeight) {
|
|
||||||
document
|
|
||||||
.querySelector<HTMLElement>(`.${ns}Table-content`)!
|
|
||||||
.addEventListener('scroll', this.affixDetect);
|
|
||||||
}
|
|
||||||
window.removeEventListener('resize', this.affixDetect);
|
window.removeEventListener('resize', this.affixDetect);
|
||||||
window.removeEventListener('resize', this.updateAutoFillHeight);
|
window.removeEventListener('resize', this.updateAutoFillHeight);
|
||||||
(this.updateTableInfoLazy as any).cancel();
|
(this.updateTableInfoLazy as any).cancel();
|
||||||
@ -1071,81 +1060,44 @@ export default class Table extends React.Component<TableProps, object> {
|
|||||||
|
|
||||||
return store.selectedRows.map(item => item.data);
|
return store.selectedRows.map(item => item.data);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 滚动重新定位Table-fixedTop
|
|
||||||
*/
|
|
||||||
affixDetect() {
|
|
||||||
const {
|
|
||||||
affixHeader,
|
|
||||||
classPrefix: ns,
|
|
||||||
affixOffsetTop,
|
|
||||||
env,
|
|
||||||
autoFillHeight
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
if (!(affixHeader || autoFillHeight) || !this.table) {
|
affixDetect() {
|
||||||
// if (!this.props.affixHeader || !this.table || this.props.autoFillHeight) {
|
if (!this.props.affixHeader || !this.table || this.props.autoFillHeight) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ns = this.props.classPrefix;
|
||||||
const dom = findDOMNode(this) as HTMLElement;
|
const dom = findDOMNode(this) as HTMLElement;
|
||||||
|
const clip = (this.table as HTMLElement).getBoundingClientRect();
|
||||||
|
const offsetY =
|
||||||
|
this.props.affixOffsetTop ?? this.props.env.affixOffsetTop ?? 0;
|
||||||
|
const headingHeight =
|
||||||
|
dom.querySelector(`.${ns}Table-heading`)?.getBoundingClientRect()
|
||||||
|
.height || 0;
|
||||||
const headerHeight =
|
const headerHeight =
|
||||||
dom.querySelector(`.${ns}Table-headToolbar`)?.getBoundingClientRect()
|
dom.querySelector(`.${ns}Table-headToolbar`)?.getBoundingClientRect()
|
||||||
.height || 0;
|
.height || 0;
|
||||||
|
|
||||||
|
const affixed =
|
||||||
|
clip.top - headerHeight - headingHeight < offsetY &&
|
||||||
|
clip.top + clip.height - 40 > offsetY;
|
||||||
const affixedDom = dom.querySelector(`.${ns}Table-fixedTop`) as HTMLElement;
|
const affixedDom = dom.querySelector(`.${ns}Table-fixedTop`) as HTMLElement;
|
||||||
|
const affixedShadowDom = dom.querySelector(
|
||||||
|
`.${ns}Table-fixedTop-shadow`
|
||||||
|
) as HTMLElement;
|
||||||
const affixedDomHeight =
|
const affixedDomHeight =
|
||||||
getComputedStyle(affixedDom).getPropertyValue('height');
|
getComputedStyle(affixedDom).getPropertyValue('height');
|
||||||
|
|
||||||
if (autoFillHeight) {
|
affixedDom.style.cssText += `top: ${offsetY}px;width: ${
|
||||||
//! 解决 sticky 不兼容的问题
|
(this.table.parentNode as HTMLElement).offsetWidth
|
||||||
const tableContentDom = document.querySelector<HTMLElement>(
|
}px`;
|
||||||
`.${ns}Table-content`
|
affixedShadowDom.style.cssText += `top: ${affixedDomHeight};width: ${
|
||||||
)!;
|
(this.table.parentNode as HTMLElement).offsetWidth
|
||||||
const clip = tableContentDom.getBoundingClientRect();
|
}px`;
|
||||||
|
|
||||||
const tableHeaderClip = affixedDom
|
|
||||||
.querySelector(`.${ns}Table-wrapper`)!
|
|
||||||
.getBoundingClientRect();
|
|
||||||
const offsetHeight =
|
|
||||||
affixedDom.getBoundingClientRect().height - tableHeaderClip.height;
|
|
||||||
const offsetY = clip.top - offsetHeight;
|
|
||||||
|
|
||||||
affixedDom.style.cssText += `top: ${offsetY}px;width: ${clip.width}px`;
|
|
||||||
|
|
||||||
affixedDom.classList.add('in');
|
|
||||||
} else {
|
|
||||||
// 配置了 affixHeader
|
|
||||||
const clip = (this.table as HTMLElement).getBoundingClientRect();
|
|
||||||
const offsetY = affixOffsetTop ?? env.affixOffsetTop ?? 0;
|
|
||||||
const headingHeight =
|
|
||||||
dom.querySelector(`.${ns}Table-heading`)?.getBoundingClientRect()
|
|
||||||
.height || 0;
|
|
||||||
const affixedShadowDom = dom.querySelector(
|
|
||||||
`.${ns}Table-fixedTop-shadow`
|
|
||||||
) as HTMLElement;
|
|
||||||
const affixed =
|
|
||||||
clip.top - headerHeight - headingHeight < offsetY &&
|
|
||||||
clip.top + clip.height - 40 > offsetY;
|
|
||||||
|
|
||||||
affixedDom.style.cssText += `top: ${offsetY}px;width: ${
|
|
||||||
(this.table.parentNode as HTMLElement).offsetWidth
|
|
||||||
}px`;
|
|
||||||
affixedShadowDom.style.cssText += `top: ${affixedDomHeight};width: ${
|
|
||||||
(this.table.parentNode as HTMLElement).offsetWidth
|
|
||||||
}px`;
|
|
||||||
|
|
||||||
const preStatus = affixedDom.classList.contains('in');
|
|
||||||
|
|
||||||
affixed
|
|
||||||
? affixedDom.classList.add('in')
|
|
||||||
: affixedDom.classList.remove('in');
|
|
||||||
|
|
||||||
// 出现affixHeader时重新计算列表宽度
|
|
||||||
if (!preStatus && affixed) {
|
|
||||||
this.updateTableInfoLazy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
affixed
|
||||||
|
? affixedDom.classList.add('in')
|
||||||
|
: affixedDom.classList.remove('in');
|
||||||
// store.markHeaderAffix(clip.top < offsetY && (clip.top + clip.height - 40) > offsetY);
|
// store.markHeaderAffix(clip.top < offsetY && (clip.top + clip.height - 40) > offsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user