Skip to content

Commit 76fa142

Browse files
committed
2 parents c4b2297 + 3b39ed2 commit 76fa142

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

src/components/common/Menu.vue

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const contextmenuMathRandom = computed(() =>
1212
Math.floor(Math.random() * 1000000),
1313
)
1414
15-
async function showContextMenu(attachObj: HTMLElement | MouseEvent, offset: MenuOffsetKind = MenuOffsetKind.MEDIUM_TOP, size: MenuSizeKind = MenuSizeKind.MEDIUM, force: boolean = false) {
15+
async function showContextMenu(attachObj: HTMLElement | MouseEvent, offset: MenuOffsetKind = MenuOffsetKind.MEDIUM_TOP, size: MenuSizeKind | MenuCustomSize = MenuSizeKind.MEDIUM, force: boolean = false, boundaryEle?: HTMLElement,
16+
) {
1617
const contextmenuEle = contextmenuRef.value!
1718
if (!is_init.value && EVENTS.init[contextmenuEle.id]) {
1819
EVENTS.init[contextmenuEle.id].callback(contextmenuEle)
@@ -55,6 +56,12 @@ async function showContextMenu(attachObj: HTMLElement | MouseEvent, offset: Menu
5556
padding = 4
5657
break
5758
}
59+
default: {
60+
minHeight = size.height ?? 80
61+
minWidth = size.width ?? 160
62+
padding = 3
63+
break
64+
}
5865
}
5966
6067
const contextMenuEle = contextmenuRef.value as HTMLElement
@@ -115,7 +122,12 @@ async function showContextMenu(attachObj: HTMLElement | MouseEvent, offset: Menu
115122
}
116123
}
117124
contextMenuEle.style.left = `${left}px`
125+
contextMenuEle.dataset.left = `${left + window.scrollX}`
118126
contextMenuEle.style.top = `${top}px`
127+
contextMenuEle.dataset.top = `${top + window.scrollY}`
128+
129+
addBoundaryAdjustment(contextMenuEle, boundaryEle)
130+
119131
contextMenuEle.style.visibility = 'visible'
120132
121133
contextMenuEle.querySelectorAll('.iw-contextmenu__item').forEach((node) => {
@@ -136,6 +148,35 @@ async function showContextMenu(attachObj: HTMLElement | MouseEvent, offset: Menu
136148
})
137149
}
138150
151+
function addBoundaryAdjustment(contextMenuEle: HTMLElement, boundaryEle?: HTMLElement) {
152+
if (boundaryEle) {
153+
const observer = new ResizeObserver((_) => {
154+
let left = contextMenuEle.offsetLeft
155+
let top = contextMenuEle.offsetTop
156+
157+
const boundaryEleRect = boundaryEle.getBoundingClientRect()
158+
if (left < boundaryEleRect.left) {
159+
left = boundaryEleRect.left
160+
}
161+
if (top < boundaryEleRect.top) {
162+
top = boundaryEleRect.top
163+
}
164+
if ((left + contextMenuEle.offsetWidth) > boundaryEleRect.right) {
165+
left = boundaryEleRect.right - contextMenuEle.offsetWidth
166+
}
167+
168+
if ((top + contextMenuEle.offsetHeight) > boundaryEleRect.bottom) {
169+
top = boundaryEleRect.bottom - contextMenuEle.offsetHeight
170+
}
171+
contextMenuEle.style.left = `${left}px`
172+
contextMenuEle.dataset.left = `${left + window.scrollX}`
173+
contextMenuEle.style.top = `${top}px`
174+
contextMenuEle.dataset.top = `${top + window.scrollY}`
175+
})
176+
observer.observe(contextMenuEle)
177+
}
178+
}
179+
139180
function hideUnActiveContextMenus(event: MouseEvent) {
140181
const contextmenuEles = Array.from(document.querySelectorAll('.iw-contextmenu'))
141182
.filter(ele => ele instanceof HTMLElement && (ele as HTMLElement).style.display !== 'none')
@@ -178,9 +219,12 @@ onMounted(() => {
178219
window.addEventListener('scroll', () => {
179220
const contextmenuEles = document.querySelectorAll('.iw-contextmenu')
180221
for (const i in contextmenuEles) {
181-
if (!(contextmenuEles[i] instanceof HTMLElement) || (contextmenuEles[i] as HTMLElement).style.display === 'none')
222+
if (!(contextmenuEles[i] instanceof HTMLElement) || (contextmenuEles[i] as HTMLElement).style.display === 'none') {
182223
continue
183-
doCloseContextMenu(contextmenuEles[i] as HTMLElement)
224+
}
225+
const contextMenuEle = contextmenuEles[i] as HTMLElement
226+
contextMenuEle.style.top = `${Number.parseInt(contextMenuEle.dataset.top!) - window.scrollY}px`
227+
contextMenuEle.style.left = `${Number.parseInt(contextMenuEle.dataset.left!) - window.scrollX}px`
184228
}
185229
})
186230
})
@@ -230,6 +274,11 @@ export enum MenuSizeKind {
230274
LARGE,
231275
}
232276
277+
export interface MenuCustomSize {
278+
width?: number
279+
height?: number
280+
}
281+
233282
export const FUN_CLOSE_CONTEXT_MENU_TYPE = Symbol('FUN_CLOSE_CONTEXT_MENU_TYPE') as InjectionKey<() => void>
234283
235284
const EVENTS: {

src/components/common/Scrollable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ onMounted(() => {
2929
3030
function offsetLeft() {
3131
const mainEle = scrollableMainRef.value!
32-
mainEle.scrollLeft = Math.min(mainEle.scrollLeft + 200, mainEle.offsetWidth)
32+
mainEle.scrollLeft = Math.max(mainEle.scrollLeft - 200, 0)
3333
}
3434
3535
function offsetRight() {
3636
const mainEle = scrollableMainRef.value!
37-
mainEle.scrollLeft = Math.max(mainEle.scrollLeft - 200, 0)
37+
mainEle.scrollLeft = Math.min(mainEle.scrollLeft + 200, mainEle.offsetWidth)
3838
}
3939
</script>
4040

src/components/function/FilterSetting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function showFilterGroupContainer(e: Event, filterGroupIdx?: number) {
7676
else {
7777
selectedFilterGroup.value = []
7878
}
79-
filterGroupContainerCompRef.value?.show(targetEle, undefined, MenuSizeKind.LARGE, false)
79+
filterGroupContainerCompRef.value?.show(targetEle, undefined, MenuSizeKind.LARGE, false, targetEle.closest('.iw-tt') as HTMLElement)
8080
}
8181
8282
async function deleteFilterGroup(filterGroupIdx: number) {

src/components/function/TableSetting.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ onMounted(() => {
3030
</script>
3131

3232
<template>
33-
<a class="cursor-pointer"><i :class="iconSvg.MORE" @click="(e) => { tableSettingCompRef?.show(e, MenuOffsetKind.RIGHT_TOP) }" /></a>
33+
<a class="cursor-pointer">
34+
<i
35+
:class="iconSvg.MORE"
36+
@click="(e) => { tableSettingCompRef?.show(e, MenuOffsetKind.RIGHT_TOP, { width: 210 }, false, (e.target as HTMLElement).closest('.iw-tt') as HTMLElement) }"
37+
/></a>
3438
<MenuComp ref="tableSettingCompRef">
3539
<BasicSettingComp :layout-conf="props.layoutConf" />
3640
<template v-if="props.basicConf.parentPkColumnName">

0 commit comments

Comments
 (0)