From 2668c807be38054fef8d585bf4e013a29bb2117c Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 13 Nov 2023 15:48:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20rowHeight?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=80=E4=B8=8B=E4=BC=A0function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fineui/src/base/list/virtualgrouplist.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/fineui/src/base/list/virtualgrouplist.js b/packages/fineui/src/base/list/virtualgrouplist.js index 06edd5692..40bbaf9a5 100644 --- a/packages/fineui/src/base/list/virtualgrouplist.js +++ b/packages/fineui/src/base/list/virtualgrouplist.js @@ -17,7 +17,7 @@ export class VirtualGroupList extends Widget { overscanHeight: 100, blockSize: 10, scrollTop: 0, - rowHeight: "auto", + rowHeight: "auto", // 'auto' 或 数值 或function items: [], el: {}, itemFormatter: (item, index) => item, @@ -97,7 +97,7 @@ export class VirtualGroupList extends Widget { } _isAutoHeight() { - return !isNumber(this.options.rowHeight); + return this.options.rowHeight === 'auto'; } _renderMoreIf() { @@ -163,7 +163,7 @@ export class VirtualGroupList extends Widget { itemsArr.push(items[j]); } } - this.container.element.height(rowHeight * items.length - topHeight); + this.container.element.height(this.summaryHeight - topHeight); this.container.populate( 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), 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(); try { @@ -188,7 +198,13 @@ export class VirtualGroupList extends Widget { } _restore() { + const o = this.options; this.renderedIndex = -1; + if (isFunction(o.rowHeight)) { + this.summaryHeight = BI.sum(o.items, o.rowHeight); + } else { + this.summaryHeight = this._isAutoHeight() ? 0 : o.rowHeight * o.items.length; + } // 依赖于cache的占位元素也要初始化 this.topBlank.setHeight(0); this.bottomBlank.setHeight(0);