From 2668c807be38054fef8d585bf4e013a29bb2117c Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 13 Nov 2023 15:48:37 +0800 Subject: [PATCH 1/2] =?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); From 697bc5bb239817a7d9a277f40e2ba356dbb0a7ef Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 20 Nov 2023 09:57:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20custom=5F?= =?UTF-8?q?tree=E6=94=AF=E6=8C=81hasNext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fineui/src/base/list/virtualgrouplist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fineui/src/base/list/virtualgrouplist.js b/packages/fineui/src/base/list/virtualgrouplist.js index 40bbaf9a5..e2e0d5ddf 100644 --- a/packages/fineui/src/base/list/virtualgrouplist.js +++ b/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"; /** @@ -201,7 +201,7 @@ export class VirtualGroupList extends Widget { const o = this.options; this.renderedIndex = -1; if (isFunction(o.rowHeight)) { - this.summaryHeight = BI.sum(o.items, o.rowHeight); + this.summaryHeight = sum(o.items, o.rowHeight); } else { this.summaryHeight = this._isAutoHeight() ? 0 : o.rowHeight * o.items.length; }