增加测量窗口
This commit is contained in:
@@ -228,6 +228,66 @@ export class BimDialog implements IBimComponent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据内容自动调整弹窗高度
|
||||
*
|
||||
* 设计说明:
|
||||
* - 主要用于“内容展开/收起”场景(比如测量面板展开后,Dialog 高度跟随变化)
|
||||
* - 默认不改变用户拖拽后的当前位置,只做边界夹紧,避免弹窗超出容器
|
||||
*
|
||||
* @param recenter 是否根据 options.position 重新定位(默认 false)
|
||||
*/
|
||||
public fitHeight(recenter: boolean = false) {
|
||||
// 1) 先让高度由内容自然撑开,便于测量真实高度
|
||||
this.element.style.height = 'auto';
|
||||
|
||||
// 2) 获取自然高度并做约束(最小高度 + 不超过容器)
|
||||
const naturalHeight = this.element.getBoundingClientRect().height;
|
||||
const minHeight = this.options.minHeight ?? 100;
|
||||
const containerHeight = this.container.clientHeight || 0;
|
||||
|
||||
// 如果容器高度不可用,至少保证最小高度
|
||||
let targetHeight = Math.max(minHeight, naturalHeight);
|
||||
|
||||
// 约束最大高度:不超过容器高度(避免完全溢出)
|
||||
if (containerHeight > 0) {
|
||||
targetHeight = Math.min(targetHeight, containerHeight);
|
||||
}
|
||||
|
||||
this.element.style.height = `${targetHeight}px`;
|
||||
|
||||
// 3) 定位修正:recenter 则重新按 position 计算,否则只做边界夹紧
|
||||
if (recenter) {
|
||||
this.initPosition();
|
||||
} else {
|
||||
this.clampToContainer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 边界夹紧:保持当前 left/top 不变的前提下,确保弹窗不超出容器
|
||||
* 说明:用于 fitHeight / fitWidth 后的“尺寸变化”场景,避免弹窗被裁切。
|
||||
*/
|
||||
private clampToContainer(): void {
|
||||
const containerW = this.container.clientWidth;
|
||||
const containerH = this.container.clientHeight;
|
||||
const elW = this.element.offsetWidth;
|
||||
const elH = this.element.offsetHeight;
|
||||
|
||||
// 当前 left/top(优先从 style 读取,避免 NaN)
|
||||
const currentLeft = this.element.offsetLeft;
|
||||
const currentTop = this.element.offsetTop;
|
||||
|
||||
const maxLeft = Math.max(0, containerW - elW);
|
||||
const maxTop = Math.max(0, containerH - elH);
|
||||
|
||||
const nextLeft = Math.max(0, Math.min(currentLeft, maxLeft));
|
||||
const nextTop = Math.max(0, Math.min(currentTop, maxTop));
|
||||
|
||||
this.element.style.left = `${nextLeft}px`;
|
||||
this.element.style.top = `${nextTop}px`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化弹窗位置
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user