From a0547729b2a2089abc51ef7529ec8660e5cde78d Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 28 May 2026 13:19:41 +0800 Subject: [PATCH] feat(trace-drawer): implement resizable trace drawer and enhance UI interactions This commit introduces a resizable trace drawer in the `doc-content` component, allowing users to adjust the width for better visibility. Key changes include: 1. Added functionality to save and load the drawer width from local storage. 2. Implemented mouse events for resizing the drawer, enhancing user interaction. 3. Updated the UI to reflect the new drawer width dynamically. 4. Enhanced the trace entry button for improved accessibility and clarity. These changes aim to improve user experience by providing a more flexible and user-friendly interface for trace inspection. --- frontend/src/components/doc-content.vue | 446 ++++++------------ .../knowledge-processing-timeline.vue | 442 +++++++++-------- frontend/src/i18n/locales/en-US.ts | 10 + frontend/src/i18n/locales/ko-KR.ts | 10 + frontend/src/i18n/locales/zh-CN.ts | 10 + 5 files changed, 433 insertions(+), 485 deletions(-) diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index d7ff4d8f..6136d63a 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -93,6 +93,103 @@ function closeTimeline() { timelineDrawerVisible.value = false; } +const TRACE_DRAWER_WIDTH_KEY = 'weknora-trace-drawer-width'; +const TRACE_DRAWER_DEFAULT_WIDTH = 820; +const TRACE_DRAWER_MIN_WIDTH = 560; + +const timelineDrawerWidth = ref(TRACE_DRAWER_DEFAULT_WIDTH); +const timelineDrawerResizing = ref(false); + +let traceResizeStartX = 0; +let traceResizeStartWidth = 0; + +function traceDrawerMaxWidth() { + return Math.min(1400, Math.max(TRACE_DRAWER_MIN_WIDTH, Math.floor(window.innerWidth * 0.92))); +} + +function clampTraceDrawerWidth(width: number) { + return Math.max(TRACE_DRAWER_MIN_WIDTH, Math.min(traceDrawerMaxWidth(), width)); +} + +function loadTraceDrawerWidth() { + try { + const raw = localStorage.getItem(TRACE_DRAWER_WIDTH_KEY); + const parsed = raw ? parseInt(raw, 10) : NaN; + if (!Number.isNaN(parsed)) { + timelineDrawerWidth.value = clampTraceDrawerWidth(parsed); + } + } catch { + /* ignore quota / private mode */ + } +} + +function onTraceDrawerResizeStart(e: MouseEvent) { + timelineDrawerResizing.value = true; + traceResizeStartX = e.clientX; + traceResizeStartWidth = timelineDrawerWidth.value; + document.addEventListener('mousemove', onTraceDrawerResizeMove); + document.addEventListener('mouseup', onTraceDrawerResizeEnd); + document.body.style.cursor = 'col-resize'; + document.body.style.userSelect = 'none'; +} + +function onTraceDrawerResizeMove(e: MouseEvent) { + const delta = traceResizeStartX - e.clientX; + timelineDrawerWidth.value = clampTraceDrawerWidth(traceResizeStartWidth + delta); +} + +function onTraceDrawerResizeEnd() { + document.removeEventListener('mousemove', onTraceDrawerResizeMove); + document.removeEventListener('mouseup', onTraceDrawerResizeEnd); + document.body.style.cursor = ''; + document.body.style.userSelect = ''; + timelineDrawerResizing.value = false; + try { + localStorage.setItem(TRACE_DRAWER_WIDTH_KEY, String(timelineDrawerWidth.value)); + } catch { + /* ignore */ + } +} + +function onTraceDrawerWindowResize() { + timelineDrawerWidth.value = clampTraceDrawerWidth(timelineDrawerWidth.value); +} + +function cleanupTraceDrawerResize() { + document.removeEventListener('mousemove', onTraceDrawerResizeMove); + document.removeEventListener('mouseup', onTraceDrawerResizeEnd); + document.body.style.cursor = ''; + document.body.style.userSelect = ''; + timelineDrawerResizing.value = false; +} + +const traceEntryTheme = computed(() => { + const s = timelineSummary.value.status || ''; + switch (s) { + case 'done': + case 'completed': + return 'success'; + case 'failed': + return 'danger'; + case 'running': + case 'processing': + case 'pending': + return 'warning'; + default: + return 'default'; + } +}); + +const traceEntryTitle = computed(() => { + let tip = t('knowledgeStages.viewTrace'); + if (timelineSummary.value.totalMs > 0) { + tip += ` · ${formatTimelineDuration(timelineSummary.value.totalMs)}`; + } else if (timelineSummary.value.stageTotal > 0) { + tip += ` · ${timelineSummary.value.stageIndex}/${timelineSummary.value.stageTotal}`; + } + return tip; +}); + // Exposed so the parent's three-dot menu can jump straight into the // trace drawer for a card without forcing the user to click the // detail drawer header link manually. @@ -193,6 +290,8 @@ const mergeChunks = (chunks: any[]): string => { }; onMounted(() => { + loadTraceDrawerWidth(); + window.addEventListener('resize', onTraceDrawerWindowResize, { passive: true }); nextTick(() => { const drawers = document.getElementsByClassName('t-drawer__body'); if (drawers && drawers.length > 0) { @@ -223,6 +322,8 @@ watch(() => props.details?.chunkLoading, (val) => { } }); onUnmounted(() => { + window.removeEventListener('resize', onTraceDrawerWindowResize); + cleanupTraceDrawerResize(); if (doc) { doc.removeEventListener('scroll', handleDetailsScroll); } @@ -817,27 +918,16 @@ const handleDetailsScroll = () => { @@ -851,27 +941,18 @@ const handleDetailsScroll = () => { - -
-
-
- trace - {{ $t('knowledgeStages.title') }} - · - {{ details.title - }} -
- -
-
- + +
+ @@ -1116,15 +1197,22 @@ const handleDetailsScroll = () => { display: flex; align-items: center; gap: 8px; + min-width: 0; .header-title { flex: 1; + min-width: 0; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + + .header-type-tag, + .trace-entry-btn { + flex-shrink: 0; + } } // 信息面板通用样式 @@ -1148,183 +1236,6 @@ const handleDetailsScroll = () => { border-radius: 6px; } -/* ============== Trace entry (header inline link) ============== - Sits in the drawer titlebar next to the file-type tag. Status-aware - tinted pill: success-green when the trace finished cleanly, - amber-stripe when still in flight, error-red on failure. The - duration is shown in mono digits to the right; the trace icon - anchors the meaning so the button reads as "open the trace" even - without the word "查看". */ -.kp-trace-link { - display: inline-flex; - align-items: center; - gap: 6px; - height: 26px; - padding: 0 10px 0 8px; - border: 1px solid var(--td-component-stroke); - border-radius: var(--td-radius-default); - background: var(--td-bg-color-container); - color: var(--td-text-color-secondary); - font-family: var(--app-font-family); - font-size: 12px; - line-height: 1; - cursor: pointer; - transition: border-color 150ms ease, color 150ms ease, - background 150ms ease, box-shadow 150ms ease; -} - -.kp-trace-link:hover { - border-color: var(--td-text-color-secondary); - color: var(--td-text-color-primary); - background: var(--td-bg-color-container-hover); -} - -.kp-trace-link-icon { - display: inline-flex; - align-items: center; - justify-content: center; - color: var(--td-text-color-placeholder); - margin-right: -2px; - transition: color 150ms ease; -} - -.kp-trace-link:hover .kp-trace-link-icon { - color: var(--td-text-color-secondary); -} - -.kp-trace-link-dot { - width: 6px; - height: 6px; - border-radius: 50%; - background: var(--td-text-color-placeholder); - flex-shrink: 0; -} - -.kp-trace-link-text { - font-weight: 500; - letter-spacing: 0.02em; -} - -.kp-trace-link-meta { - font-family: var(--app-font-family-mono); - font-size: 11px; - color: var(--td-text-color-placeholder); - font-weight: 500; - padding-left: 2px; - border-left: 1px solid var(--td-component-stroke); - margin-left: 2px; - padding-left: 8px; - letter-spacing: 0; -} - -/* Status tints — done / failed / running each get a soft palette - pull. Lets a glance at the pill tell you the trace's outcome - without needing to look at the colored dot. */ -.kp-trace-link-done, -.kp-trace-link-completed { - border-color: var(--td-success-color-3); - background: var(--td-success-color-1); - color: var(--td-success-color-7); -} - -.kp-trace-link-done .kp-trace-link-dot, -.kp-trace-link-completed .kp-trace-link-dot { - background: var(--td-success-color); -} - -.kp-trace-link-done .kp-trace-link-icon, -.kp-trace-link-completed .kp-trace-link-icon { - color: var(--td-success-color-6); -} - -.kp-trace-link-done .kp-trace-link-meta, -.kp-trace-link-completed .kp-trace-link-meta { - color: var(--td-success-color-7); - border-color: var(--td-success-color-3); -} - -.kp-trace-link-done:hover, -.kp-trace-link-completed:hover { - border-color: var(--td-success-color-5); - background: var(--td-success-color-2); - color: var(--td-success-color-8); -} - -.kp-trace-link-failed { - border-color: var(--td-error-color-3); - background: var(--td-error-color-1); - color: var(--td-error-color-7); -} - -.kp-trace-link-failed .kp-trace-link-dot { - background: var(--td-error-color); -} - -.kp-trace-link-failed .kp-trace-link-icon { - color: var(--td-error-color-6); -} - -.kp-trace-link-failed .kp-trace-link-meta { - color: var(--td-error-color-7); - border-color: var(--td-error-color-3); -} - -.kp-trace-link-failed:hover { - border-color: var(--td-error-color-5); - background: var(--td-error-color-2); - color: var(--td-error-color-8); -} - -.kp-trace-link-running, -.kp-trace-link-processing, -.kp-trace-link-pending { - border-color: var(--td-warning-color-3); - background: var(--td-warning-color-1); - color: var(--td-warning-color-7); -} - -.kp-trace-link-running .kp-trace-link-dot, -.kp-trace-link-processing .kp-trace-link-dot, -.kp-trace-link-pending .kp-trace-link-dot { - background: var(--td-warning-color); - animation: kpTriggerPulse 1.4s ease-in-out infinite; -} - -.kp-trace-link-running .kp-trace-link-icon, -.kp-trace-link-processing .kp-trace-link-icon, -.kp-trace-link-pending .kp-trace-link-icon { - color: var(--td-warning-color-6); -} - -.kp-trace-link-running .kp-trace-link-meta, -.kp-trace-link-processing .kp-trace-link-meta, -.kp-trace-link-pending .kp-trace-link-meta { - color: var(--td-warning-color-7); - border-color: var(--td-warning-color-3); -} - -.kp-trace-link-running:hover, -.kp-trace-link-processing:hover, -.kp-trace-link-pending:hover { - border-color: var(--td-warning-color-5); - background: var(--td-warning-color-2); - color: var(--td-warning-color-8); -} - -@keyframes kpTriggerPulse { - - 0%, - 100% { - transform: scale(1); - opacity: 1; - } - - 50% { - transform: scale(0.6); - opacity: 0.5; - } -} - /* Hidden mount keeps fetcher live without showing UI */ .kp-trigger-shadow { display: none; @@ -1332,6 +1243,7 @@ const handleDetailsScroll = () => { /* ============== Secondary drawer shell ============== */ .kp-drawer-shell { + position: relative; display: flex; flex-direction: column; height: 100%; @@ -1343,90 +1255,40 @@ const handleDetailsScroll = () => { min-width: 0; } -.kp-drawer-titlebar { - flex: 0 0 auto; +.kp-drawer-resize-handle { + position: absolute; + top: 0; + left: -6px; + bottom: 0; + width: 12px; + cursor: col-resize; + z-index: 20; display: flex; align-items: center; - justify-content: space-between; - padding: 14px 20px 12px; - border-bottom: 1px solid var(--td-component-stroke); - background: var(--td-bg-color-container); -} - -.kp-drawer-titlebar-left { - display: flex; - align-items: center; - gap: 10px; - min-width: 0; -} - -.kp-drawer-titlebar-kind { - font-family: var(--app-font-family-mono); - font-size: 10px; - text-transform: uppercase; - letter-spacing: 0.5px; - color: var(--td-text-color-placeholder); - background: var(--td-bg-color-secondarycontainer); - border-radius: var(--td-radius-default); - padding: 2px 6px; - line-height: 1.2; -} - -.kp-drawer-titlebar-title { - font-size: 15px; - font-weight: 600; - color: var(--td-text-color-primary); - letter-spacing: -0.005em; -} - -.kp-drawer-titlebar-sep { - font-size: 13px; - color: var(--td-text-color-placeholder); - flex-shrink: 0; -} - -.kp-drawer-titlebar-doc { - font-size: 13px; - color: var(--td-text-color-secondary); - min-width: 0; - flex: 0 1 auto; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.kp-drawer-titlebar-close { - display: inline-flex; - align-items: center; justify-content: center; - width: 28px; - height: 28px; - border: none; - background: transparent; - cursor: pointer; - color: var(--td-text-color-placeholder); - border-radius: var(--td-radius-default); - transition: background 150ms ease, color 150ms ease; + + &:hover .kp-drawer-resize-line, + .kp-drawer-shell--resizing & .kp-drawer-resize-line { + opacity: 1; + background: var(--td-brand-color); + } } -.kp-drawer-titlebar-close:hover { - background: var(--td-bg-color-secondarycontainer); - color: var(--td-text-color-primary); +.kp-drawer-resize-line { + width: 2px; + height: 48px; + border-radius: 1px; + background: var(--td-component-border); + opacity: 0.55; + transition: opacity 0.15s ease, background 0.15s ease; } -.kp-drawer-body { - flex: 1 1 auto; - min-height: 0; - min-width: 0; - overflow: hidden; - /* Plain block layout — flex was unnecessary and risked the timeline - becoming a flex item with auto-sized basis, leaking past the drawer - bounds when its internal min-widths exceeded the parent. */ - display: block; - position: relative; +.kp-drawer-shell--resizing .kp-drawer-resize-line { + opacity: 1; + background: var(--td-brand-color); } -.kp-drawer-body> :deep(.kp-timeline) { +.kp-drawer-shell> :deep(.kp-timeline) { width: 100%; height: 100%; } @@ -1865,4 +1727,8 @@ const handleDetailsScroll = () => { .t-drawer.kp-secondary-drawer .t-drawer__content { background: var(--td-bg-color-container); } + +.t-drawer.kp-secondary-drawer--resizing .t-drawer__content { + transition: none !important; +} diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue index d482f683..c9ec7a75 100644 --- a/frontend/src/components/knowledge-processing-timeline.vue +++ b/frontend/src/components/knowledge-processing-timeline.vue @@ -1,5 +1,5 @@