Optimize Tree contextMenu

This commit is contained in:
梁灏 2020-09-02 10:58:26 +08:00
parent baa83cac60
commit e3d2e05598

View file

@ -205,15 +205,18 @@
this.$emit('on-check-change', this.getCheckedNodes(), node); this.$emit('on-check-change', this.getCheckedNodes(), node);
}, },
handleContextmenu ({ data, event }) { handleContextmenu ({ data, event }) {
const $TreeWrap = this.$refs.treeWrap; if (this.contextMenuVisible) this.handleClickContextMenuOutside();
const TreeBounding = $TreeWrap.getBoundingClientRect(); this.$nextTick(() => {
const position = { const $TreeWrap = this.$refs.treeWrap;
left: `${event.clientX - TreeBounding.left}px`, const TreeBounding = $TreeWrap.getBoundingClientRect();
top: `${event.clientY - TreeBounding.top}px` const position = {
}; left: `${event.clientX - TreeBounding.left}px`,
this.contextMenuStyles = position; top: `${event.clientY - TreeBounding.top}px`
this.contextMenuVisible = true; };
this.$emit('on-contextmenu', data, event, position); this.contextMenuStyles = position;
this.contextMenuVisible = true;
this.$emit('on-contextmenu', data, event, position);
});
}, },
handleClickContextMenuOutside () { handleClickContextMenuOutside () {
this.contextMenuVisible = false; this.contextMenuVisible = false;