Skip to content

Commit

Permalink
refactor:修复右击菜单组件的菜单面板可能超出屏幕的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
build-admin committed Apr 18, 2024
1 parent 4905d71 commit 830506d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion web/src/components/contextmenu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</li>
</template>
</ul>
<span class="el-popper__arrow" :style="{ left: `${state.arrowAxis}px` }"></span>
<span v-if="state.showArrow" class="el-popper__arrow" :style="{ left: `${state.arrowAxis}px` }"></span>
</div>
</transition>
</template>
Expand Down Expand Up @@ -45,6 +45,7 @@ const state: {
y: number
}
sourceData: any
showArrow: boolean
arrowAxis: number
} = reactive({
show: false,
Expand All @@ -53,6 +54,7 @@ const state: {
y: 0,
},
sourceData: null,
showArrow: true,
arrowAxis: 10,
})
Expand All @@ -62,7 +64,20 @@ const state: {
* @param axis 右击坐标信息
*/
const onShowContextmenu = (sourceData: any, axis: Axis) => {
state.showArrow = true
state.sourceData = sourceData
const yOffset = document.documentElement.clientHeight - axis.y - (props.items.length * 40 + 20)
const xOffset = document.documentElement.clientWidth - axis.x - (props.width + 20)
if (yOffset < 0) {
axis.y += yOffset
state.showArrow = false
}
if (xOffset < 0) {
axis.x += xOffset
state.showArrow = false
}
state.axis = axis
state.show = true
}
Expand Down

0 comments on commit 830506d

Please sign in to comment.