Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/renderless/src/common/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ const globalConfig = {
viewportWindow: null // 获取真实视口的window,解决在微前端中某些bug
}

export const getViewportWindow = () => globalConfig.viewportWindow || window

export default globalConfig
16 changes: 3 additions & 13 deletions packages/renderless/src/grid/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

import { getRowid } from './common'
import { hasClass } from '../../common/deps/dom'
import { hasClass, getDomNode } from '../../common/deps/dom'
import { getActualTarget } from '../../common/event'
import { arrayIndexOf } from '../static'

Expand Down Expand Up @@ -150,18 +150,6 @@ export const colToVisible = ($table, column, move) => {
})
}

export const getDomNode = () => {
const documentElement = document.documentElement
const bodyElement = document.body

return {
scrollTop: documentElement.scrollTop || bodyElement.scrollTop,
scrollLeft: documentElement.scrollLeft || bodyElement.scrollLeft,
visibleHeight: documentElement.clientHeight || bodyElement.clientHeight,
visibleWidth: documentElement.clientWidth || bodyElement.clientWidth
}
}

export const getEventTargetNode = (event, container, queryCls) => {
let targetEl
let target = getActualTarget(event)
Expand Down Expand Up @@ -284,3 +272,5 @@ export const getCell = ($table, { row, column }) =>
)
})
})

export { getDomNode }
10 changes: 8 additions & 2 deletions packages/renderless/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { KEY_CODE } from '../common'
import { on, off, addClass, hasClass, removeClass } from '../common/deps/dom'
import PopupManager from '../common/deps/popup-manager'
import { getDomNode } from '../common/deps/dom'
import { getViewportWindow } from '../common/global'

import type {
IModalProps,
IModalRenderlessParams,
Expand Down Expand Up @@ -234,9 +236,13 @@ export const open =
if (!isMobileFirstMode) {
let modalBoxElem = api.getBox()

let clientVisibleWidth = document.documentElement.clientWidth || document.body.clientWidth
const viewportWindow = getViewportWindow()

let clientVisibleWidth =
viewportWindow.document.documentElement.clientWidth || viewportWindow.document.body.clientWidth

let clientVisibleHeight = document.documentElement.clientHeight || document.body.clientHeight
let clientVisibleHeight =
viewportWindow.document.documentElement.clientHeight || viewportWindow.document.body.clientHeight

modalBoxElem.style.left = `${clientVisibleWidth / 2 - modalBoxElem.offsetWidth / 2}px`

Expand Down