From baa83cac60daf4dc47e2dd6e38286ebb6155e7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Wed, 2 Sep 2020 10:54:49 +0800 Subject: [PATCH] Optimize Table contextMenu --- src/components/table/table.vue | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 42a4455f..31886d75 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -717,19 +717,22 @@ } }, contextmenuCurrentRow (_index, rowKey, event) { - const $TableWrap = this.$refs.tableWrap; - const TableBounding = $TableWrap.getBoundingClientRect(); - const position = { - left: `${event.clientX - TableBounding.left}px`, - top: `${event.clientY - TableBounding.top}px` - }; - this.contextMenuStyles = position; - this.contextMenuVisible = true; - if (rowKey) { - this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.getBaseDataByRowKey(rowKey))), event, position); - } else { - this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.cloneData[_index])), event, position); - } + if (this.contextMenuVisible) this.handleClickContextMenuOutside(); + this.$nextTick(() => { + const $TableWrap = this.$refs.tableWrap; + const TableBounding = $TableWrap.getBoundingClientRect(); + const position = { + left: `${event.clientX - TableBounding.left}px`, + top: `${event.clientY - TableBounding.top}px` + }; + this.contextMenuStyles = position; + this.contextMenuVisible = true; + if (rowKey) { + this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.getBaseDataByRowKey(rowKey))), event, position); + } else { + this.$emit('on-contextmenu', JSON.parse(JSON.stringify(this.cloneData[_index])), event, position); + } + }); }, getSelection () { // 分别拿根数据和子数据的已选项