From 47ca2b4957639a6a630146d4f2992d87e8cc74fd Mon Sep 17 00:00:00 2001 From: gongbei Date: Fri, 13 Dec 2024 14:11:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E4=B8=8B=EF=BC=8C=E6=A0=91=E5=BD=A2=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=B1=95=E5=BC=80=E3=80=81=E6=94=B6=E8=B5=B7=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/cell/corner-cell.ts | 21 ++++++++++----------- packages/s2-core/src/cell/header-cell.ts | 17 ----------------- packages/s2-core/src/cell/row-cell.ts | 22 +++++++++++----------- packages/s2-core/src/utils/g-renders.ts | 7 +------ 4 files changed, 22 insertions(+), 45 deletions(-) diff --git a/packages/s2-core/src/cell/corner-cell.ts b/packages/s2-core/src/cell/corner-cell.ts index 2da4553ce9..55c8331ed8 100644 --- a/packages/s2-core/src/cell/corner-cell.ts +++ b/packages/s2-core/src/cell/corner-cell.ts @@ -87,28 +87,27 @@ export class CornerCell extends HeaderCell { values(collapseFields!).filter(Boolean).length === rootRowNodes.length || rootRowNodes.every((node) => node.isCollapsed); const isCollapsed = isAllCollapsed; - const { offsetXY, offsetWH } = this.getActionIconOffset(size); this.treeIcon = renderTreeIcon({ group: this, iconCfg: { - x: area.x - offsetXY, - y: this.getIconPosition().y - offsetXY, - width: size + offsetWH, - height: size + offsetWH, + x: area.x, + y: this.getIconPosition().y, + width: size, + height: size, fill, }, isCollapsed, onClick: () => { this.onTreeIconClick(isCollapsed); }, - onTouchEnd: () => { - /** - * 移动端时,绑定展开、收起事件 - */ - this.emitCollapseEvent(isCollapsed); - }, }); + // 移动端, 点击热区为整个单元格 + if (isMobile()) { + this.addEventListener('touchend', () => { + this.emitCollapseEvent(isCollapsed); + }); + } } protected isLastRowCornerCell() { diff --git a/packages/s2-core/src/cell/header-cell.ts b/packages/s2-core/src/cell/header-cell.ts index c473627b80..553d543048 100644 --- a/packages/s2-core/src/cell/header-cell.ts +++ b/packages/s2-core/src/cell/header-cell.ts @@ -43,7 +43,6 @@ import { } from '../utils/cell/header-cell'; import { findFieldCondition } from '../utils/condition/condition'; import { renderIcon } from '../utils/g-renders'; -import { isMobile } from '../utils/is-mobile'; import { getSortTypeIcon } from '../utils/sort-action'; export abstract class HeaderCell< @@ -520,20 +519,4 @@ export abstract class HeaderCell< public getActionIcons() { return this.actionIcons || []; } - - protected getActionIconOffset(iconSize: number) { - let offsetXY = 0; - let offsetWH = 0; - - // 移动端的时候,将icon变大,从而增加触发交互的面积 - if (isMobile()) { - offsetXY = iconSize / 4; - offsetWH = iconSize / 2; - } - - return { - offsetXY, - offsetWH, - }; - } } diff --git a/packages/s2-core/src/cell/row-cell.ts b/packages/s2-core/src/cell/row-cell.ts index ba62eb4b3d..0acb6d7ae5 100644 --- a/packages/s2-core/src/cell/row-cell.ts +++ b/packages/s2-core/src/cell/row-cell.ts @@ -155,28 +155,28 @@ export class RowCell extends HeaderCell { const iconX = x + contentIndent; const iconY = this.getIconPosition().y; - const { offsetXY, offsetWH } = this.getActionIconOffset(size); this.treeIcon = renderTreeIcon({ group: this, iconCfg: { - x: iconX - offsetXY, - y: iconY - offsetXY, - width: size + offsetWH, - height: size + offsetWH, + x: iconX, + y: iconY, + width: size, + height: size, fill, }, isCollapsed, onClick: () => { this.onTreeIconClick(); }, - onTouchEnd: () => { - /** - * 移动端时,绑定展开、收起事件 - */ - this.emitCollapseEvent(); - }, }); + + // 移动端, 点击热区为整个单元格 + if (isMobile()) { + this.addEventListener('touchend', () => { + this.emitCollapseEvent(); + }); + } } protected drawTreeLeafNodeAlignDot() { diff --git a/packages/s2-core/src/utils/g-renders.ts b/packages/s2-core/src/utils/g-renders.ts index 77fb2c9a74..a97f9b3189 100644 --- a/packages/s2-core/src/utils/g-renders.ts +++ b/packages/s2-core/src/utils/g-renders.ts @@ -130,9 +130,8 @@ export function renderTreeIcon(options: { isCollapsed?: boolean | null; iconCfg: Omit; onClick?: () => void; - onTouchEnd?: () => void; }) { - const { group, iconCfg, isCollapsed, onClick, onTouchEnd } = options; + const { group, iconCfg, isCollapsed, onClick } = options; const iconShape = renderIcon(group, { ...iconCfg, name: isCollapsed ? 'Plus' : 'Minus', @@ -143,9 +142,5 @@ export function renderTreeIcon(options: { iconShape.addEventListener('click', onClick); } - if (isFunction(onTouchEnd)) { - iconShape.addEventListener('touchend', onTouchEnd); - } - return iconShape; }