Table: Add handleEvent. (#3305)

This commit is contained in:
Cyril Su 2017-03-06 18:45:27 +08:00 committed by cinwell.li
parent 4aabc95a6d
commit 5e796ca33b
2 changed files with 10 additions and 18 deletions

View File

@ -219,37 +219,29 @@ export default {
}, },
handleContextMenu(event, row) { handleContextMenu(event, row) {
const table = this.table; this.handleEvent(event, row, 'contextmenu');
const cell = getCell(event);
let column;
if (cell) {
column = getColumnByCell(table, cell);
if (column) {
table.$emit('cell-dblclick', row, column, cell, event);
}
}
table.$emit('row-contextmenu', row, event);
}, },
handleDoubleClick(event, row) { handleDoubleClick(event, row) {
const table = this.table; this.handleEvent(event, row, 'dblclick');
table.$emit('row-dblclick', row, event);
}, },
handleClick(event, row) { handleClick(event, row) {
this.store.commit('setCurrentRow', row);
this.handleEvent(event, row, 'click');
},
handleEvent(event, row, name) {
const table = this.table; const table = this.table;
const cell = getCell(event); const cell = getCell(event);
let column; let column;
if (cell) { if (cell) {
column = getColumnByCell(table, cell); column = getColumnByCell(table, cell);
if (column) { if (column) {
table.$emit('cell-click', row, column, cell, event); table.$emit(`cell-${name}`, row, column, cell, event);
} }
} }
table.$emit(`row-${name}`, row, event, column);
this.store.commit('setCurrentRow', row);
table.$emit('row-click', row, event, column);
}, },
handleExpandClick(row) { handleExpandClick(row) {

View File

@ -459,7 +459,7 @@ describe('Table', () => {
const cell = vm.$el.querySelectorAll('.el-table__body .cell')[2]; // first row const cell = vm.$el.querySelectorAll('.el-table__body .cell')[2]; // first row
triggerEvent(cell.parentNode.parentNode, 'dblclick'); triggerEvent(cell.parentNode.parentNode, 'dblclick');
expect(vm.result).to.length(2); // row, event expect(vm.result).to.length(3); // row, event, column
expect(vm.result[0]).to.have.property('name').to.equal(getTestData()[0].name); expect(vm.result[0]).to.have.property('name').to.equal(getTestData()[0].name);
destroyVM(vm); destroyVM(vm);
done(); done();