From b8f272885f9e949b950cb2370cc435b5a7a34c82 Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 14 Dec 2022 17:23:12 +0800 Subject: [PATCH] =?UTF-8?q?BI-118659=20fix:=20belowMouse=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/combination/combo.js | 26 +++++++++-------------- src/core/platform/web/dom.js | 39 ++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index f73fec11d..003571b29 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -196,28 +196,22 @@ this.popupView.visible(); var combo = (o.belowMouse && BI.isNotNull(e)) ? { element: { - 0: e.target, + 0: BI.extend({}, e.target, { + getBoundingClientRect: function () { + return { + left: e.pageX, + top: e.pageY, + width: 0, + height: 0, + }; + } + }), offset: function () { return { left: e.pageX, top: e.pageY, }; }, - bounds: function () { - // offset为其相对于父定位元素的偏移 - return { - x: e.offsetX, - y: e.offsetY, - width: 0, - height: 24, - }; - }, - outerWidth: function () { - return 0; - }, - outerHeight: function () { - return 24; - }, }, } : this.combo; var positionRelativeElement = BI.DOM.getPositionRelativeContainingBlock(BI.isNull(o.container) ? this.element[0] : BI.Widget._renderEngine.createElement(BI.isFunction(o.container) ? o.container() : o.container)[0]); diff --git a/src/core/platform/web/dom.js b/src/core/platform/web/dom.js index d2fffd753..9b1026683 100644 --- a/src/core/platform/web/dom.js +++ b/src/core/platform/web/dom.js @@ -249,12 +249,14 @@ }, _getLeftAlignPosition: function (combo, popup, extraWidth, container) { - var viewBounds = popup.element.bounds(), - windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); - var left = combo.element.offset().left - (container ? container.getBoundingClientRect().left : 0) + extraWidth; + var comboRect = combo.element[0].getBoundingClientRect(), + popupRect = popup.element.bounds(), + viewportRect = document.documentElement.getBoundingClientRect(), + containerRect = container ? container.getBoundingClientRect() : { left: 0 }; + var left = comboRect.left - containerRect.left + extraWidth; - if (left + viewBounds.width > windowBounds.width) { - left = windowBounds.width - viewBounds.width; + if (left + popupRect.width - containerRect.left > viewportRect.width) { + left = viewportRect.width - popupRect.width - containerRect.left; } return left; }, @@ -285,17 +287,19 @@ }; }, - _getRightAlignPosition: function (combo, popup, extraWidth) { - var comboBounds = combo.element.bounds(), viewBounds = popup.element.bounds(); - return combo.element.offset().left + comboBounds.width - viewBounds.width - extraWidth; + _getRightAlignPosition: function (combo, popup, extraWidth, container) { + var comboBounds = combo.element[0].getBoundingClientRect(), + viewBounds = popup.element[0].getBoundingClientRect(), + containerRect = container ? container.getBoundingClientRect() : { left: 0 }; + return comboBounds.left + comboBounds.width - viewBounds.width - extraWidth - containerRect.left; }, - getRightAlignPosition: function (combo, popup, extraWidth) { - var left = this._getRightAlignPosition(combo, popup, extraWidth); + getRightAlignPosition: function (combo, popup, extraWidth, container) { + var left = this._getRightAlignPosition(combo, popup, extraWidth, container); var dir = ""; // 如果放不下,优先使用LeftAlign, 如果LeftAlign也放不下, 再使用left=0 if (left < 0) { - left = this._getLeftAlignPosition(combo, popup, extraWidth); + left = this._getLeftAlignPosition(combo, popup, extraWidth, container); dir = "right"; } if (left < 0) { @@ -317,14 +321,13 @@ }, getTopAlignPosition: function (combo, popup, extraHeight, needAdaptHeight, container) { - var comboOffset = combo.element.offset(); var comboBounds = combo.element[0].getBoundingClientRect(), popupBounds = popup.element[0].getBoundingClientRect(), viewportBounds = document.documentElement.getBoundingClientRect(), containerBounds = container ? container.getBoundingClientRect() : { top: 0 }; var top, adaptHeight, dir; if (BI.DOM.isBottomSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) { - top = comboOffset.top - containerBounds.top + extraHeight; + top = comboBounds.top - containerBounds.top + extraHeight; } else if (needAdaptHeight) { top = comboBounds.top - containerBounds.top + extraHeight; adaptHeight = viewportBounds.height - comboBounds.top; @@ -375,20 +378,19 @@ }, getBottomAlignPosition: function (combo, popup, extraHeight, needAdaptHeight, container) { - var comboOffset = combo.element.offset(); var comboBounds = combo.element[0].getBoundingClientRect(), popupBounds = popup.element[0].getBoundingClientRect(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(), containerBounds = container ? container.getBoundingClientRect() : { top: 0 }; var top, adaptHeight, dir; if (BI.DOM.isTopSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) { - top = comboOffset.top + comboBounds.height - containerBounds.top - popupBounds.height; + top = comboBounds.top + comboBounds.height - containerBounds.top - popupBounds.height; } else if (needAdaptHeight) { top = 0 - containerBounds.top; adaptHeight = comboBounds.top + comboBounds.height - extraHeight; } else if (BI.DOM.isBottomSpaceEnough(combo, popup, -1 * comboBounds.height + extraHeight)) { // 上方空间不足且不允许调整高度的情况下,优先使用下对齐 - top = comboOffset.top - containerBounds.top + extraHeight; + top = comboBounds.top - containerBounds.top + extraHeight; dir = "bottom"; } else { top = 0; @@ -410,7 +412,6 @@ }, getBottomAdaptPosition: function (combo, popup, extraHeight, needAdaptHeight) { - var comboOffset = combo.element.offset(); var comboBounds = combo.element.bounds(), popupBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); if (BI.DOM.isBottomSpaceEnough(combo, popup, extraHeight)) { @@ -418,8 +419,8 @@ } if (needAdaptHeight) { return { - top: comboOffset.top + comboBounds.height + extraHeight, - adaptHeight: windowBounds.height - comboOffset.top - comboBounds.height - extraHeight + top: comboBounds.top + comboBounds.height + extraHeight, + adaptHeight: windowBounds.height - comboBounds.top - comboBounds.height - extraHeight }; } if (popupBounds.height + extraHeight > windowBounds.height) {