diff --git a/common/changes/@visactor/vtable/feat-isShowOverflowTextTooltip-func_2024-11-18-13-51.json b/common/changes/@visactor/vtable/feat-isShowOverflowTextTooltip-func_2024-11-18-13-51.json new file mode 100644 index 000000000..b7e2c7178 --- /dev/null +++ b/common/changes/@visactor/vtable/feat-isShowOverflowTextTooltip-func_2024-11-18-13-51.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vtable", + "comment": "feat: isShowOverflowTextTooltip support function", + "type": "none" + } + ], + "packageName": "@visactor/vtable" +} \ No newline at end of file diff --git a/packages/vtable/src/components/tooltip/TooltipHandler.ts b/packages/vtable/src/components/tooltip/TooltipHandler.ts index 6ba0568ca..388842adb 100644 --- a/packages/vtable/src/components/tooltip/TooltipHandler.ts +++ b/packages/vtable/src/components/tooltip/TooltipHandler.ts @@ -8,6 +8,7 @@ import { isMobile } from '../../tools/util'; import type { TooltipOptions } from '../../ts-types/tooltip'; import { TABLE_EVENT_TYPE } from '../../core/TABLE_EVENT_TYPE'; import type { BaseTableAPI } from '../../ts-types/base-table'; +import { isFunction } from '@visactor/vutils'; const TOOLTIP_INSTANCE_FACTORY = { // tooltip(table: BaseTableAPI): BaseTooltip { // return new Tooltip(table); @@ -201,7 +202,11 @@ export class TooltipHandler { disappearDelay: table.internalProps.tooltip.overflowTextTooltipDisappearDelay ?? 0, style: table.theme.tooltipStyle }; - } else if (table.internalProps.tooltip?.isShowOverflowTextTooltip) { + } else if ( + (isFunction(table.internalProps.tooltip?.isShowOverflowTextTooltip) && + table.internalProps.tooltip.isShowOverflowTextTooltip(col, row, table)) || + table.internalProps.tooltip.isShowOverflowTextTooltip + ) { const overflowText = table.getCellOverflowText(col, row); const rect = table.getCellRangeRelativeRect({ col, row }); if (overflowText) { diff --git a/packages/vtable/src/ts-types/base-table.ts b/packages/vtable/src/ts-types/base-table.ts index d58842ea3..7d3fad6b7 100644 --- a/packages/vtable/src/ts-types/base-table.ts +++ b/packages/vtable/src/ts-types/base-table.ts @@ -206,7 +206,7 @@ export interface IBaseTableProtected { parentElement: HTMLElement; renderMode: 'html' | 'canvas'; /** 代替原来hover:isShowTooltip配置 */ - isShowOverflowTextTooltip: boolean; + isShowOverflowTextTooltip: boolean | ((col: number, row: number, table: BaseTableAPI) => boolean); /** 缩略文字提示框 延迟消失时间 */ overflowTextTooltipDisappearDelay?: number; /** 弹框是否需要限定在表格区域内 */ @@ -397,7 +397,7 @@ export interface BaseTableConstructorOptions { /** html目前实现较完整 先默认html渲染方式 */ renderMode?: 'html'; // 目前暂不支持canvas方案 /** 是否显示缩略文字提示框。 代替原来hover:isShowTooltip配置 暂时需要将renderMode配置为html才能显示,canvas的还未开发*/ - isShowOverflowTextTooltip?: boolean; + isShowOverflowTextTooltip?: boolean | ((col: number, row: number, table: BaseTableAPI) => boolean); /** 缩略文字提示框 延迟消失时间 */ overflowTextTooltipDisappearDelay?: number; /** 是否将 tooltip 框限制在画布区域内,默认开启。针对renderMode:"html"有效 */