Browse Source

Pull request #3680: 无JIRA任务 rowHeight支持一下传function

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '697bc5bb239817a7d9a277f40e2ba356dbb0a7ef':
  无JIRA任务 custom_tree支持hasNext
  无JIRA任务 rowHeight支持一下传function
research/test
guy-王川 1 year ago
parent
commit
1de0efcd03
  1. 24
      packages/fineui/src/base/list/virtualgrouplist.js

24
packages/fineui/src/base/list/virtualgrouplist.js

@ -1,4 +1,4 @@
import { VerticalLayout, Layout, Widget, shortcut, extend, isFunction, isNumber, PrefixIntervalTree, ResizeDetector } from "@/core"; import { VerticalLayout, Layout, Widget, shortcut, extend, isFunction, isNumber, sum, PrefixIntervalTree, ResizeDetector } from "@/core";
import { VirtualGroup } from "../combination"; import { VirtualGroup } from "../combination";
/** /**
@ -17,7 +17,7 @@ export class VirtualGroupList extends Widget {
overscanHeight: 100, overscanHeight: 100,
blockSize: 10, blockSize: 10,
scrollTop: 0, scrollTop: 0,
rowHeight: "auto", rowHeight: "auto", // 'auto' 或 数值 或function
items: [], items: [],
el: {}, el: {},
itemFormatter: (item, index) => item, itemFormatter: (item, index) => item,
@ -97,7 +97,7 @@ export class VirtualGroupList extends Widget {
} }
_isAutoHeight() { _isAutoHeight() {
return !isNumber(this.options.rowHeight); return this.options.rowHeight === 'auto';
} }
_renderMoreIf() { _renderMoreIf() {
@ -163,7 +163,7 @@ export class VirtualGroupList extends Widget {
itemsArr.push(items[j]); itemsArr.push(items[j]);
} }
} }
this.container.element.height(rowHeight * items.length - topHeight); this.container.element.height(this.summaryHeight - topHeight);
this.container.populate( this.container.populate(
itemsArr.map((item, i) => itemFormatter(item, (start < 0 ? 0 : start) * blockSize + i)) itemsArr.map((item, i) => itemFormatter(item, (start < 0 ? 0 : start) * blockSize + i))
); );
@ -180,6 +180,16 @@ export class VirtualGroupList extends Widget {
Math.ceil(this.options.items.length / blockSize), Math.ceil(this.options.items.length / blockSize),
this._isAutoHeight() ? 0 : rowHeight * blockSize this._isAutoHeight() ? 0 : rowHeight * blockSize
); );
if (isFunction(rowHeight)) {
for (let i = 0; i < this.options.items.length / blockSize; i++) {
const index = i * blockSize;
let summaryHeight = 0;
for (let j = index; j < index + blockSize && j < this.options.items.length; j++) {
summaryHeight += rowHeight(j, this.options.items[j]);
}
this.tree.set(i, summaryHeight);
}
}
this._calculateBlocksToRender(); this._calculateBlocksToRender();
try { try {
@ -188,7 +198,13 @@ export class VirtualGroupList extends Widget {
} }
_restore() { _restore() {
const o = this.options;
this.renderedIndex = -1; this.renderedIndex = -1;
if (isFunction(o.rowHeight)) {
this.summaryHeight = sum(o.items, o.rowHeight);
} else {
this.summaryHeight = this._isAutoHeight() ? 0 : o.rowHeight * o.items.length;
}
// 依赖于cache的占位元素也要初始化 // 依赖于cache的占位元素也要初始化
this.topBlank.setHeight(0); this.topBlank.setHeight(0);
this.bottomBlank.setHeight(0); this.bottomBlank.setHeight(0);

Loading…
Cancel
Save