diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index 8a72f701..ca6a08b2 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -17,6 +17,7 @@ import { MessagePlugin } from "tdesign-vue-next"; import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages, isValidURL } from '@/utils/security'; import { normalizeSpuriousTablePrefixes } from '@/utils/markdownTableNormalize'; import { openMermaidFullscreen } from '@/utils/mermaidViewer'; +import { diffWikiLines, type WikiDiffLine } from '@/utils/wikiLineDiff'; import { useI18n } from 'vue-i18n'; import { useAuthStore } from '@/stores/auth'; import DocumentPreview from '@/components/document-preview.vue'; @@ -1077,22 +1078,15 @@ const retryChunkIndex = async (item: any) => { } }; -const chunkHistoryOpen = ref>(new Set()); +type ChunkDiffLine = WikiDiffLine | { type: 'skip'; text: string }; + +const chunkHistoryPopup = ref(''); const chunkHistoryLoading = ref(''); const chunkHistories = ref>({}); +const selectedChunkRevision = ref>({}); const revertingRevision = ref(''); -const isChunkHistoryOpen = (chunkID: string) => chunkHistoryOpen.value.has(chunkID); - const showChunkHistory = async (item: any) => { - if (chunkHistoryOpen.value.has(item.id)) { - chunkHistoryOpen.value.delete(item.id); - chunkHistoryOpen.value = new Set(chunkHistoryOpen.value); - return; - } - - chunkHistoryOpen.value.add(item.id); - chunkHistoryOpen.value = new Set(chunkHistoryOpen.value); if (chunkHistories.value[item.id]) return; chunkHistoryLoading.value = item.id; @@ -1106,6 +1100,54 @@ const showChunkHistory = async (item: any) => { } }; +const setChunkHistoryPopupVisible = (item: any, visible: boolean) => { + chunkHistoryPopup.value = visible ? item.id : ''; + if (visible) showChunkHistory(item); +}; + +const selectChunkRevision = (item: any, revision: number) => { + selectedChunkRevision.value[item.id] = selectedChunkRevision.value[item.id] === revision ? null : revision; +}; + +const getSelectedChunkRevision = (item: any) => { + const revision = selectedChunkRevision.value[item.id]; + return (chunkHistories.value[item.id] || []).find((entry: any) => entry.revision === revision) || null; +}; + +const compactChunkDiff = (item: any): ChunkDiffLine[] => { + const revision = getSelectedChunkRevision(item); + if (!revision) return []; + const lines = diffWikiLines(revision.content || '', item.content || ''); + const changed = new Set(); + lines.forEach((line, index) => { + if (line.type !== 'same') { + for (let i = Math.max(0, index - 2); i <= Math.min(lines.length - 1, index + 2); i++) changed.add(i); + } + }); + if (!changed.size) return []; + + const compact: ChunkDiffLine[] = []; + let lastIndex = -2; + [...changed].sort((a, b) => a - b).forEach((index) => { + if (index > lastIndex + 1) compact.push({ type: 'skip', text: '…' }); + compact.push(lines[index]); + lastIndex = index; + }); + return compact; +}; + +const diffLinePrefix = (type: ChunkDiffLine['type']) => { + if (type === 'add') return '+ '; + if (type === 'del') return '- '; + return type === 'same' ? ' ' : ''; +}; + +const revisionStatusChanged = (item: any, revisionIndex: number) => { + const revisions = chunkHistories.value[item.id] || []; + const newerEnabled = revisionIndex === 0 ? item.is_enabled : revisions[revisionIndex - 1]?.is_enabled; + return revisions[revisionIndex]?.is_enabled !== newerEnabled; +}; + const revertChunk = async (item: any, revision: number) => { revertingRevision.value = `${item.id}:${revision}`; try { @@ -1114,6 +1156,7 @@ const revertChunk = async (item: any, revision: number) => { delete chunkHistories.value[item.id]; const historyResult: any = await listChunkRevisions(props.details.id, item.id); chunkHistories.value[item.id] = historyResult?.data || []; + selectedChunkRevision.value[item.id] = null; MessagePlugin.success(t('knowledgeBase.chunkReverted')); } catch (error: any) { MessagePlugin.error(error?.message || t('common.error')); @@ -1133,7 +1176,7 @@ const savingQuestionKey = ref(''); watch(() => props.details?.id, () => { metadataEditing.value = false; editingChunkId.value = ''; - chunkHistoryOpen.value = new Set(); + chunkHistoryPopup.value = ''; questionComposerChunk.value = ''; editingQuestionKey.value = ''; }); @@ -1679,12 +1722,79 @@ const handleDetailsScroll = () => { - - + + - + + {
-
-
-
- - {{ $t('knowledgeBase.chunkHistory') }} -
- - - -
-
- - {{ $t('common.loading') }} -
-
- {{ $t('knowledgeBase.noChunkHistory') }} -
-
-
-
-
-
- v{{ revision.revision }} - {{ new Date(revision.edited_at).toLocaleString() }} - - {{ revision.is_enabled ? $t('knowledgeBase.enabledStatus') : $t('knowledgeBase.disabledStatus') }} - -
-
{{ revision.content }}
-
- - - - {{ $t('knowledgeBase.revertRevision') }} - - -
-
-
-
-
- - - {{ $t('knowledgeBase.viewParentContext') }} -
+
@@ -2057,11 +2126,9 @@ const handleDetailsScroll = () => { .doc-metadata-row { display: block; - margin-top: 2px; - padding: 12px; - border: 1px solid var(--td-component-border); - border-radius: 6px; - background: var(--td-bg-color-container); + margin-top: 4px; + padding-top: 12px; + border-top: 1px solid var(--td-component-stroke); } .metadata-card-head, @@ -2099,16 +2166,17 @@ const handleDetailsScroll = () => { } .metadata-grid { - display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); - gap: 8px; + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 7px 18px; } .metadata-item { + display: inline-flex; + align-items: baseline; + gap: 5px; min-width: 0; - padding: 8px 10px; - border-radius: 4px; - background: var(--td-bg-color-container-hover); } .metadata-item-key, @@ -2120,9 +2188,12 @@ const handleDetailsScroll = () => { } .metadata-item-key { - margin-bottom: 2px; color: var(--td-text-color-placeholder); - font-size: 11px; + font-size: 12px; + + &::after { + content: ':'; + } } .metadata-item-value { @@ -2134,11 +2205,12 @@ const handleDetailsScroll = () => { .metadata-add-row { display: flex; align-items: center; - justify-content: center; - gap: 6px; - width: 100%; - min-height: 34px; - border: 1px dashed var(--td-component-border); + justify-content: flex-start; + gap: 5px; + width: fit-content; + min-height: 28px; + padding: 0 4px; + border: none; border-radius: 4px; color: var(--td-text-color-secondary); background: transparent; @@ -2148,7 +2220,6 @@ const handleDetailsScroll = () => { &:hover { color: var(--td-brand-color); - border-color: var(--td-brand-color); background: var(--td-brand-color-light); } } @@ -2195,10 +2266,6 @@ const handleDetailsScroll = () => { } @media (max-width: 720px) { - .metadata-grid { - grid-template-columns: 1fr; - } - .metadata-editor-row { flex-wrap: wrap; } @@ -2449,11 +2516,6 @@ const handleDetailsScroll = () => { padding: 12px 14px; background: var(--td-bg-color-container); border: 1px solid var(--td-component-border); - transition: border-color 0.15s ease, box-shadow 0.15s ease; - - &:hover { - border-color: var(--td-text-color-disabled); - } &.chunk-item--disabled { background: var(--td-bg-color-secondarycontainer); @@ -2530,120 +2592,210 @@ const handleDetailsScroll = () => { font-weight: 500; } -.chunk-history-panel { - margin-top: 12px; - padding: 10px 12px; - border: 1px solid var(--td-component-border); - border-radius: 5px; - background: var(--td-bg-color-secondarycontainer); +.chunk-history-popup { + width: min(560px, calc(100vw - 32px)); + max-height: min(620px, calc(100vh - 96px)); + overflow: hidden; + border-radius: 6px; + background: var(--td-bg-color-container); } -.chunk-subsection-head, -.chunk-subsection-title, -.chunk-subsection-loading, -.chunk-history-item, -.chunk-history-meta { +.chunk-history-popup-head { + padding: 12px 14px 10px; + border-bottom: 1px solid var(--td-component-stroke); +} + +.chunk-history-popup-title { display: flex; align-items: center; -} - -.chunk-subsection-head { - justify-content: space-between; - min-height: 28px; -} - -.chunk-subsection-title { gap: 6px; color: var(--td-text-color-primary); + font-size: 13px; + font-weight: 600; +} + +.chunk-history-current { + margin-top: 4px; + color: var(--td-text-color-placeholder); + font-size: 11px; +} + +.chunk-history-popup-state { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + min-height: 100px; + color: var(--td-text-color-placeholder); + font-size: 12px; +} + +.chunk-history-popup-list { + max-height: min(520px, calc(100vh - 180px)); + overflow-y: auto; +} + +.chunk-history-popup-item { + border-bottom: 1px solid var(--td-component-stroke); + + &:last-child { + border-bottom: none; + } + + &.is-selected { + background: var(--td-bg-color-secondarycontainer); + } +} + +.chunk-history-version-row { + display: flex; + align-items: center; + gap: 8px; + width: 100%; + min-height: 40px; + padding: 8px 14px; + border: none; + color: var(--td-text-color-secondary); + background: transparent; + cursor: pointer; + font: inherit; + text-align: left; + + &:hover { + background: var(--td-bg-color-container-hover); + } +} + +.chunk-history-version { + min-width: 32px; + color: var(--td-text-color-primary); font-size: 12px; font-weight: 600; } -.chunk-subsection-loading, -.chunk-subsection-empty { - justify-content: center; - gap: 8px; - padding: 18px 0; +.chunk-history-time { color: var(--td-text-color-placeholder); + font-size: 11px; +} + +.chunk-history-status-change { + display: inline-flex; + align-items: center; + gap: 4px; + margin-left: auto; + color: var(--td-text-color-secondary); + font-size: 11px; +} + +.chunk-history-row-chevron { + margin-left: auto; + color: var(--td-text-color-placeholder); +} + +.chunk-history-status-change + .chunk-history-row-chevron { + margin-left: 0; +} + +.chunk-history-diff { + padding: 0 14px 12px; +} + +.chunk-history-diff-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + min-height: 32px; + color: var(--td-text-color-placeholder); + font-size: 11px; +} + +.chunk-history-no-diff { + padding: 12px; + border-radius: 4px; + color: var(--td-text-color-placeholder); + background: var(--td-bg-color-container); text-align: center; font-size: 12px; } -.chunk-history-list { - margin-top: 6px; -} - -.chunk-history-item { - position: relative; - align-items: flex-start; - gap: 10px; - padding: 10px 0; - border-top: 1px solid var(--td-component-stroke); -} - -.chunk-history-marker { - width: 6px; - height: 6px; - margin-top: 7px; - border: 1px solid var(--td-text-color-placeholder); - border-radius: 50%; +.chunk-history-diff-body { + max-height: 240px; + margin: 0; + padding: 8px 0; + overflow: auto; + border: 1px solid var(--td-component-border); + border-radius: 4px; background: var(--td-bg-color-container); - flex-shrink: 0; -} - -.chunk-history-main { - flex: 1; - min-width: 0; -} - -.chunk-history-meta { - gap: 8px; - color: var(--td-text-color-placeholder); + font-family: var(--app-font-family-mono); font-size: 11px; - - strong { - color: var(--td-text-color-secondary); - font-size: 12px; - } -} - -.chunk-history-preview { - display: -webkit-box; - margin-top: 5px; - overflow: hidden; - color: var(--td-text-color-secondary); - font-size: 12px; - line-height: 1.5; + line-height: 1.55; white-space: pre-wrap; word-break: break-word; - -webkit-box-orient: vertical; - -webkit-line-clamp: 3; +} + +.chunk-history-diff-line { + display: block; + min-height: 17px; + padding: 0 10px; + + &--add { + color: var(--td-success-color-active); + background: var(--td-success-color-light); + } + + &--del { + color: var(--td-error-color-active); + background: var(--td-error-color-light); + } + + &--same { + color: var(--td-text-color-secondary); + } + + &--skip { + color: var(--td-text-color-placeholder); + } } // 父 Chunk 上下文样式 .parent-context-section { - margin-top: 10px; - padding-top: 8px; - border-top: 1px dashed var(--td-component-stroke); + margin-top: 12px; + border-top: 1px solid var(--td-component-stroke); } .parent-context-toggle { display: flex; align-items: center; - gap: 6px; + justify-content: space-between; + gap: 8px; + width: 100%; + min-height: 36px; + padding: 6px 2px; + border: none; cursor: pointer; - color: var(--td-brand-color); + color: var(--td-text-color-secondary); + background: transparent; + font: inherit; font-size: 12px; font-weight: 500; - padding: 4px 0; + + &:hover { + color: var(--td-text-color-primary); + } +} + +.parent-context-toggle-label { + display: inline-flex; + align-items: center; + gap: 6px; } .parent-context-content { - margin-top: 8px; + margin-bottom: 4px; padding: 10px 12px; - background: var(--td-brand-color-light); + background: var(--td-bg-color-secondarycontainer); border-radius: 4px; - border-left: 3px solid var(--td-brand-color); .md-content { color: var(--td-text-color-secondary); @@ -2654,10 +2806,8 @@ const handleDetailsScroll = () => { // 辅助召回问题:沿用中性容器样式,避免使用成功态绿色作为列表背景。 .questions-section { margin-top: 12px; - border: 1px solid var(--td-component-border); - border-radius: 5px; - overflow: hidden; - background: var(--td-bg-color-container); + padding-top: 4px; + border-top: 1px solid var(--td-component-stroke); } .questions-head, @@ -2674,7 +2824,7 @@ const handleDetailsScroll = () => { .questions-head { justify-content: space-between; min-height: 38px; - padding: 4px 8px 4px 10px; + padding: 4px 0; } .questions-toggle { @@ -2696,10 +2846,7 @@ const handleDetailsScroll = () => { .questions-count { min-width: 20px; - padding: 1px 6px; - border-radius: 999px; color: var(--td-text-color-placeholder); - background: var(--td-bg-color-container-hover); text-align: center; font-size: 11px; font-weight: 400; @@ -2714,8 +2861,7 @@ const handleDetailsScroll = () => { } .questions-body { - padding: 0 10px 10px; - border-top: 1px solid var(--td-component-stroke); + padding-bottom: 4px; } .questions-list { @@ -2761,12 +2907,10 @@ const handleDetailsScroll = () => { display: flex; align-items: center; justify-content: center; - width: 24px; + width: 18px; height: 24px; margin-top: -1px; - border-radius: 4px; color: var(--td-text-color-secondary); - background: var(--td-bg-color-container-hover); flex-shrink: 0; } diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index d6ab887f..7e7ff189 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -551,7 +551,10 @@ export default { indexRetrySuccess: 'Index synchronized', history: 'History', chunkHistory: 'Chunk edit history', + currentVersion: 'Current version', noChunkHistory: 'No edit history', + compareRevisionWithCurrent: 'Content changes from v{revision} to current v{current}', + noContentChanges: 'No content changes; this revision only changed status', revertRevision: 'Revert revision', revertRevisionConfirm: 'Revert to v{revision}? A new revision will be created.', enterRevision: 'Enter the revision to restore', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 2d4b8d89..53bdebae 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -561,7 +561,10 @@ export default { indexRetrySuccess: "인덱스가 동기화되었습니다", history: "기록", chunkHistory: "청크 편집 기록", + currentVersion: "현재 버전", noChunkHistory: "편집 기록 없음", + compareRevisionWithCurrent: "v{revision}과 현재 v{current}의 내용 차이", + noContentChanges: "내용 변경이 없으며 상태만 변경된 버전입니다", revertRevision: "버전 되돌리기", revertRevisionConfirm: "v{revision}(으)로 되돌리시겠습니까? 새 버전이 생성됩니다.", enterRevision: "복원할 버전을 입력하세요", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index f1fdb6f8..0b37d3c5 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -486,7 +486,10 @@ export default { indexRetrySuccess: 'Индекс синхронизирован', history: 'История', chunkHistory: 'История изменений чанка', + currentVersion: 'Текущая версия', noChunkHistory: 'История изменений пуста', + compareRevisionWithCurrent: 'Изменения содержимого от v{revision} до текущей v{current}', + noContentChanges: 'Содержимое не изменилось; версия содержит только смену статуса', revertRevision: 'Откатить версию', revertRevisionConfirm: 'Откатить к v{revision}? Будет создана новая версия.', enterRevision: 'Введите номер версии', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 47221907..15d9ef8a 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -550,7 +550,10 @@ export default { indexRetrySuccess: "索引已同步", history: "历史", chunkHistory: "分块编辑历史", + currentVersion: "当前版本", noChunkHistory: "暂无编辑历史", + compareRevisionWithCurrent: "v{revision} 与当前 v{current} 的内容差异", + noContentChanges: "内容没有变化,该版本仅包含状态变更", revertRevision: "回滚版本", revertRevisionConfirm: "确定回滚到 v{revision} 吗?回滚后会生成一个新版本。", enterRevision: "输入要回滚的版本号",