merge: 修复 TaskTree 时间轴视觉问题

This commit is contained in:
root
2026-07-21 13:38:38 +02:00
3 changed files with 65 additions and 27 deletions
+25 -6
View File
@@ -154,7 +154,12 @@ export class TaskTreeStore {
LEFT JOIN tasktree_tasks t ON t.group_id=g.id
LEFT JOIN tasktree_execution_reports r ON r.task_id=t.id
GROUP BY g.id
ORDER BY g.updated_at DESC, g.name
ORDER BY GREATEST(
g.updated_at,
COALESCE(MAX(t.updated_at),g.updated_at),
COALESCE(MAX(r.created_at),g.updated_at),
COALESCE((SELECT MAX(m.created_at) FROM tasktree_milestones m WHERE m.group_id=g.id),g.updated_at)
) DESC, g.name
`);
return result.rows.map(overviewRow);
}
@@ -338,11 +343,25 @@ export class TaskTreeStore {
async createReport(input: { taskId: string; title: string; body: string; status?: string }): Promise<ExecutionReport> {
await this.ensureSchema();
const result = await this.pool.query(
"INSERT INTO tasktree_execution_reports (id,task_id,title,body,status) VALUES ($1,$2,$3,$4,$5) RETURNING *",
[`tr_${randomUUID()}`, input.taskId, input.title, input.body, input.status ?? "succeeded"]
);
return reportRow(result.rows[0]);
const client = await this.pool.connect();
try {
await client.query("BEGIN");
const result = await client.query(
"INSERT INTO tasktree_execution_reports (id,task_id,title,body,status) VALUES ($1,$2,$3,$4,$5) RETURNING *",
[`tr_${randomUUID()}`, input.taskId, input.title, input.body, input.status ?? "succeeded"]
);
await client.query(
"UPDATE tasktree_groups g SET updated_at=now() FROM tasktree_tasks t WHERE t.id=$1 AND g.id=t.group_id",
[input.taskId]
);
await client.query("COMMIT");
return reportRow(result.rows[0]);
} catch (error) {
await client.query("ROLLBACK").catch(() => {});
throw error;
} finally {
client.release();
}
}
async listReports(taskId: string): Promise<ExecutionReport[]> {
@@ -56,7 +56,7 @@ const combinedMarkdown = computed(() => {
});
function plainTitle(task: TaskTreeTask) {
return task.title.replace(/^R\d+(?:\.\d+){0,2}\s+/u, "").replace(/\[([^\]]+)\]\([^)]+\)/gu, "$1").replace(/`([^`]+)`/gu, "$1").trim();
return task.title.replace(/\[([^\]]+)\]\([^)]+\)/gu, "$1").replace(/`([^`]+)`/gu, "$1").trim();
}
function plainReportTitle(report: TaskTreeReport) {
return report.title.replace(/\[([^\]]+)\]\([^)]+\)/gu, "$1").replace(/`([^`]+)`/gu, "$1").trim();
@@ -20,6 +20,7 @@ const collapsedTaskIds = ref(new Set<string>());
const timelineHeaderElement = ref<HTMLElement | null>(null);
const taskLabelsElement = ref<HTMLElement | null>(null);
const timelineBodyElement = ref<HTMLElement | null>(null);
const timelineScrollbarWidth = ref(0);
const labelChildScrollers = new Map<string, HTMLElement>();
const timelineChildScrollers = new Map<string, HTMLElement>();
const initializedChildGroups = new Set<string>();
@@ -28,6 +29,7 @@ const timelineScaleIndex = ref(1);
const taskColumnWidth = ref(typeof window !== "undefined" ? Math.round(window.innerWidth * (window.innerWidth <= 720 ? 0.55 : 0.21)) : 400);
const loading = ref(false);
const error = ref<string | null>(null);
let positionedView = "";
const groupId = computed(() => String(route.params.groupId || ""));
const displayTime = displayTimeConfig();
const displayPartsFormatter = new Intl.DateTimeFormat(displayTime.locale, {
@@ -113,6 +115,8 @@ async function loadActiveView() {
if (!groupId.value) {
timeline.value = null;
loading.value = false;
await nextTick();
positionTimelineAtNow("global");
return;
}
const timelineResponse = await tasktreeAPI.timeline(groupId.value);
@@ -124,6 +128,8 @@ async function loadActiveView() {
timeline.value = timelineResponse.data.data;
initializedChildGroups.clear();
syncSelectedTaskFromRoute();
await nextTick();
positionTimelineAtNow(groupId.value);
}
function selectGroup(event: Event) {
const value = (event.target as HTMLSelectElement).value;
@@ -282,13 +288,18 @@ async function changeTimelineScale(direction: -1 | 1) {
function syncTimelineBody() {
const body = timelineBodyElement.value;
if (!body) return;
timelineScrollbarWidth.value = Math.max(0, body.offsetWidth - body.clientWidth);
if (timelineHeaderElement.value && timelineHeaderElement.value.scrollLeft !== body.scrollLeft) timelineHeaderElement.value.scrollLeft = body.scrollLeft;
if (taskLabelsElement.value && taskLabelsElement.value.scrollTop !== body.scrollTop) taskLabelsElement.value.scrollTop = body.scrollTop;
}
function syncTimelineHeader() {
const header = timelineHeaderElement.value;
function positionTimelineAtNow(view: string) {
const body = timelineBodyElement.value;
if (header && body && body.scrollLeft !== header.scrollLeft) body.scrollLeft = header.scrollLeft;
if (!body || positionedView === view) return;
timelineScrollbarWidth.value = Math.max(0, body.offsetWidth - body.clientWidth);
const now = todayOffset.value;
body.scrollLeft = now === null ? 0 : Math.max(0, Math.min(body.scrollWidth - body.clientWidth, body.scrollWidth * now / 100 - body.clientWidth * 0.8));
if (timelineHeaderElement.value) timelineHeaderElement.value.scrollLeft = body.scrollLeft;
positionedView = view;
}
function syncTaskLabels() {
const labels = taskLabelsElement.value;
@@ -321,8 +332,10 @@ function displaySerial(date: Date) { const parts = displayParts(date); return Da
function displayDaySerial(date: Date) { const parts = displayParts(date); return Date.UTC(parts.year, parts.month - 1, parts.day); }
function barStyle(item: { startAt: string | null; dueAt: string | null }) {
const start = displaySerial(new Date(item.startAt || item.dueAt || range.value.start)); const end = displaySerial(new Date(item.dueAt || item.startAt || range.value.start)); const unit = 100 / range.value.dayCount;
const left = Math.max(0, (start - displaySerial(range.value.start)) / 86400000) * unit; const width = Math.max(unit * 0.65, ((end - start) / 86400000) * unit);
return { left: `${left}%`, width: `${Math.min(100 - left, width)}%` };
const rangeStart = displaySerial(range.value.start);
const left = Math.max(0, (start - rangeStart) / 86400000) * unit;
const rightEdge = Math.min(100, Math.max(left, (end - rangeStart) / 86400000 * unit));
return { right: `${100 - rightEdge}%`, width: `${Math.max(0, rightEdge - left)}%` };
}
function trackStyle() {
return {
@@ -357,7 +370,6 @@ function tickClass(date: Date) {
};
}
function statusLabel(status: string) { return ({ pending: "待处理", in_progress: "进行中", completed: "已完成", blocked: "阻塞" } as Record<string, string>)[status] || status; }
function displayTaskTitle(task: TaskTreeTask) { return task.title.replace(/^R\d+(?:\.\d+){0,2}\s+/u, ""); }
function taskKindLabel(kind: TaskTreeTask["kind"]) { return ({ task: "Task", subtask: "Subtask", subsubtask: "Subsubtask" })[kind]; }
function plainTaskTitle(task: TaskTreeTask | null) {
return String(task?.title || "任务详情").replace(/\[([^\]]+)\]\([^)]+\)/gu, "$1").replace(/`([^`]+)`/gu, "$1").trim();
@@ -394,7 +406,14 @@ function syncSelectedTaskFromRoute() {
<template>
<main class="tasktree-page" data-testid="tasktree-page">
<AsyncBoundary :state="asyncState" title="TaskTree 暂无任务" :message="error || '通过 CLI 创建 taskgroup 和任务后会显示在时间轴中。'" @retry="loadActiveView">
<AsyncBoundary
:state="asyncState"
empty-title="TaskTree 暂无任务"
empty-description="通过 CLI 创建 taskgroup 和任务后会显示在时间轴中"
error-title="TaskTree 加载失败"
:error="error || '请求未完成,请稍后重试。'"
@retry="loadActiveView"
>
<div v-if="isGlobalView || timeline" class="tasktree-view-layout" :class="{ docked: detailMode === 'docked' && selectedTask }">
<section class="tasktree-workspace" aria-label="TaskTree 甘特图">
<header class="tasktree-context">
@@ -417,7 +436,7 @@ function syncSelectedTaskFromRoute() {
<button class="icon-button tasktree-refresh" type="button" title="刷新" aria-label="刷新" :disabled="loading" @click="loadActiveView"><RefreshCw :size="15" aria-hidden="true" /></button>
</div>
</header>
<div class="tasktree-gantt" :class="{ 'global-view': isGlobalView, 'has-today': todayOffset !== null }" :style="{ '--task-column-width': `${taskColumnWidth}px`, '--tick-count': timelineTicks.length, '--tick-width': `${timelineScale.tickWidth}px`, '--timeline-width': `${timelineWidth}px`, '--today-left': `${todayOffset ?? 0}%` }">
<div class="tasktree-gantt" :class="{ 'global-view': isGlobalView, 'has-today': todayOffset !== null }" :style="{ '--task-column-width': `${taskColumnWidth}px`, '--tick-count': timelineTicks.length, '--tick-width': `${timelineScale.tickWidth}px`, '--timeline-width': `${timelineWidth}px`, '--today-left': `${todayOffset ?? 0}%`, '--timeline-scrollbar-width': `${timelineScrollbarWidth}px` }">
<div class="tasktree-corner">{{ isGlobalView ? 'TaskGroup' : '任务' }}</div>
<div
class="tasktree-column-resizer"
@@ -431,7 +450,7 @@ function syncSelectedTaskFromRoute() {
@pointerdown="startTaskColumnResize"
@keydown="resizeTaskColumnByKeyboard"
/>
<div ref="timelineHeaderElement" class="tasktree-timeline-header" @scroll="syncTimelineHeader">
<div ref="timelineHeaderElement" class="tasktree-timeline-header">
<div class="tasktree-days">
<span v-for="tick in timelineTicks" :key="tick.toISOString()" :class="tickClass(tick)">{{ tickLabel(tick) }}</span>
</div>
@@ -449,7 +468,6 @@ function syncSelectedTaskFromRoute() {
<div v-else class="tasktree-labels-canvas tasktree-detail-labels">
<section v-for="root in rootTasks" :key="root.id" class="tasktree-task-group">
<div class="tasktree-label" :data-task-id="root.id" :data-dated="Boolean(root.startAt || root.dueAt)">
<span class="tasktree-outline-ref">{{ root.outlineRef }}</span>
<button
v-if="childrenByParent.has(root.id)"
class="tasktree-disclosure"
@@ -465,7 +483,8 @@ function syncSelectedTaskFromRoute() {
<span v-else class="tasktree-disclosure-spacer" aria-hidden="true" />
<div class="tasktree-title" role="button" tabindex="0" @click="selectTaskFromTitle($event, root)" @keydown.enter="selectTask(root)">
<span class="tasktree-status" :data-status="root.status" />
<MessageMarkdown class="tasktree-title-markdown" :source="displayTaskTitle(root)" />
<span class="tasktree-outline-ref">{{ root.outlineRef }}</span>
<MessageMarkdown class="tasktree-title-markdown" :source="root.title" />
</div>
</div>
<div
@@ -477,7 +496,6 @@ function syncSelectedTaskFromRoute() {
@wheel="handleChildWheel($event, root.id, 'labels')"
>
<div v-for="task in visibleDescendants(root.id)" :key="task.id" class="tasktree-label" :class="task.kind" :data-task-id="task.id" :data-dated="Boolean(task.startAt || task.dueAt)">
<span class="tasktree-outline-ref">{{ task.outlineRef }}</span>
<button
v-if="childrenByParent.has(task.id)"
class="tasktree-disclosure"
@@ -493,7 +511,8 @@ function syncSelectedTaskFromRoute() {
<span v-else class="tasktree-disclosure-spacer" aria-hidden="true" />
<div class="tasktree-title" role="button" tabindex="0" @click="selectTaskFromTitle($event, task)" @keydown.enter="selectTask(task)">
<span class="tasktree-status" :data-status="task.status" />
<MessageMarkdown class="tasktree-title-markdown" :source="displayTaskTitle(task)" />
<span class="tasktree-outline-ref">{{ task.outlineRef }}</span>
<MessageMarkdown class="tasktree-title-markdown" :source="task.title" />
</div>
</div>
</div>
@@ -606,7 +625,7 @@ function syncSelectedTaskFromRoute() {
.tasktree-column-resizer:focus-visible::after,
.tasktree-column-resizer:active::after { background: #2376c9; }
.tasktree-corner { display: flex; align-items: center; padding: 0 14px; border-right: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color); background: transparent; font-size: 11px; font-weight: 700; }
.tasktree-timeline-header { min-width: 0; overflow-x: auto; overflow-y: hidden; border-bottom: 1px solid #dfe5e4; background: #fbfcfc; scrollbar-width: none; overscroll-behavior-inline: contain; }
.tasktree-timeline-header { min-width: 0; overflow: hidden; padding-right: var(--timeline-scrollbar-width); border-bottom: 1px solid #dfe5e4; background: #fbfcfc; scrollbar-width: none; }
.tasktree-timeline-header::-webkit-scrollbar { display: none; }
.tasktree-days { position: relative; width: max(100%, var(--timeline-width)); height: 100%; display: grid; grid-template-columns: repeat(var(--tick-count), minmax(var(--tick-width), 1fr)); }
.tasktree-days span { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0 4px; overflow: hidden; border-right: 1px solid #e6ebea; color: #68777a; font-family: var(--console-font-mono); font-size: 10px; white-space: nowrap; }
@@ -617,12 +636,12 @@ function syncSelectedTaskFromRoute() {
.tasktree-labels-canvas { min-height: 100%; align-content: start; }
.tasktree-overview-labels { display: grid; grid-auto-rows: 68px; }
.tasktree-task-group { min-width: 0; }
.tasktree-label { height: 46px; border-bottom: 1px solid #edf0ef; background: #fff; padding: 0 8px; display: grid; grid-template-columns: 9ch 24px minmax(0, 1fr); align-items: center; color: var(--text-primary); min-width: 0; }
.tasktree-label { height: 46px; border-bottom: 1px solid #edf0ef; background: #fff; padding: 0 8px; display: flex; align-items: center; color: var(--text-primary); min-width: 0; }
.tasktree-task-group > .tasktree-label { background: #f7f9f8; font-weight: 600; }
.tasktree-label:hover { background: #f2f7f5; }
.tasktree-outline-ref { min-width: 0; padding-right: 7px; overflow: hidden; color: #64767b; font-family: var(--console-font-mono); font-size: 10px; font-weight: 700; line-height: 18px; text-align: right; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tasktree-label.subtask,
.tasktree-label.subsubtask { color: var(--text-secondary); }
.tasktree-outline-ref { flex: 0 0 auto; color: #587078; font-family: var(--console-font-mono); font-size: 11px; font-weight: 700; }
.tasktree-label.subtask { padding-left: 30px; color: var(--text-secondary); }
.tasktree-label.subsubtask { padding-left: 54px; color: var(--text-secondary); }
.tasktree-group-label { height: 68px; padding: 9px 14px; display: grid; align-content: center; gap: 5px; cursor: pointer; }
.tasktree-group-label > span { color: var(--text-secondary); font-family: var(--console-font-mono); font-size: 10px; }
.tasktree-group-title { display: flex; min-width: 0; align-items: center; gap: 8px; color: var(--text-primary); font-size: 15px; font-weight: 700; }
@@ -631,13 +650,13 @@ function syncSelectedTaskFromRoute() {
.tasktree-disclosure-spacer { width: 24px; height: 28px; flex: 0 0 24px; }
.tasktree-disclosure { display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; }
.tasktree-disclosure:hover { color: var(--text-primary); background: var(--surface-secondary); }
.tasktree-title { display: flex; align-items: center; gap: 7px; min-width: 0; width: 100%; height: 100%; padding: 0 4px 0 3px; color: inherit; text-align: left; cursor: pointer; }
.tasktree-title { display: flex; flex: 1 1 auto; align-items: center; gap: 8px; min-width: 0; height: 100%; padding: 0 4px; color: inherit; text-align: left; cursor: pointer; }
.tasktree-title:focus-visible { outline: 2px solid #2376c9; outline-offset: -2px; }
.tasktree-title-markdown { min-width: 0; overflow: hidden; }
.tasktree-title-markdown :deep(p) { min-width: 0; margin: 0; overflow: hidden; font: inherit; text-overflow: ellipsis; white-space: nowrap; }
.tasktree-title-markdown :deep(a) { color: #1766ad; text-decoration: underline; text-underline-offset: 2px; }
.tasktree-title-markdown :deep(code) { padding: 1px 3px; border: 1px solid var(--border-subtle); background: var(--surface-secondary); color: inherit; font-size: 0.9em; }
.tasktree-status { width: 6px; height: 6px; border-radius: 50%; background: #83909c; flex: 0 0 auto; }
.tasktree-status { width: 7px; height: 7px; border-radius: 50%; background: #83909c; flex: 0 0 auto; }
.tasktree-status[data-status="completed"] { background: #1f9d67; }
.tasktree-status[data-status="in_progress"] { background: #2376c9; }
.tasktree-status[data-status="blocked"] { background: #c73e48; }