/* * @Author: 疯狂秀才(Lucas Huang) * @Date: 2019-05-23 10:27:09 * @LastEditors: 疯狂秀才(Lucas Huang) * @LastEditTime: 2019-09-02 09:08:25 * @QQ: 1055818239 * @Version: v0.0.1 */ import { TreeTableComponent } from './treetable.component'; import { RowNode } from './types/treenode'; export class VirtualizedLoaderService { constructor(private tt: TreeTableComponent) {} getTableHeight() { return this.tt.height; } getTableHeaderHeight() { return this.tt.headerBox.nativeElement.getBoundingClientRect().height; } getTableBodyHeight() { return this.tt.height - this.getTableHeaderHeight(); } getTableWidth() { return this.tt.width; } getRowHeight() { return this.tt.rowHeight; } getRowNodes(scrollTop: number) { let top = 0; const rows = []; let topHideHeight = 0; let bottomHideHeight = 0; const {rowNodes } = this.tt.state; const rowHeight = this.getRowHeight(); const minTop = scrollTop; const maxTop = minTop + this.getTableHeight() + rowHeight; // console.time('循环所有节点'); for (let i = 0; i < rowNodes.length; i++) { const n: RowNode = rowNodes[i]; if ( !n.visible) { continue; } top += rowHeight; if (top + rowHeight < minTop) { topHideHeight += rowHeight; continue; } else { if (top > maxTop) { bottomHideHeight += rowHeight; continue; } } rows.push(n); } // console.timeEnd('循环所有节点'); return { data: rows, topHideHeight, bottomHideHeight }; } }