Browse Source

Pull request #301371: BI-161134 perf: 表格每次 populate 都会因调用 getScrollWidth 多一次重排

Merge in DEC/fineui from ~XAVIER.MENG/dec-fineui:feature/x to feature/x

* commit 'ddc4156b37024cdac6c05fbb351bb475223a59ba':
  BI-161134 fix: display: none 时计算为 0 下次调用也需重新计算,不能单靠 isNull 判断
  BI-161134 perf: 表格每次 populate 都会因调用 getScrollWidth 多一次重排
master
Xavier.Meng-孟宇翔 1 month ago
parent
commit
c51dec6e65
  1. 28
      packages/fineui/src/core/utils/dom.js

28
packages/fineui/src/core/utils/dom.js

@ -2,7 +2,7 @@
* 对DOM操作的通用函数
*/
import $ from "jquery";
import { each, isEmpty, isNotNull, isNull } from "../2.base";
import { each, isEmpty, isNotEmptyObject } from "../2.base";
import { Widget } from "../4.widget";
import { isIE } from "./../platform";
@ -102,23 +102,37 @@ export function getTextSizeHeight(text, fontSize = 12) {
}
// 获取滚动条的宽度,页面display: none时候获取到的为0
let _scrollWidth = null;
const _scrollWidthMap = {};
export function getScrollWidth(css) {
if (isNull(_scrollWidth) || isNotNull(css) || _scrollWidth === 0) {
const ul = Widget._renderEngine.createElement("<div>").width(50).height(50)
/**
* 指定 scrollbar-width: none;
* 支持的浏览器版本结果肯定为 0无需重复计算
*/
const supportScrollWidth = 'scrollbarWidth' in document.documentElement.style;
const hasNoneScrollWidth =
supportScrollWidth && isNotEmptyObject(css) && [css["scrollbar-width"], css["scrollbarWidth"]].includes("none");
const key = JSON.stringify(css) || "default";
if (hasNoneScrollWidth) {
return 0;
} else if (!_scrollWidthMap[key]) {
const ul = Widget._renderEngine
.createElement("<div>")
.width(50)
.height(50)
.css({
position: "absolute",
top: "-9999px",
overflow: "scroll",
...css
...css,
})
.appendTo("body");
_scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
_scrollWidthMap[key] = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
return _scrollWidth;
return _scrollWidthMap[key];
}
export function getImage(param, fillStyle, backgroundColor) {

Loading…
Cancel
Save