Skip to content

Commit

Permalink
feat: CRUD 的自动撑开功能支持编辑器切换及时生效 (#11513)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop authored Jan 16, 2025
1 parent e62d9e2 commit 79fcf97
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,17 +790,7 @@ export default class Table<
componentDidMount() {
const currentNode = this.dom.current!;

if (this.props.autoFillHeight) {
this.toDispose.push(
resizeSensor(
currentNode.parentElement!,
this.updateAutoFillHeightLazy,
false,
'height'
)
);
this.updateAutoFillHeight();
}
this.initAutoFillHeight();

// todo 因为没有监控里面内容的宽度变化,所以单元格内容变化撑开时可能看不到 fixed 的阴影
// 应该加上 table 的宽度检测
Expand Down Expand Up @@ -851,6 +841,23 @@ export default class Table<
}
}

autoFillHeightDispose?: () => void;
initAutoFillHeight() {
const props = this.props;
const currentNode = this.dom.current!;

if (props.autoFillHeight) {
this.autoFillHeightDispose = resizeSensor(
currentNode.parentElement!,
this.updateAutoFillHeightLazy,
false,
'height'
);
this.toDispose.push(this.autoFillHeightDispose);
this.updateAutoFillHeight();
}
}

/**
* 自动设置表格高度占满界面剩余区域
* 用 css 实现有点麻烦,要改很多结构,所以先用 dom hack 了,避免对之前的功能有影响
Expand Down Expand Up @@ -1025,13 +1032,32 @@ export default class Table<
this.syncSelected();
}
}

// 检测属性变化,来切换功能
if (props.autoFillHeight !== prevProps.autoFillHeight) {
if (this.autoFillHeightDispose) {
const idx = this.toDispose.indexOf(this.autoFillHeightDispose);
if (idx !== -1) {
this.toDispose.splice(idx, 1);
}
this.autoFillHeightDispose();
delete this.autoFillHeightDispose;
const tableContent = this.table?.parentElement as HTMLElement;
if (tableContent) {
tableContent.style.height = '';
}
}

this.initAutoFillHeight();
}
}

componentWillUnmount() {
const {formItem} = this.props;

this.toDispose.forEach(fn => fn());
this.toDispose = [];
delete this.autoFillHeightDispose;

this.updateTableInfoLazy.cancel();
this.updateAutoFillHeightLazy.cancel();
Expand Down

0 comments on commit 79fcf97

Please sign in to comment.