Skip to content

Commit 1b17d50

Browse files
committed
v1.4.2-patch.2 - bugfix: tasklist列宽度设置问题
1 parent cacaece commit 1b17d50

File tree

10 files changed

+140
-15
lines changed

10 files changed

+140
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.4.2-patch2] - 2025-11-11
9+
10+
### Fixed
11+
- 缺陷修复:TaskList配置列宽无效的问题修复
12+
- Defect fix: Fixed the issue of invalid column width configuration in TaskList
13+
814
## [1.4.2-patch1] - 2025-11-03
915

1016
### Fixed

demo/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const toolbarConfig = {
4848
// TaskList列配置
4949
const availableColumns = ref<TaskListColumnConfig[]>([
5050
{ key: 'predecessor', label: '前置任务', visible: true },
51-
{ key: 'assignee', label: '负责人', visible: true },
51+
{ key: 'assignee', label: '负责人', visible: true, width: 250 },
5252
{ key: 'startDate', label: '开始日期', visible: true },
5353
{ key: 'endDate', label: '结束日期', visible: true },
5454
{ key: 'estimatedHours', label: '预估工时', visible: true },
5555
{ key: 'actualHours', label: '实际工时', visible: true },
5656
{ key: 'progress', label: '进度', visible: true },
57-
{ key: 'custom', label: '自定义列', visible: true, width: 120 }, // 添加默认宽度120px
57+
{ key: 'custom', label: '自定义列', visible: true, width: '30%' }, // 添加默认宽度120px
5858
])
5959
6060
// TaskList宽度配置

demo/version-history.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,15 @@
276276
"Defect fix: Fixed the issue of infinite loop calls when updating child tasks after updating the parent task",
277277
"<span style=\"font-weight: bold; color: #f00;\">Special thanks to Ky1in666@github for their valuable use and feedback</span>"
278278
]
279+
},
280+
{
281+
"version": "1.4.2-patch2",
282+
"date": "2025-11-11",
283+
"notes": [
284+
"缺陷修复:TaskList配置列宽无效的问题修复",
285+
"<span style=\"font-weight: bold; color: #f00;\">特别感谢 @SHENGLONG749的使用及反馈的宝贵意见</span>",
286+
"Defect fix: Fixed the issue of invalid column width configuration in TaskList",
287+
"<span style=\"font-weight: bold; color: #f00;\">Special thanks to @SHENGLONG749 for their valuable use and feedback</span>"
288+
]
279289
}
280290
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jordium-gantt-vue3",
3-
"version": "1.4.2-pacth.1",
3+
"version": "1.4.2-patch.2",
44
"type": "module",
55
"main": "dist/jordium-gantt-vue3.cjs.js",
66
"module": "dist/jordium-gantt-vue3.es.js",

