From b8a970f32a7289767788081b18e40af7c4b78dc7 Mon Sep 17 00:00:00 2001 From: Rui-Sun Date: Fri, 7 Jul 2023 10:59:49 +0800 Subject: [PATCH] feat: check textStick state before bind event --- packages/vtable/examples/menu.ts | 4 ++++ packages/vtable/src/event/event.ts | 10 ++++++---- .../vtable/src/scenegraph/stick-text/index.ts | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/vtable/examples/menu.ts b/packages/vtable/examples/menu.ts index 81a5186e5..b8dd8803f 100644 --- a/packages/vtable/examples/menu.ts +++ b/packages/vtable/examples/menu.ts @@ -6,6 +6,10 @@ export const menus = [ path: 'list', name: 'list' }, + { + path: 'list', + name: 'list-transpose' + }, { path: 'list', name: 'list-tree' diff --git a/packages/vtable/src/event/event.ts b/packages/vtable/src/event/event.ts index 4d0131d55..4a0c53080 100644 --- a/packages/vtable/src/event/event.ts +++ b/packages/vtable/src/event/event.ts @@ -11,7 +11,7 @@ import { bindMediaClick } from './media-click'; import { bindDrillEvent, drillClick } from './drill'; import { bindSparklineHoverEvent } from './sparkline-event'; import type { BaseTableAPI } from '../ts-types/base-table'; -import { handleTextStick } from '../scenegraph/stick-text'; +import { checkHaveTextStick, handleTextStick } from '../scenegraph/stick-text'; import { bindTableGroupListener } from './listener/table-group'; import { bindScrollBarListener } from './listener/scroll-bar'; import { bindContainerDomListener } from './listener/container-dom'; @@ -74,9 +74,11 @@ export class EventManeger { }); // 处理textStick - this.table.listen(TABLE_EVENT_TYPE.SCROLL, e => { - handleTextStick(this.table); - }); + if (checkHaveTextStick(this.table)) { + this.table.listen(TABLE_EVENT_TYPE.SCROLL, e => { + handleTextStick(this.table); + }); + } // link/image/video点击 bindMediaClick(this.table); diff --git a/packages/vtable/src/scenegraph/stick-text/index.ts b/packages/vtable/src/scenegraph/stick-text/index.ts index a5a6f3fad..a0d74bb79 100644 --- a/packages/vtable/src/scenegraph/stick-text/index.ts +++ b/packages/vtable/src/scenegraph/stick-text/index.ts @@ -4,6 +4,7 @@ import { PIVOT_TABLE_EVENT_TYPE } from '../../ts-types/pivot-table/PIVOT_TABLE_E import type { Group } from '../graphic/group'; import type { WrapText } from '../graphic/text'; import type { PivotHeaderLayoutMap } from '../../layout/pivot-header-layout'; +import type { ITextStyleOption } from '../../ts-types'; const changedCells: { col: number; row: number }[] = []; export function handleTextStick(table: BaseTableAPI) { changedCells.forEach(cellPos => { @@ -133,3 +134,21 @@ function adjustCellContentHorizontalLayout(cellGroup: Group, minLeft: number, ma }); } } + +export function checkHaveTextStick(table: BaseTableAPI) { + const headerObjects = table.internalProps.layoutMap.headerObjects; + const columnObjects = table.internalProps.layoutMap.columnObjects; + for (let i = 0; i < headerObjects.length; i++) { + const header = headerObjects[i]; + if (header && (header.define.headerStyle as ITextStyleOption)?.textStick) { + return true; + } + } + for (let i = 0; i < columnObjects.length; i++) { + const column = columnObjects[i]; + if (column && (column.define.style as ITextStyleOption)?.textStick) { + return true; + } + } + return false; +}