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

View file

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

View file

@ -266,6 +266,11 @@
// 4.1.0 // 4.1.0
loadData: { loadData: {
type: Function type: Function
},
// 4.1.0
contentMenu: {
type: Boolean,
default: false
} }
}, },
data () { data () {
@ -694,6 +699,13 @@
this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index])), _index); 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 () { getSelection () {
// //
let selectionIndexes = []; let selectionIndexes = [];