This commit is contained in:
2024-09-24 17:04:44 +08:00
parent 6cd84e0021
commit 30528311c1
77 changed files with 2251 additions and 1361 deletions

View File

@@ -72,30 +72,42 @@ const _sfc_main = defineComponent({
leftSelectedKeys.value = [];
}
};
watch(() => [props.modelValue, props.dataSource], () => {
let targetDataSource = [];
props.dataSource.forEach((ds) => {
if (props.modelValue.includes(ds[props.id])) {
targetDataSource.push(ds);
watch(
() => [props.modelValue, props.dataSource],
() => {
let targetDataSource = [];
props.dataSource.forEach((ds) => {
if (props.modelValue.includes(ds[props.id])) {
targetDataSource.push(ds);
}
});
leftDataSource.value = props.dataSource.filter(
(item) => !props.modelValue.includes(item[props.id])
);
_leftDataSource.value = props.dataSource.filter(
(item) => !props.modelValue.includes(item[props.id])
);
rightDataSource.value = [...targetDataSource];
_rightDataSource.value = [...targetDataSource];
},
{ immediate: true }
);
watch(
leftSelectedKeys,
() => {
if (leftDataSource.value.length === leftSelectedKeys.value.length && leftDataSource.value.length != 0) {
allLeftChecked.value = true;
} else {
allLeftChecked.value = false;
}
});
leftDataSource.value = props.dataSource.filter((item) => !props.modelValue.includes(item[props.id]));
_leftDataSource.value = props.dataSource.filter((item) => !props.modelValue.includes(item[props.id]));
rightDataSource.value = [...targetDataSource];
_rightDataSource.value = [...targetDataSource];
}, { immediate: true });
watch(leftSelectedKeys, () => {
if (leftDataSource.value.length === leftSelectedKeys.value.length && leftDataSource.value.length != 0) {
allLeftChecked.value = true;
} else {
allLeftChecked.value = false;
}
if (leftSelectedKeys.value.length > 0 && leftDataSource.value.length != 0) {
hasLeftChecked.value = true;
} else {
hasLeftChecked.value = false;
}
}, { deep: true });
if (leftSelectedKeys.value.length > 0 && leftDataSource.value.length != 0) {
hasLeftChecked.value = true;
} else {
hasLeftChecked.value = false;
}
},
{ deep: true }
);
const allRightChange = (checked) => {
if (checked) {
const datasources = rightDataSource.value.filter((item) => {
@@ -109,18 +121,22 @@ const _sfc_main = defineComponent({
rightSelectedKeys.value = [];
}
};
watch(rightSelectedKeys, () => {
if (rightDataSource.value.length === rightSelectedKeys.value.length && rightDataSource.value.length > 0) {
allRightChecked.value = true;
} else {
allRightChecked.value = false;
}
if (rightSelectedKeys.value.length > 0 && rightDataSource.value.length != 0) {
hasRightChecked.value = true;
} else {
hasRightChecked.value = false;
}
}, { deep: true });
watch(
rightSelectedKeys,
() => {
if (rightDataSource.value.length === rightSelectedKeys.value.length && rightDataSource.value.length > 0) {
allRightChecked.value = true;
} else {
allRightChecked.value = false;
}
if (rightSelectedKeys.value.length > 0 && rightDataSource.value.length != 0) {
hasRightChecked.value = true;
} else {
hasRightChecked.value = false;
}
},
{ deep: true }
);
const add = () => {
if (leftSelectedKeys.value.length === 0) {
return;