diff --git a/packages/renderless/src/common/global.ts b/packages/renderless/src/common/global.ts index d9b8f73041..a73e754491 100644 --- a/packages/renderless/src/common/global.ts +++ b/packages/renderless/src/common/global.ts @@ -2,4 +2,6 @@ const globalConfig = { viewportWindow: null // 获取真实视口的window,解决在微前端中某些bug } +export const getViewportWindow = () => globalConfig.viewportWindow || window + export default globalConfig diff --git a/packages/renderless/src/grid/utils/dom.ts b/packages/renderless/src/grid/utils/dom.ts index d795d4c237..ed7d501510 100644 --- a/packages/renderless/src/grid/utils/dom.ts +++ b/packages/renderless/src/grid/utils/dom.ts @@ -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' @@ -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) @@ -284,3 +272,5 @@ export const getCell = ($table, { row, column }) => ) }) }) + +export { getDomNode } diff --git a/packages/renderless/src/modal/index.ts b/packages/renderless/src/modal/index.ts index 2f7fee7042..275859ea37 100644 --- a/packages/renderless/src/modal/index.ts +++ b/packages/renderless/src/modal/index.ts @@ -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, @@ -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`