Skip to content

[Bug] getTaskBarRelativeRect 在空任务行调用报错,且在紧凑模式下无法获取同一行所有子任务位置 #4778

Description

@yueyan-zm

Version

1.22.5

Link to Minimal Reproduction

https://codesandbox.io/p/sandbox/blue-violet-lmvdjx?file=%2Fsrc%2Findex.mjs%3A70%2C7

Steps to Reproduce

  1. 初始化 VTable Gantt,设置 tasksShowModeSub_Tasks_Inline(或 Sub_Tasks_Compact,即子任务在同一行显示的模式)。
  2. 构造数据场景:
    • 场景A:某一行的任务数据为空(例如没有子任务,或者时间无效导致未渲染任务条)。
    • 场景B:某一行的任务数据包含多个子任务(例如同一行显示了 Task 1-1 和 Task 1-2)。
  3. 调用 API ganttInstance.getTaskBarRelativeRect(taskIndex)
// Example Code Logic
const gantt = new VTableGantt.Gantt(dom, {
  tasksShowMode: VTableGantt.TYPES.TasksShowMode.Sub_Tasks_Inline,
  // ...
});

// 1. Trigger error
// Assuming index 0 has no valid task bar to render
try {
  gantt.getTaskBarRelativeRect(0); 
} catch (e) {
  console.error(e); // TypeError: Cannot read properties of null (reading 'attribute')
}

// 2. Trigger incorrect return value
// Assuming index 1 has multiple sub-tasks on the same row
const rect = gantt.getTaskBarRelativeRect(1);
console.log(rect); // Only returns the rect of the FIRST sub-task, ignoring others.

Current Behavior

  1. 报错问题:当对没有渲染任务条的行索引调用 getTaskBarRelativeRect 时,内部代码未做判空处理,直接访问图形属性导致抛出 TypeError: Cannot read properties of null (reading 'attribute'),导致程序中断。
  2. 逻辑问题:在紧凑/内联视图模式下,一行内会渲染多个任务条,但目前的 API 仅返回该行 第一个 任务条的位置信息,导致开发者无法获取该行剩余任务的位置(用于自定义悬浮层等场景)。

Expected Behavior

  1. 健壮性:方法内部应增加空值检查。如果该行未渲染任何任务条,应返回 nullundefined,而不是抛出异常。
  2. 完整性:针对多任务共存一行的场景,该 API 应该支持返回一个位置数组 Rect[],包含该行所有可视任务条的位置信息;或者提供参数支持获取特定子任务。

Environment

- OS: macOS
- Browser: Chrome
- Framework: Vue

Any additional comments?

该问题导致在开发“任务条吸附图标”或“自定义 Overlay”功能时,无法处理紧凑视图下的多任务定位,且容易因为空数据行导致页面崩溃。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions