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(transfer): fix disabled value removed from target #2599

Merged
merged 1 commit into from
Jul 21, 2023
Merged
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
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
Loading