Skip to content

Commit

Permalink
feat: check textStick state before bind event
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Jul 7, 2023
1 parent f587d63 commit b8a970f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/vtable/examples/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const menus = [
path: 'list',
name: 'list'
},
{
path: 'list',
name: 'list-transpose'
},
{
path: 'list',
name: 'list-tree'
Expand Down
10 changes: 6 additions & 4 deletions packages/vtable/src/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions packages/vtable/src/scenegraph/stick-text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
}

0 comments on commit b8a970f

Please sign in to comment.