Skip to content

Commit

Permalink
fix(transfer): fix disabled value removed from target
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Jul 21, 2023
1 parent f516ae8 commit a9ca949
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/transfer/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ export default mixins(getConfigReceiverMixins('transfer')).extend({
newTargetValue = oldTargetValue.filter((v) => !checkedValue.includes(v));
} else if (this.targetSort === 'original') {
// 按照原始顺序
const remainValue = this.transferData.reduce((acc, data) => {
if (oldTargetValue.includes(data.value) && data.disabled) {
return acc.concat(data.value);
}
return acc;
}, []);
newTargetValue = getDataValues(this.transferData, oldTargetValue.concat(checkedValue), {
isTreeMode: this.isTreeMode,
remainValue,
});
} else if (this.targetSort === 'unshift') {
newTargetValue = checkedValue.concat(oldTargetValue);
Expand Down
6 changes: 5 additions & 1 deletion src/transfer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function getDataValues(
{
isTreeMode = false,
include = true, // true=保留filterValues,false=删除filterValues中元素
remainValue = [] as Array<TransferValue>,
} = {},
): Array<TransferValue> {
// 用于处理 tree 组件这种数据结构是树形的
Expand Down Expand Up @@ -69,10 +70,13 @@ function getDataValues(
}
return result;
}
// 处理普通结构
return data
.filter((item) => {
const isInclude = filterValues.includes(item.value);
return ((include && isInclude) || (!include && !isInclude)) && !item.disabled;
return (
((include && isInclude) || (!include && !isInclude)) && (!item.disabled || remainValue.includes(item.value))
);
})
.map((item) => item.value);
}
Expand Down

0 comments on commit a9ca949

Please sign in to comment.