src/components/GanttChart.vue

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,45 @@ function onMouseDown(e: MouseEvent) {
299299
taskListBodyProposedWidth.value = window.innerWidth * 0.8 - 6 // 减去splitter宽度
300300
301301
// 获取左侧面板的最小宽度
302-
taskListBodyWidthLimit.value = Math.min(taskListBodyProposedWidth.value, taskListBodyWidth.value)
302+
taskListBodyWidthLimit.value = Math.min(taskListBodyProposedWidth.value,
303+
taskListBodyWidthLimit.value)
303304
304305
// 广播拖拽开始事件,通知其他组件暂停悬停效果
305306
window.dispatchEvent(new CustomEvent('splitter-drag-start'))
306307
307-
// 在拖拽期间禁用页面选择
308+
// 在拖拽期间禁用页面选择和所有指针事件
308309
document.body.style.userSelect = 'none'
309310
document.body.style.webkitUserSelect = 'none'
310311
document.body.style.cursor = 'col-resize'
312+
document.body.style.pointerEvents = 'none' // 禁止所有指针事件
313+
314+
// 全局事件拦截器:在捕获阶段拦截所有事件(除了 mousemove 和 mouseup)
315+
const blockAllEvents = (ev: Event) => {
316+
if (ev.type !== 'mousemove' && ev.type !== 'mouseup') {
317+
ev.preventDefault()
318+
ev.stopPropagation()
319+
ev.stopImmediatePropagation()
320+
}
321+
}
322+
323+
// 在捕获阶段添加事件监听,确保最先拦截
324+
document.addEventListener('mousedown', blockAllEvents, { capture: true })
325+
document.addEventListener('click', blockAllEvents, { capture: true })
326+
document.addEventListener('dblclick', blockAllEvents, { capture: true })
327+
document.addEventListener('mouseover', blockAllEvents, { capture: true })
328+
document.addEventListener('mouseout', blockAllEvents, { capture: true })
329+
document.addEventListener('mouseenter', blockAllEvents, { capture: true })
330+
document.addEventListener('mouseleave', blockAllEvents, { capture: true })
331+
document.addEventListener('wheel', blockAllEvents, { capture: true, passive: false })
332+
document.addEventListener('contextmenu', blockAllEvents, { capture: true })
311333
312334
function onMouseMove(ev: MouseEvent) {
313335
if (!dragging.value) return
314336
315-
// 阻止默认行为,防止滚动等
337+
// 强制阻止所有默认行为和事件传播
316338
ev.preventDefault()
317339
ev.stopPropagation()
340+
ev.stopImmediatePropagation()
318341
319342
const delta = ev.clientX - startX
320343
const proposedWidth = startWidth + delta
@@ -327,13 +350,25 @@ function onMouseDown(e: MouseEvent) {
327350
function onMouseUp() {
328351
dragging.value = false
329352
353+
// 移除全局事件拦截器
354+
document.removeEventListener('mousedown', blockAllEvents, { capture: true })
355+
document.removeEventListener('click', blockAllEvents, { capture: true })
356+
document.removeEventListener('dblclick', blockAllEvents, { capture: true })
357+
document.removeEventListener('mouseover', blockAllEvents, { capture: true })
358+
document.removeEventListener('mouseout', blockAllEvents, { capture: true })
359+
document.removeEventListener('mouseenter', blockAllEvents, { capture: true })
360+
document.removeEventListener('mouseleave', blockAllEvents, { capture: true })
361+
document.removeEventListener('wheel', blockAllEvents, { capture: true })
362+
document.removeEventListener('contextmenu', blockAllEvents, { capture: true })
363+
330364
// 广播拖拽结束事件,通知其他组件恢复悬停效果
331365
window.dispatchEvent(new CustomEvent('splitter-drag-end'))
332366
333-
// 恢复页面选择和光标
367+
// 恢复页面选择、光标和指针事件
334368
document.body.style.userSelect = ''
335369
document.body.style.webkitUserSelect = ''
336370
document.body.style.cursor = ''
371+
document.body.style.pointerEvents = ''
337372
338373
taskListBodyWidth.value = getTaskListMaxWidth() // TaskList默认宽度
339374
ganttPanelLeftMinWidth.value = getTaskListMinWidth() // 左侧面板最小宽度

src/components/TaskBar.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,6 @@ watch(
15721572
const safeNewContainerWidth = newContainerWidth || 0
15731573
const safeOldScrollLeft = oldScrollLeft || 0
15741574
const safeOldContainerWidth = oldContainerWidth || 0
1575-
15761575
// 如果容器宽度发生变化(包括Splitter拖拽、TaskList展开收起、窗口resize等)
15771576
if (Math.abs(safeNewContainerWidth - safeOldContainerWidth) > 1 && safeOldContainerWidth > 0) {
15781577
hasManualResize.value = true
@@ -1583,6 +1582,13 @@ watch(
15831582
// computed会自动重新计算
15841583
})
15851584
1585+
// 🔥 容器宽度变化时,标记初始化完成(修复 splitter 拖拽后半圆不显示的问题)
1586+
if (isInitializing.value) {
1587+
setTimeout(() => {
1588+
isInitializing.value = false
1589+
}, 300)
1590+
}
1591+
15861592
// 延长禁用动画的时间,确保各种resize操作稳定
15871593
setTimeout(() => {
15881594
hasManualResize.value = false
@@ -1622,6 +1628,7 @@ watch(
16221628
}, 200)
16231629
}
16241630
},
1631+
{ immediate: true },
16251632
)
16261633
16271634
// 监听外部hideBubbles属性变化,确保Timeline的容器变化能及时反应

src/components/TaskList.vue

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ const hasRowSlot = computed(() => Boolean(slots['custom-task-content']))
3333
// 多语言支持
3434
const { t } = useI18n()
3535
36+
// TaskList 容器引用
37+
const taskListRef = ref<HTMLElement | null>(null)
38+
39+
// 获取列宽度样式(百分比转像素)
40+
const getColumnWidthStyle = (column: { width?: number | string }) => {
41+
if (!column.width) return {}
42+
43+
let widthPx: string
44+
45+
// 如果是百分比,转换为像素
46+
if (typeof column.width === 'string' && column.width.includes('%')) {
47+
const containerWidth = taskListRef.value?.offsetWidth || 0
48+
if (containerWidth > 0) {
49+
const percentage = parseFloat(column.width) / 100
50+
const pixels = Math.floor(containerWidth * percentage)
51+
widthPx = `${pixels}px`
52+
} else {
53+
return {} // 容器宽度未知时返回空
54+
}
55+
} else {
56+
// 像素值
57+
widthPx = `${column.width}px`
58+
}
59+
60+
return {
61+
flex: `0 0 ${widthPx}`,
62+
minWidth: widthPx,
63+
maxWidth: widthPx,
64+
}
65+
}
66+
3667
// 计算可见的列配置
3768
const visibleColumns = computed(() => {
3869
const columns = props.taskListConfig?.columns || DEFAULT_TASK_LIST_COLUMNS
@@ -385,7 +416,7 @@ onUnmounted(() => {
385416
</script>
386417

387418
<template>
388-
<div class="task-list">
419+
<div ref="taskListRef" class="task-list">
389420
<div class="task-list-header">
390421
<!-- 任务名称列,始终显示 -->
391422
<div class="col col-name">
@@ -397,13 +428,13 @@ onUnmounted(() => {
397428
:key="column.key"
398429
class="col"
399430
:class="column.cssClass || `col-${column.key}`"
400-
:style="column.width ? { width: column.width + 'px' } : undefined"
431+
:style="getColumnWidthStyle(column)"
401432
>
402433
{{ (t as any)[column.key] || column.label }}
403434
</div>
404435
</div>
405436
<div class="task-list-body" @scroll="handleTaskListScroll">
406-
<TaskRow
437+
<TaskRow
407438
v-for="task in localTasks"
408439
:key="task.id"
409440
:task="task"
@@ -412,6 +443,7 @@ onUnmounted(() => {
412443
:hovered-task-id="hoveredTaskId"
413444
:on-hover="handleTaskRowHover"
414445
:columns="visibleColumns"
446+
:get-column-width-style="getColumnWidthStyle"
415447
@toggle="toggleCollapse"
416448
@dblclick="handleTaskRowDoubleClick"
417449
@contextmenu="handleTaskRowContextMenu"

src/components/TaskRow.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface Props {
3535
hoveredTaskId?: number | null
3636
onHover?: (taskId: number | null) => void
3737
columns: TaskListColumnConfig[]
38+
getColumnWidthStyle?: (column: { width?: number | string }) => object
3839
}
3940
const props = defineProps<Props>()
4041
const emit = defineEmits([
@@ -410,6 +411,7 @@ onUnmounted(() => {
410411
:key="column.key"
411412
class="col"
412413
:class="column.cssClass || `col-${column.key}`"
414+
:style="getColumnWidthStyle ? getColumnWidthStyle(column) : {}"
413415
>
414416
<!-- 里程碑分组显示空列 -->
415417
<template v-if="isMilestoneGroup">
@@ -476,6 +478,7 @@ onUnmounted(() => {
476478
:hovered-task-id="props.hoveredTaskId"
477479
:on-hover="props.onHover"
478480
:columns="props.columns"
481+
:get-column-width-style="props.getColumnWidthStyle"
479482
@toggle="emit('toggle', $event)"
480483
@dblclick="emit('dblclick', $event)"
481484
@start-timer="emit('start-timer', $event)"

src/components/Timeline.vue

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ const timelineContainerWidth = ref(0)
631631
// 半圆气泡控制状态
632632
const hideBubbles = ref(true) // 初始时隐藏半圆,等待初始滚动完成
633633
const isInitialScrolling = ref(true) // 跟踪初始滚动状态
634+
let hideBubblesTimeout: number | null = null // 半圆显示恢复定时器
634635
635636
// 虚拟滚动相关状态
636637
const HOUR_WIDTH = 40 // 每小时40px
@@ -945,6 +946,15 @@ const handleSplitterDragStart = () => {
945946
const handleSplitterDragEnd = () => {
946947
isSplitterDragging.value = false
947948
949+
// 拖拽结束后,手动触发一次容器宽度更新
950+
const timelineContainer = document.querySelector('.timeline') as HTMLElement
951+
if (timelineContainer) {
952+
const newWidth = timelineContainer.clientWidth
953+
if (Math.abs(newWidth - timelineContainerWidth.value) > 1) {
954+
timelineContainerWidth.value = newWidth
955+
}
956+
}
957+
948958
// Splitter拖拽结束后,强制重新计算半圆显示状态
949959
// 因为Timeline容器宽度可能发生了变化
950960
hideBubbles.value = true
@@ -964,9 +974,15 @@ const handleTimelineContainerResized = () => {
964974
taskBarPositions.value = {}
965975
taskBarRenderKey.value++
966976
977+
// 清除之前的定时器,避免多次触发冲突
978+
if (hideBubblesTimeout) {
979+
clearTimeout(hideBubblesTimeout)
980+
}
981+
967982
// 延迟恢复显示,确保容器变化完全生效
968-
setTimeout(() => {
983+
hideBubblesTimeout = setTimeout(() => {
969984
hideBubbles.value = false
985+
hideBubblesTimeout = null
970986
// 再次更新SVG尺寸,确保关系线容器大小正确
971987
updateSvgSize()
972988
}, 300)
@@ -2053,9 +2069,15 @@ onMounted(() => {
20532069
// 短时间隐藏后重新显示,让TaskBar重新计算边界
20542070
hideBubbles.value = true
20552071
2072+
// 清除之前的定时器,避免多次触发冲突
2073+
if (hideBubblesTimeout) {
2074+
clearTimeout(hideBubblesTimeout)
2075+
}
2076+
20562077
// 延迟恢复显示,确保宽度变化完全生效
2057-
setTimeout(() => {
2078+
hideBubblesTimeout = setTimeout(() => {
20582079
hideBubbles.value = false
2080+
hideBubblesTimeout = null
20592081
}, 300) // 增加到300ms,确保resize完全结束
20602082
}
20612083
}
@@ -2546,12 +2568,19 @@ watch(
25462568
)
25472569
25482570
// 监听滚动变化,重新计算里程碑位置
2549-
watch([timelineScrollLeft, timelineContainerWidth], computeAllMilestonesPositions)
2571+
watch([timelineScrollLeft, timelineContainerWidth], () => {
2572+
// 拖拽 splitter 时跳过计算
2573+
if (isSplitterDragging.value) return
2574+
computeAllMilestonesPositions()
2575+
})
25502576
25512577
// 监听容器宽度变化,重新计算时间线范围以填充容器
25522578
watch(
25532579
timelineContainerWidth,
25542580
(newWidth, oldWidth) => {
2581+
// ⚠️ 拖拽 splitter 时跳过重新计算,避免频繁生成 timelineData
2582+
if (isSplitterDragging.value) return
2583+
25552584
// 只在容器宽度从 0 变为有效值,或容器宽度发生显著变化时重新计算
25562585
if (!oldWidth || oldWidth === 0 || Math.abs(newWidth - oldWidth) > 50) {
25572586
if (newWidth > 0) {
@@ -2593,6 +2622,9 @@ watch(
25932622
25942623
// 监听timelineData或容器宽度变化,强制TaskBar重新渲染以更新关系线位置
25952624
watch([timelineData, timelineContainerWidth], () => {
2625+
// ⚠️ 拖拽 splitter 时跳过 TaskBar 重新渲染,避免频繁更新
2626+
if (isSplitterDragging.value) return
2627+
25962628
// 清空位置信息
25972629
taskBarPositions.value = {}
25982630
// 更新渲染key强制TaskBar重新渲染

src/models/configs/TaskListConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface TaskListColumnConfig {
1515
key: string // 用于国际化的key,也可以作为识别符
1616
label?: string // 显示标签
1717
cssClass?: string // CSS类名
18-
width?: number // 可选的列宽度
18+
width?: number | string // 列宽度,支持像素(120)或百分比('15%')
1919
visible?: boolean // 是否显示,默认true
2020
}
2121

0 commit comments

Comments
 (0)