feat(component): 完善 表格 穿梭狂 组件

This commit is contained in:
就眠仪式 2021-10-14 18:00:24 +08:00
parent 5584b9886a
commit 19302af243

View File

@ -115,7 +115,7 @@ const allLeftChange = function ({ checked }: any) {
watch( watch(
leftSelectedKeys, leftSelectedKeys,
function () { function () {
if (leftDataSource.value.length === leftSelectedKeys.value.length) { if (leftDataSource.value.length === leftSelectedKeys.value.length && leftDataSource.value.length != 0) {
allLeftChecked.value = true allLeftChecked.value = true
} else { } else {
allLeftChecked.value = false allLeftChecked.value = false
@ -138,7 +138,7 @@ const allRightChange = function ({ checked }: any) {
watch( watch(
rightSelectedKeys, rightSelectedKeys,
function () { function () {
if (rightDataSource.value.length === rightSelectedKeys.value.length) { if (rightDataSource.value.length === rightSelectedKeys.value.length && rightDataSource.value.length != 0) {
allRightChecked.value = true allRightChecked.value = true
} else { } else {
allRightChecked.value = false allRightChecked.value = false
@ -149,15 +149,30 @@ watch(
const add = function () { const add = function () {
// leftDataSource // leftDataSource
if(leftSelectedKeys.value.length === 0){
return
}
rightDataSource.value = leftDataSource.value.filter( rightDataSource.value = leftDataSource.value.filter(
(item) => leftSelectedKeys.value.indexOf(item.id) != -1 (item) => leftSelectedKeys.value.indexOf(item.id) != -1
) )
leftDataSource.value = leftDataSource.value.filter(
(item) => leftSelectedKeys.value.indexOf(item.id) === -1
)
leftSelectedKeys.value = []
} }
const remove = function () { const remove = function () {
// rightDataSource // rightDataSource
if(rightSelectedKeys.value.length === 0){
return
}
leftDataSource.value = rightDataSource.value.filter( leftDataSource.value = rightDataSource.value.filter(
(item) => rightSelectedKeys.value.indexOf(item.id) != -1 (item) => rightSelectedKeys.value.indexOf(item.id) != -1
) )
rightDataSource.value = rightDataSource.value.filter(
(item) => rightSelectedKeys.value.indexOf(item.id) === -1
)
rightSelectedKeys.value = []
} }
</script> </script>