Skip to content

Commit

Permalink
chore: 兼容异常数据 (#8923)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop authored Nov 29, 2023
1 parent abcf0ed commit 2c05f9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
23 changes: 19 additions & 4 deletions packages/amis/src/renderers/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {CardProps, CardSchema} from './Card';
import {Card2Props, Card2Schema} from './Card2';
import type {IItem} from 'amis-core';
import find from 'lodash/find';

/**
* Cards 卡片集合渲染器。
Expand Down Expand Up @@ -496,11 +497,25 @@ export default class Cards extends React.Component<GridProps, object> {
store.reset();
}

bulkUpdate(value: object, items: Array<object>) {
const {store} = this.props;
bulkUpdate(value: any, items: Array<object>) {
// const {store} = this.props;

// const items2 = store.items.filter(item => ~items.indexOf(item.pristine));
// items2.forEach(item => item.change(value));

const {store, primaryField} = this.props;

const items2 = store.items.filter(item => ~items.indexOf(item.pristine));
items2.forEach(item => item.change(value));
if (primaryField && value.ids) {
const ids = value.ids.split(',');
const rows = store.items.filter(item =>
find(ids, (id: any) => id && id == item.data[primaryField])
);
const newValue = {...value, ids: undefined};
rows.forEach(item => item.change(newValue));
} else if (Array.isArray(items)) {
const rows = store.items.filter(item => ~items.indexOf(item.pristine));
rows.forEach(item => item.change(value));
}
}

getSelected() {
Expand Down
23 changes: 19 additions & 4 deletions packages/amis/src/renderers/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {ActionSchema} from './Action';
import {SchemaRemark} from './Remark';
import type {IItem} from 'amis-core';
import type {OnEventProps} from 'amis-core';
import find from 'lodash/find';

/**
* 不指定类型默认就是文本
Expand Down Expand Up @@ -560,11 +561,25 @@ export default class List extends React.Component<ListProps, object> {
store.reset();
}

bulkUpdate(value: object, items: Array<object>) {
const {store} = this.props;
bulkUpdate(value: any, items: Array<object>) {
// const {store} = this.props;

// const items2 = store.items.filter(item => ~items.indexOf(item.pristine));
// items2.forEach(item => item.change(value));

const {store, primaryField} = this.props;

const items2 = store.items.filter(item => ~items.indexOf(item.pristine));
items2.forEach(item => item.change(value));
if (primaryField && value.ids) {
const ids = value.ids.split(',');
const rows = store.items.filter(item =>
find(ids, (id: any) => id && id == item.data[primaryField])
);
const newValue = {...value, ids: undefined};
rows.forEach(item => item.change(newValue));
} else if (Array.isArray(items)) {
const rows = store.items.filter(item => ~items.indexOf(item.pristine));
rows.forEach(item => item.change(value));
}
}

getSelected() {
Expand Down
2 changes: 1 addition & 1 deletion packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ export default class Table extends React.Component<TableProps, object> {
);
const newValue = {...value, ids: undefined};
rows.forEach(row => row.change(newValue));
} else {
} else if (Array.isArray(items)) {
const rows = store.rows.filter(item => ~items.indexOf(item.pristine));
rows.forEach(row => row.change(value));
}
Expand Down

0 comments on commit 2c05f9c

Please sign in to comment.