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

fix: 调整 table 的本地存储策略,增加id区分不同页面的表格列缓存,修复#10983 #11053

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/amis-core/src/store/iRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 的时刻
Expand Down
12 changes: 11 additions & 1 deletion packages/amis-core/src/store/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 15 additions & 6 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ export default class Table extends React.Component<TableProps, object> {
this.updateAutoFillHeight = this.updateAutoFillHeight.bind(this);

const {
id,
store,
columns,
selectable,
Expand Down Expand Up @@ -643,6 +644,7 @@ export default class Table extends React.Component<TableProps, object> {

store.update(
{
crudId: id,
selectable,
draggable,
columns,
Expand Down Expand Up @@ -859,11 +861,19 @@ export default class Table extends React.Component<TableProps, object> {
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;
Expand Down Expand Up @@ -2860,7 +2870,6 @@ export default class Table extends React.Component<TableProps, object> {
const tableClassName = cx('Table-table', this.props.tableClassName, {
'Table-table--withCombine': store.combineNum > 0
});

return (
<div
ref={this.dom}
Expand Down
Loading