Demo:优化鼠标在窗口边缘点击右键时菜单显示不全的问题
This commit is contained in:
parent
6b40358f65
commit
20fae6270d
@ -2,6 +2,7 @@
|
|||||||
<div
|
<div
|
||||||
class="contextmenuContainer listBox"
|
class="contextmenuContainer listBox"
|
||||||
v-if="isShow"
|
v-if="isShow"
|
||||||
|
ref="contextmenuRef"
|
||||||
:style="{ left: left + 'px', top: top + 'px' }"
|
:style="{ left: left + 'px', top: top + 'px' }"
|
||||||
:class="{ isDark: isDark }"
|
:class="{ isDark: isDark }"
|
||||||
>
|
>
|
||||||
@ -239,24 +240,31 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
...mapMutations(['setLocalConfig']),
|
...mapMutations(['setLocalConfig']),
|
||||||
|
|
||||||
/**
|
// 计算右键菜单元素的显示位置
|
||||||
* @Author: 王林
|
getShowPosition(x, y) {
|
||||||
* @Date: 2021-07-14 21:38:50
|
const rect = this.$refs.contextmenuRef.getBoundingClientRect()
|
||||||
* @Desc: 节点右键显示
|
if (x + rect.width > window.innerWidth) {
|
||||||
*/
|
x = x - rect.width - 20
|
||||||
show(e, node) {
|
}
|
||||||
this.type = 'node'
|
if (y + rect.height > window.innerHeight) {
|
||||||
this.left = e.clientX + 10
|
y = window.innerHeight - rect.height - 10
|
||||||
this.top = e.clientY + 10
|
}
|
||||||
this.isShow = true
|
return { x, y }
|
||||||
this.node = node
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 节点右键显示
|
||||||
* @Author: 王林
|
show(e, node) {
|
||||||
* @Date: 2021-07-16 13:27:48
|
this.type = 'node'
|
||||||
* @Desc: 鼠标按下事件
|
this.isShow = true
|
||||||
*/
|
this.node = node
|
||||||
|
this.$nextTick(() => {
|
||||||
|
const { x, y } = this.getShowPosition(e.clientX + 10, e.clientY + 10)
|
||||||
|
this.left = x
|
||||||
|
this.top = y
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 鼠标按下事件
|
||||||
onMousedown(e) {
|
onMousedown(e) {
|
||||||
if (e.which !== 3) {
|
if (e.which !== 3) {
|
||||||
return
|
return
|
||||||
@ -266,11 +274,7 @@ export default {
|
|||||||
this.isMousedown = true
|
this.isMousedown = true
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 鼠标松开事件
|
||||||
* @Author: 王林
|
|
||||||
* @Date: 2021-07-16 13:27:53
|
|
||||||
* @Desc: 鼠标松开事件
|
|
||||||
*/
|
|
||||||
onMouseup(e) {
|
onMouseup(e) {
|
||||||
if (!this.isMousedown) {
|
if (!this.isMousedown) {
|
||||||
return
|
return
|
||||||
@ -286,35 +290,26 @@ export default {
|
|||||||
this.show2(e)
|
this.show2(e)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 画布右键显示
|
||||||
* @Author: 王林
|
|
||||||
* @Date: 2021-07-15 22:54:08
|
|
||||||
* @Desc: 画布右键显示
|
|
||||||
*/
|
|
||||||
show2(e) {
|
show2(e) {
|
||||||
this.type = 'svg'
|
this.type = 'svg'
|
||||||
this.left = e.clientX + 10
|
|
||||||
this.top = e.clientY + 10
|
|
||||||
this.isShow = true
|
this.isShow = true
|
||||||
|
this.$nextTick(() => {
|
||||||
|
const { x, y } = this.getShowPosition(e.clientX + 10, e.clientY + 10)
|
||||||
|
this.left = x
|
||||||
|
this.top = y
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 隐藏
|
||||||
* @Author: 王林
|
|
||||||
* @Date: 2021-07-14 21:37:55
|
|
||||||
* @Desc: 隐藏
|
|
||||||
*/
|
|
||||||
hide() {
|
hide() {
|
||||||
this.isShow = false
|
this.isShow = false
|
||||||
this.left = 0
|
this.left = -9999
|
||||||
this.top = 0
|
this.top = -9999
|
||||||
this.type = ''
|
this.type = ''
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 执行命令
|
||||||
* @Author: 王林
|
|
||||||
* @Date: 2021-07-14 23:27:54
|
|
||||||
* @Desc: 执行命令
|
|
||||||
*/
|
|
||||||
exec(key, disabled, ...args) {
|
exec(key, disabled, ...args) {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user