Skip to content

Commit

Permalink
microApp offset in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjinpeng1235 committed Aug 20, 2024
1 parent 4e743b2 commit 240a8c1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/TableDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ const events: IwProps.TableEventProps = {
selectContextMenu(item: IwProps.ContextMenuItemProps, rowPk: string) {
// select context menu option
},
getMicroAppOffset() {
return {
left: -20,
top: -20,
}
},
}
const columns: IwProps.SimpleTableColumnProps[] = [
Expand Down
7 changes: 7 additions & 0 deletions src/components/common/Menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getParentWithClass } from '../../utils/basic'
import * as eb from '../../components/eventbus'

/**
* 上下文菜单的位置偏移类型
Expand Down Expand Up @@ -131,6 +132,12 @@ export function getInitOffset(attachObj: HTMLElement | MouseEvent, offset: MenuO
}
}

if(eb.getMicroAppOffset){
const { left: microAppLeft, top: microAppTop } = eb.getMicroAppOffset()
left -= microAppLeft
top -= microAppTop
}

return { left, top }
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/common/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export const FUN_CLOSE_CONTEXT_MENU_TYPE = Symbol('FUN_CLOSE_CONTEXT_MENU_TYPE')
v-show="isInit"
:id="'iw-contextmenu-' + `${contextmenuMathRandom}`"
ref="contextmenuRef"
class="iw-contextmenu flex flex-col items-start fixed z-[3100] bg-base-100 p-1 rounded-md border border-base-300"
class="iw-contextmenu overflow-auto flex flex-col items-start fixed z-[3100] bg-base-100 p-1 rounded-md border border-base-300"
:style="{'maxHeight': '600px'}"
>
<!-- 仅在初始化后渲染插槽信息 -->
<!-- Only render slot information after initialization -->
Expand Down
13 changes: 13 additions & 0 deletions src/components/eventbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,16 @@ export function selectContextMenu(item: ContextMenuItemProps, exArg?: any) {
events.selectContextMenu(item, exArg)
}
}

/**
* 获取微应用偏移
*
* get micro app offset
*
*/
export function getMicroAppOffset() {
if (events.getMicroAppOffset) {
return events.getMicroAppOffset()
}
return { left: 0, top: 0 }
}
6 changes: 6 additions & 0 deletions src/props/eventProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,10 @@ export interface TableEventProps {
* @param exArg 额外参数 / Extra argument
*/
selectContextMenu?: (item: ContextMenuItemProps, exArg?: any) => void
/**
* 获取微应用偏移
*
* get micro app offset
*/
getMicroAppOffset?: () => {left: number, top: number}
}

0 comments on commit 240a8c1

Please sign in to comment.