mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 21:49:09 +08:00
修复 picker 没有保持用户选择顺序问题
This commit is contained in:
parent
160848fa22
commit
40d35e3010
@ -26,6 +26,7 @@ import {evalExpression, filter} from '../utils/tpl';
|
|||||||
import {isValidApi, buildApi, isEffectiveApi} from '../utils/api';
|
import {isValidApi, buildApi, isEffectiveApi} from '../utils/api';
|
||||||
import omit from 'lodash/omit';
|
import omit from 'lodash/omit';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
|
import findIndex from 'lodash/findIndex';
|
||||||
import Html from '../components/Html';
|
import Html from '../components/Html';
|
||||||
import {Spinner} from '../components';
|
import {Spinner} from '../components';
|
||||||
|
|
||||||
@ -996,18 +997,57 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
|||||||
let newUnSelectedItems = unSelectedItems;
|
let newUnSelectedItems = unSelectedItems;
|
||||||
|
|
||||||
if (keepItemSelectionOnPageChange && store.selectedItems.length) {
|
if (keepItemSelectionOnPageChange && store.selectedItems.length) {
|
||||||
const thisBatch = items.concat(unSelectedItems);
|
const oldItems = store.selectedItems.concat();
|
||||||
let notInThisBatch = (item: any) =>
|
const oldUnselectedItems = store.unSelectedItems.concat();
|
||||||
!find(
|
|
||||||
thisBatch,
|
items.forEach(item => {
|
||||||
|
const idx = findIndex(
|
||||||
|
oldItems,
|
||||||
a => a[primaryField || 'id'] == item[primaryField || 'id']
|
a => a[primaryField || 'id'] == item[primaryField || 'id']
|
||||||
);
|
);
|
||||||
|
|
||||||
newItems = store.selectedItems.filter(notInThisBatch);
|
if (~idx) {
|
||||||
newUnSelectedItems = store.unSelectedItems.filter(notInThisBatch);
|
oldItems[idx] = item;
|
||||||
|
} else {
|
||||||
|
oldItems.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
newItems.push(...items);
|
unSelectedItems.forEach(item => {
|
||||||
newUnSelectedItems.push(...unSelectedItems);
|
const idx = findIndex(
|
||||||
|
oldUnselectedItems,
|
||||||
|
a => a[primaryField || 'id'] == item[primaryField || 'id']
|
||||||
|
);
|
||||||
|
|
||||||
|
const idx2 = findIndex(
|
||||||
|
oldItems,
|
||||||
|
a => a[primaryField || 'id'] == item[primaryField || 'id']
|
||||||
|
);
|
||||||
|
|
||||||
|
if (~idx) {
|
||||||
|
oldUnselectedItems[idx] = item;
|
||||||
|
} else {
|
||||||
|
oldUnselectedItems.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
~idx2 && oldItems.splice(idx2, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
newItems = oldItems;
|
||||||
|
newUnSelectedItems = oldUnselectedItems;
|
||||||
|
|
||||||
|
// const thisBatch = items.concat(unSelectedItems);
|
||||||
|
// let notInThisBatch = (item: any) =>
|
||||||
|
// !find(
|
||||||
|
// thisBatch,
|
||||||
|
// a => a[primaryField || 'id'] == item[primaryField || 'id']
|
||||||
|
// );
|
||||||
|
|
||||||
|
// newItems = store.selectedItems.filter(notInThisBatch);
|
||||||
|
// newUnSelectedItems = store.unSelectedItems.filter(notInThisBatch);
|
||||||
|
|
||||||
|
// newItems.push(...items);
|
||||||
|
// newUnSelectedItems.push(...unSelectedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pickerMode && !multiple && newItems.length > 1) {
|
if (pickerMode && !multiple && newItems.length > 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user