diff --git a/packages/amis-core/src/store/iRenderer.ts b/packages/amis-core/src/store/iRenderer.ts index 741660fd782..c56af429ecc 100644 --- a/packages/amis-core/src/store/iRenderer.ts +++ b/packages/amis-core/src/store/iRenderer.ts @@ -22,6 +22,7 @@ import {DataChangeReason} from '../types'; export const iRendererStore = StoreNode.named('iRendererStore') .props({ + crudId: types.optional(types.string, ''), hasRemoteData: types.optional(types.boolean, false), data: types.optional(types.frozen(), {}), initedAt: 0, // 初始 init 的时刻 diff --git a/packages/amis-core/src/store/table.ts b/packages/amis-core/src/store/table.ts index 2ec945b03c1..c6a4d16b0cc 100644 --- a/packages/amis-core/src/store/table.ts +++ b/packages/amis-core/src/store/table.ts @@ -810,8 +810,13 @@ export const TableStore = iRendererStore return { getSelectionUpperLimit, + // 前端列缓存,必须有crud的id作为标识,否则会导致读取的缓存列数据错误 get columnsKey() { - return location.pathname + self.path; + return ( + location.pathname + + self.path + + `${self.crudId ? '?' + self.crudId : ''}` + ); }, get columnsData() { @@ -1072,6 +1077,11 @@ export const TableStore = iRendererStore resolveDefinitions?: (ref: string) => any; } ) { + // 更换为crud组件的id, id赋值后就不能为空,否则缓存列配置会丢失 + if (!self.crudId) { + self.crudId = config.crudId || ''; + } + config.primaryField !== undefined && (self.primaryField = config.primaryField); config.selectable !== undefined && (self.selectable = config.selectable); diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index b78749b281a..7afac5c7c95 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -605,6 +605,7 @@ export default class Table extends React.Component { this.updateAutoFillHeight = this.updateAutoFillHeight.bind(this); const { + id, store, columns, selectable, @@ -643,6 +644,7 @@ export default class Table extends React.Component { store.update( { + crudId: id, selectable, draggable, columns, @@ -859,11 +861,19 @@ export default class Table extends React.Component { let nextSiblingHeight = 0; let nextSibling = selfNode.nextElementSibling as HTMLElement; while (nextSibling) { - const positon = getComputedStyle(nextSibling).position; - if (positon !== 'absolute' && positon !== 'fixed') { - nextSiblingHeight += - nextSibling.offsetHeight + - getStyleNumber(nextSibling, 'margin-bottom'); + //TODO 这里先做容器组件的兼容处理,希望大佬们能优化一下 + // 如果下一个兄弟节点不是 cxd-Container,cxd-Grid-col--xxx2种容器,则计算下一个兄弟节点的高度 + let classString = Array.from(nextSibling.classList).join(','); + if ( + classString.indexOf(`${ns}Container`) < 0 && + classString.indexOf(`${ns}Grid-col--`) < 0 + ) { + const positon = getComputedStyle(nextSibling).position; + if (positon !== 'absolute' && positon !== 'fixed') { + nextSiblingHeight += + nextSibling.offsetHeight + + getStyleNumber(nextSibling, 'margin-bottom'); + } } nextSibling = nextSibling.nextElementSibling as HTMLElement; @@ -2860,7 +2870,6 @@ export default class Table extends React.Component { const tableClassName = cx('Table-table', this.props.tableClassName, { 'Table-table--withCombine': store.combineNum > 0 }); - return (