fix: 优化右键菜单位置计算逻辑,确保菜单在窗口内显示,提升用户体验

This commit is contained in:
xudan 2025-10-15 17:03:08 +08:00
parent a46c170fbb
commit 2ac24349a8

View File

@ -80,11 +80,42 @@ const {
watch(
() => props.visible,
(isVisible) => {
if (isVisible) {
positionX.value = props.x;
positionY.value = props.y;
if (isVisible && menuRef.value) {
//
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
//
const menuWidth = menuRef.value.offsetWidth;
const menuHeight = menuRef.value.offsetHeight;
//
let newX = props.x;
let newY = props.y;
//
if (newX + menuWidth > windowWidth) {
newX = windowWidth - menuWidth - 5; // 5px
}
if (newY + menuHeight > windowHeight) {
newY = windowHeight - menuHeight - 5; // 5px
}
//
if (newX < 0) {
newX = 5;
}
if (newY < 0) {
newY = 5;
}
positionX.value = newX;
positionY.value = newY;
}
},
{
flush: 'post', // DOM
},
);
//