Demo:优化鼠标在窗口边缘点击右键时菜单显示不全的问题

This commit is contained in:
街角小林 2024-04-17 09:14:58 +08:00
parent 6b40358f65
commit 20fae6270d

View File

@ -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