mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 列表选取boolean类型选择错误 (#7328)
This commit is contained in:
parent
0f97e378d9
commit
dbc4da2740
@ -100,6 +100,7 @@ export const ListStore = iRendererStore
|
||||
draggable: false,
|
||||
dragging: false,
|
||||
multiple: true,
|
||||
strictMode: false,
|
||||
selectable: false,
|
||||
itemCheckableOn: '',
|
||||
itemDraggableOn: '',
|
||||
@ -167,6 +168,7 @@ export const ListStore = iRendererStore
|
||||
config.selectable === void 0 || (self.selectable = config.selectable);
|
||||
config.draggable === void 0 || (self.draggable = config.draggable);
|
||||
config.multiple === void 0 || (self.multiple = config.multiple);
|
||||
config.strictMode === void 0 || (self.strictMode = config.strictMode);
|
||||
config.hideCheckToggler === void 0 ||
|
||||
(self.hideCheckToggler = config.hideCheckToggler);
|
||||
|
||||
@ -212,11 +214,13 @@ export const ListStore = iRendererStore
|
||||
if (~selected.indexOf(item.pristine)) {
|
||||
self.selectedItems.push(item);
|
||||
} else if (
|
||||
find(
|
||||
selected,
|
||||
a =>
|
||||
a[valueField || 'value'] == item.pristine[valueField || 'value']
|
||||
)
|
||||
find(selected, a => {
|
||||
const selectValue = a[valueField || 'value'];
|
||||
const itemValue = item.pristine[valueField || 'value'];
|
||||
return self.strictMode
|
||||
? selectValue === itemValue
|
||||
: selectValue == itemValue;
|
||||
})
|
||||
) {
|
||||
self.selectedItems.push(item);
|
||||
}
|
||||
|
@ -185,6 +185,7 @@ export class PickerControlPlugin extends BasePlugin {
|
||||
]
|
||||
},
|
||||
|
||||
getSchemaTpl('strictMode'),
|
||||
getSchemaTpl('multiple'),
|
||||
getSchemaTpl('joinValues'),
|
||||
getSchemaTpl('delimiter'),
|
||||
|
@ -140,6 +140,25 @@ setSchemaTpl('multiple', (schema: any = {}) => {
|
||||
};
|
||||
});
|
||||
|
||||
setSchemaTpl('strictMode', {
|
||||
type: 'switch',
|
||||
label: '严格模式',
|
||||
name: 'strictMode',
|
||||
value: false,
|
||||
mode: 'horizontal',
|
||||
horizontal: {
|
||||
justify: true,
|
||||
left: 8
|
||||
},
|
||||
inputClassName: 'is-inline ',
|
||||
labelRemark: {
|
||||
trigger: ['hover', 'focus'],
|
||||
setting: true,
|
||||
title: '',
|
||||
content: '启用严格模式将采用值严格相等比较'
|
||||
}
|
||||
});
|
||||
|
||||
setSchemaTpl('checkAllLabel', {
|
||||
type: 'input-text',
|
||||
name: 'checkAllLabel',
|
||||
|
@ -1511,6 +1511,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
primaryField,
|
||||
multiple,
|
||||
pickerMode,
|
||||
strictMode,
|
||||
onSelect
|
||||
} = this.props;
|
||||
let newItems = items;
|
||||
@ -1520,14 +1521,20 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
const oldItems = store.selectedItems.concat();
|
||||
const oldUnselectedItems = store.unSelectedItems.concat();
|
||||
|
||||
const isSameValue = (
|
||||
a: Record<string, unknown>,
|
||||
item: Record<string, unknown>
|
||||
) => {
|
||||
const oldValue = a[primaryField || 'id'];
|
||||
const itemValue = item[primaryField || 'id'];
|
||||
const isSame = strictMode
|
||||
? oldValue === itemValue
|
||||
: oldValue == itemValue;
|
||||
return a === item || (oldValue && isSame);
|
||||
};
|
||||
|
||||
items.forEach(item => {
|
||||
const idx = findIndex(
|
||||
oldItems,
|
||||
a =>
|
||||
a === item ||
|
||||
(a[primaryField || 'id'] &&
|
||||
a[primaryField || 'id'] == item[primaryField || 'id'])
|
||||
);
|
||||
const idx = findIndex(oldItems, a => isSameValue(a, item));
|
||||
|
||||
if (~idx) {
|
||||
oldItems[idx] = item;
|
||||
@ -1535,13 +1542,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
oldItems.push(item);
|
||||
}
|
||||
|
||||
const idx2 = findIndex(
|
||||
oldUnselectedItems,
|
||||
a =>
|
||||
a === item ||
|
||||
(a[primaryField || 'id'] &&
|
||||
a[primaryField || 'id'] == item[primaryField || 'id'])
|
||||
);
|
||||
const idx2 = findIndex(oldUnselectedItems, a => isSameValue(a, item));
|
||||
|
||||
if (~idx2) {
|
||||
oldUnselectedItems.splice(idx2, 1);
|
||||
@ -1549,21 +1550,9 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
});
|
||||
|
||||
unSelectedItems.forEach(item => {
|
||||
const idx = findIndex(
|
||||
oldUnselectedItems,
|
||||
a =>
|
||||
a === item ||
|
||||
(a[primaryField || 'id'] &&
|
||||
a[primaryField || 'id'] == item[primaryField || 'id'])
|
||||
);
|
||||
const idx = findIndex(oldUnselectedItems, a => isSameValue(a, item));
|
||||
|
||||
const idx2 = findIndex(
|
||||
oldItems,
|
||||
a =>
|
||||
a === item ||
|
||||
(a[primaryField || 'id'] &&
|
||||
a[primaryField || 'id'] == item[primaryField || 'id'])
|
||||
);
|
||||
const idx2 = findIndex(oldItems, a => isSameValue(a, item));
|
||||
|
||||
if (~idx) {
|
||||
oldUnselectedItems[idx] = item;
|
||||
@ -2297,6 +2286,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
bulkActions,
|
||||
pickerMode,
|
||||
multiple,
|
||||
strictMode,
|
||||
valueField,
|
||||
primaryField,
|
||||
value,
|
||||
@ -2397,6 +2387,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
pickerMode || keepItemSelectionOnPageChange
|
||||
? store.selectedItemsAsArray
|
||||
: undefined,
|
||||
strictMode,
|
||||
keepItemSelectionOnPageChange,
|
||||
maxKeepItemSelectionLength,
|
||||
valueField: valueField || primaryField,
|
||||
|
@ -463,7 +463,8 @@ export default class PickerControl extends React.PureComponent<
|
||||
multiple,
|
||||
valueField,
|
||||
embed,
|
||||
source
|
||||
source,
|
||||
strictMode
|
||||
} = this.props;
|
||||
|
||||
return render('modal-body', this.state.schema, {
|
||||
@ -472,6 +473,7 @@ export default class PickerControl extends React.PureComponent<
|
||||
primaryField: valueField,
|
||||
options: source ? [] : options,
|
||||
multiple,
|
||||
strictMode,
|
||||
onSelect: embed
|
||||
? (selectedItems: Array<any>, unSelectedItems: Array<any>) => {
|
||||
// 选择行后,crud 会给出连续多次事件,且selectedItems会变化,会导致初始化和点击无效
|
||||
|
@ -321,6 +321,7 @@ export default class List extends React.Component<ListProps, object> {
|
||||
orderBy,
|
||||
orderDir,
|
||||
multiple,
|
||||
strictMode,
|
||||
hideCheckToggler,
|
||||
itemCheckableOn,
|
||||
itemDraggableOn
|
||||
@ -329,6 +330,7 @@ export default class List extends React.Component<ListProps, object> {
|
||||
store.update({
|
||||
/** Card嵌套List情况下该属性获取到的值为ListStore的默认值, 会导致Schema中的配置被覆盖 */
|
||||
multiple: multiple || props?.$schema.multiple,
|
||||
strictMode: strictMode || props?.$schema.strictMode,
|
||||
selectable: selectable || props?.$schema.selectable,
|
||||
draggable: draggable || props?.$schema.draggable,
|
||||
orderBy,
|
||||
@ -399,6 +401,7 @@ export default class List extends React.Component<ListProps, object> {
|
||||
'orderBy',
|
||||
'orderDir',
|
||||
'multiple',
|
||||
'strictMode',
|
||||
'hideCheckToggler',
|
||||
'itemCheckableOn',
|
||||
'itemDraggableOn'
|
||||
@ -409,6 +412,7 @@ export default class List extends React.Component<ListProps, object> {
|
||||
) {
|
||||
store.update({
|
||||
multiple: props.multiple,
|
||||
strictMode: props.strictMode,
|
||||
selectable: props.selectable,
|
||||
draggable: props.draggable,
|
||||
orderBy: props.orderBy,
|
||||
|
Loading…
Reference in New Issue
Block a user