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

Transfer: add left-check-change and right-check-change #10156

Merged
merged 1 commit into from
Mar 14, 2018
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
2 changes: 2 additions & 0 deletions examples/docs/en-US/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,5 @@ By default, Transfer looks for `key`, `label` and `disabled` in a data item. If
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| change | triggers when data items change in the right list | key array of current data items in the right list, transfer direction (left or right), moved item keys |
| left-check-change | triggers when end user changes the checked state of any data item in the left list | key array of currently checked items, key array of items whose checked state have changed |
| right-check-change | triggers when end user changes the checked state of any data item in the right list | key array of currently checked items, key array of items whose checked state have changed |
3 changes: 2 additions & 1 deletion examples/docs/es/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,5 @@ Por defecto Transfer busca los atributos `key`, `label`, y `disabled` en cada el
| Nombre | Descripcion | Parametros |
| ------ | ---------------------------------------- | ---------------------------------------- |
| change | se lanzá cuando los elementos cambian en la lista de la derecha | array con las claves de los elementos de la lista de la derecha |

| left-check-change | triggers when end user changes the checked state of any data item in the left list | key array of currently checked items, key array of items whose checked state have changed |
| right-check-change | triggers when end user changes the checked state of any data item in the right list | key array of currently checked items, key array of items whose checked state have changed |
2 changes: 2 additions & 0 deletions examples/docs/zh-CN/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,5 @@
| 事件名称 | 说明 | 回调参数 |
|---------- |-------- |---------- |
| change | 右侧列表元素变化时触发 | 当前值、数据移动的方向('left' / 'right')、发生移动的数据 key 数组 |
| left-check-change | 左侧列表元素被用户选中 / 取消选中时触发 | 当前被选中的元素的 key 数组、选中状态发生变化的元素的 key 数组 |
| right-check-change | 右侧列表元素被用户选中 / 取消选中时触发 | 当前被选中的元素的 key 数组、选中状态发生变化的元素的 key 数组 |
8 changes: 6 additions & 2 deletions packages/transfer/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,16 @@
};
},

onSourceCheckedChange(val) {
onSourceCheckedChange(val, movedKeys) {
this.leftChecked = val;
if (movedKeys === undefined) return;
this.$emit('left-check-change', val, movedKeys);
},

onTargetCheckedChange(val) {
onTargetCheckedChange(val, movedKeys) {
this.rightChecked = val;
if (movedKeys === undefined) return;
this.$emit('right-check-change', val, movedKeys);
},

addToLeft() {
Expand Down
16 changes: 13 additions & 3 deletions packages/transfer/src/transfer-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,22 @@
checked: [],
allChecked: false,
query: '',
inputHover: false
inputHover: false,
checkChangeByUser: true
};
},

watch: {
checked(val) {
checked(val, oldVal) {
this.updateAllChecked();
this.$emit('checked-change', val);
if (this.checkChangeByUser) {
const movedKeys = val.concat(oldVal)
.filter(v => val.indexOf(v) === -1 || oldVal.indexOf(v) === -1);
this.$emit('checked-change', val, movedKeys);
} else {
this.$emit('checked-change', val);
this.checkChangeByUser = true;
}
},

data() {
Expand All @@ -130,6 +138,7 @@
checked.push(item);
}
});
this.checkChangeByUser = false;
this.checked = checked;
},

Expand All @@ -149,6 +158,7 @@
checked.push(item);
}
});
this.checkChangeByUser = false;
this.checked = checked;
}
}
Expand Down