Table add content-menu prop & event

This commit is contained in:
梁灏 2020-01-12 13:33:48 +08:00
parent 2d77fb5f39
commit 0b7430090d
3 changed files with 26 additions and 2 deletions

View file

@ -5,6 +5,7 @@
<Table
border
highlight-row
content-menu
@on-current-change="occ"
@on-row-click="orc"
@on-row-dblclick="ordc"
@ -12,6 +13,7 @@
@on-select-cancel="osc"
@on-select-all="osa"
@on-select-all-cancel="osac"
@on-contextmenu="ocm"
ref="selection"
:columns="columns4"
:data="data1"
@ -340,6 +342,9 @@
osac (s) {
console.log(s);
},
ocm (s) {
console.log(s);
},
loadData (item, callback) {
setTimeout(() => {
const data = [

View file

@ -114,6 +114,11 @@
event.stopPropagation();
this.$parent.dblclickCurrentRow(_index, rowKey);
},
contextmenuCurrentRow (_index, event, rowKey) {
event.stopPropagation();
if (this.$parent.contentMenu) event.preventDefault();
this.$parent.contextmenuCurrentRow(_index, rowKey);
},
getSpan (row, column, rowIndex, columnIndex) {
const fn = this.$parent.spanMethod;
if (typeof fn === 'function') {
@ -269,7 +274,8 @@
mouseenter: (e) => this.handleMouseIn(row._index, e, row._rowKey),
mouseleave: (e) => this.handleMouseOut(row._index, e, row._rowKey),
click: (e) => this.clickCurrentRow(row._index, e, row._rowKey),
dblclick: (e) => this.dblclickCurrentRow(row._index, e, row._rowKey)
dblclick: (e) => this.dblclickCurrentRow(row._index, e, row._rowKey),
contextmenu: (e) => this.contextmenuCurrentRow(row._index, e, row._rowKey)
}
}, $tds);
@ -337,7 +343,8 @@
mouseenter: (e) => this.handleMouseIn(row._index, e),
mouseleave: (e) => this.handleMouseOut(row._index, e),
click: (e) => this.clickCurrentRow(row._index, e),
dblclick: (e) => this.dblclickCurrentRow(row._index, e)
dblclick: (e) => this.dblclickCurrentRow(row._index, e),
contextmenu: (e) => this.contextmenuCurrentRow(row._index, e)
}
}, $tds);
$tableTrs.push($tableTr);

View file

@ -266,6 +266,11 @@
// 4.1.0
loadData: {
type: Function
},
// 4.1.0
contentMenu: {
type: Boolean,
default: false
}
},
data () {
@ -694,6 +699,13 @@
this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index])), _index);
}
},
contextmenuCurrentRow (_index, rowKey) {
if (rowKey) {
this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.getBaseDataByRowKey(rowKey))));
} else {
this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.cloneData[_index])), _index);
}
},
getSelection () {
//
let selectionIndexes = [];