feat: Implement wiki status tracking and indexing indicators in KnowledgeBase and WikiBrowser components
- Added functionality to track and display the wiki indexing status, including pending tasks and active state. - Introduced a polling mechanism to update the wiki status at regular intervals, enhancing user awareness of background processes. - Updated the breadcrumb navigation to show indexing indicators, improving the user interface and experience during wiki operations. - Enhanced the WikiBrowser component to emit status changes to the parent component for better state management.
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
} from "@/api/knowledge-base/index";
|
} from "@/api/knowledge-base/index";
|
||||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||||
import WikiBrowser from './wiki/WikiBrowser.vue';
|
import WikiBrowser from './wiki/WikiBrowser.vue';
|
||||||
|
import { getWikiStats } from '@/api/wiki';
|
||||||
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
||||||
@@ -50,6 +51,59 @@ const validTabs = ['documents', 'wiki', 'graph'] as const
|
|||||||
type KbTab = typeof validTabs[number]
|
type KbTab = typeof validTabs[number]
|
||||||
const initTab = validTabs.includes(route.query.tab as any) ? (route.query.tab as KbTab) : 'documents'
|
const initTab = validTabs.includes(route.query.tab as any) ? (route.query.tab as KbTab) : 'documents'
|
||||||
const activeKbTab = ref<KbTab>(initTab);
|
const activeKbTab = ref<KbTab>(initTab);
|
||||||
|
|
||||||
|
// Wiki 状态用于面包屑上的索引中指示。父组件自行拉取,避免依赖 WikiBrowser 挂载状态
|
||||||
|
// (用户切到"文档" tab 时 WikiBrowser 会卸载,这里仍需持续反映后台索引进度)。
|
||||||
|
const wikiStatus = ref<{ pendingTasks: number; isActive: boolean; pendingIssues: number }>({
|
||||||
|
pendingTasks: 0,
|
||||||
|
isActive: false,
|
||||||
|
pendingIssues: 0,
|
||||||
|
})
|
||||||
|
const wikiIsIndexing = computed(() => wikiStatus.value.isActive || wikiStatus.value.pendingTasks > 0)
|
||||||
|
const wikiIndexingTip = computed(() => {
|
||||||
|
if (!wikiIsIndexing.value) return ''
|
||||||
|
return t('knowledgeEditor.wikiBrowser.queueStatus', { count: wikiStatus.value.pendingTasks || 0 })
|
||||||
|
})
|
||||||
|
const onWikiStatusChange = (payload: { pendingTasks: number; isActive: boolean; pendingIssues: number }) => {
|
||||||
|
wikiStatus.value = payload
|
||||||
|
}
|
||||||
|
|
||||||
|
let wikiStatusTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
const stopWikiStatusPolling = () => {
|
||||||
|
if (wikiStatusTimer) {
|
||||||
|
clearInterval(wikiStatusTimer)
|
||||||
|
wikiStatusTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const fetchWikiStatusOnce = async () => {
|
||||||
|
if (!kbId.value || !isWiki.value) return
|
||||||
|
try {
|
||||||
|
const res: any = await getWikiStats(kbId.value)
|
||||||
|
const data = res?.data || res
|
||||||
|
if (!data) return
|
||||||
|
wikiStatus.value = {
|
||||||
|
pendingTasks: data.pending_tasks || 0,
|
||||||
|
isActive: !!data.is_active,
|
||||||
|
pendingIssues: data.pending_issues || 0,
|
||||||
|
}
|
||||||
|
// 活跃时轮询,空闲时停掉定时器,避免无谓请求
|
||||||
|
if (wikiIsIndexing.value) {
|
||||||
|
if (!wikiStatusTimer) {
|
||||||
|
wikiStatusTimer = setInterval(fetchWikiStatusOnce, 5000)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stopWikiStatusPolling()
|
||||||
|
}
|
||||||
|
} catch (_) { /* ignore */ }
|
||||||
|
}
|
||||||
|
watch([kbId, isWiki], ([newKbId, newIsWiki]) => {
|
||||||
|
stopWikiStatusPolling()
|
||||||
|
wikiStatus.value = { pendingTasks: 0, isActive: false, pendingIssues: 0 }
|
||||||
|
if (newKbId && newIsWiki) {
|
||||||
|
fetchWikiStatusOnce()
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
onUnmounted(stopWikiStatusPolling)
|
||||||
const missingStorageEngine = computed(() => {
|
const missingStorageEngine = computed(() => {
|
||||||
if (!kbInfo.value || isFAQ.value) return false
|
if (!kbInfo.value || isFAQ.value) return false
|
||||||
const spc = kbInfo.value.storage_provider_config
|
const spc = kbInfo.value.storage_provider_config
|
||||||
@@ -1614,14 +1668,24 @@ async function createNewSession(value: string): Promise<void> {
|
|||||||
>{{ $t('knowledgeEditor.wikiBrowser.tabDocuments') }}</span>
|
>{{ $t('knowledgeEditor.wikiBrowser.tabDocuments') }}</span>
|
||||||
<span class="breadcrumb-tab-sep">/</span>
|
<span class="breadcrumb-tab-sep">/</span>
|
||||||
<span
|
<span
|
||||||
:class="['breadcrumb-tab', { active: activeKbTab === 'wiki' }]"
|
:class="['breadcrumb-tab', { active: activeKbTab === 'wiki', indexing: wikiIsIndexing }]"
|
||||||
@click="activeKbTab = 'wiki'"
|
@click="activeKbTab = 'wiki'"
|
||||||
>Wiki</span>
|
>
|
||||||
|
Wiki
|
||||||
|
<t-tooltip v-if="wikiIsIndexing" :content="wikiIndexingTip" placement="bottom">
|
||||||
|
<t-loading size="small" class="breadcrumb-tab-indicator" />
|
||||||
|
</t-tooltip>
|
||||||
|
</span>
|
||||||
<span class="breadcrumb-tab-sep">/</span>
|
<span class="breadcrumb-tab-sep">/</span>
|
||||||
<span
|
<span
|
||||||
:class="['breadcrumb-tab', { active: activeKbTab === 'graph' }]"
|
:class="['breadcrumb-tab', { active: activeKbTab === 'graph', indexing: wikiIsIndexing }]"
|
||||||
@click="activeKbTab = 'graph'"
|
@click="activeKbTab = 'graph'"
|
||||||
>{{ $t('knowledgeEditor.wikiBrowser.tabGraph') }}</span>
|
>
|
||||||
|
{{ $t('knowledgeEditor.wikiBrowser.tabGraph') }}
|
||||||
|
<t-tooltip v-if="wikiIsIndexing" :content="wikiIndexingTip" placement="bottom">
|
||||||
|
<t-loading size="small" class="breadcrumb-tab-indicator" />
|
||||||
|
</t-tooltip>
|
||||||
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<span v-else class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
<span v-else class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||||
</h2>
|
</h2>
|
||||||
@@ -1677,7 +1741,7 @@ async function createNewSession(value: string): Promise<void> {
|
|||||||
|
|
||||||
<!-- Wiki Browser / Graph (shown when wiki or graph tab is active) -->
|
<!-- Wiki Browser / Graph (shown when wiki or graph tab is active) -->
|
||||||
<div v-if="isWiki && (activeKbTab === 'wiki' || activeKbTab === 'graph')" class="wiki-main-area">
|
<div v-if="isWiki && (activeKbTab === 'wiki' || activeKbTab === 'graph')" class="wiki-main-area">
|
||||||
<WikiBrowser v-if="kbId" :knowledge-base-id="kbId" :view="activeKbTab === 'graph' ? 'graph' : 'browser'" @open-source-doc="openSourceDoc" />
|
<WikiBrowser v-if="kbId" :knowledge-base-id="kbId" :view="activeKbTab === 'graph' ? 'graph' : 'browser'" @open-source-doc="openSourceDoc" @status-change="onWikiStatusChange" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template v-if="activeKbTab === 'documents' || !isWiki">
|
<template v-if="activeKbTab === 'documents' || !isWiki">
|
||||||
@@ -2274,6 +2338,9 @@ async function createNewSession(value: string): Promise<void> {
|
|||||||
color: var(--td-text-color-placeholder);
|
color: var(--td-text-color-placeholder);
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
transition: color 0.15s;
|
transition: color 0.15s;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: var(--td-text-color-primary);
|
color: var(--td-text-color-primary);
|
||||||
@@ -2283,6 +2350,18 @@ async function createNewSession(value: string): Promise<void> {
|
|||||||
color: var(--td-brand-color);
|
color: var(--td-brand-color);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.indexing {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.breadcrumb-tab-indicator {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.breadcrumb-tab-sep {
|
.breadcrumb-tab-sep {
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'open-source-doc', knowledgeId: string): void
|
(e: 'open-source-doc', knowledgeId: string): void
|
||||||
|
(e: 'status-change', payload: { pendingTasks: number; isActive: boolean; pendingIssues: number }): void
|
||||||
}>()
|
}>()
|
||||||
const pages = ref<WikiPage[]>([])
|
const pages = ref<WikiPage[]>([])
|
||||||
const selectedPage = ref<WikiPage | null>(null)
|
const selectedPage = ref<WikiPage | null>(null)
|
||||||
@@ -825,6 +826,15 @@ async function loadStats() {
|
|||||||
const res = await getWikiStats(props.knowledgeBaseId)
|
const res = await getWikiStats(props.knowledgeBaseId)
|
||||||
stats.value = (res as any).data || res as any
|
stats.value = (res as any).data || res as any
|
||||||
|
|
||||||
|
// Notify parent so it can reflect wiki status (e.g. indexing badge in the breadcrumb)
|
||||||
|
if (stats.value) {
|
||||||
|
emit('status-change', {
|
||||||
|
pendingTasks: stats.value.pending_tasks || 0,
|
||||||
|
isActive: !!stats.value.is_active,
|
||||||
|
pendingIssues: stats.value.pending_issues || 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Poll if there are pending tasks or wiki ingest is active
|
// Poll if there are pending tasks or wiki ingest is active
|
||||||
if (stats.value && (stats.value.pending_tasks > 0 || stats.value.is_active)) {
|
if (stats.value && (stats.value.pending_tasks > 0 || stats.value.is_active)) {
|
||||||
if (!statsTimer) {
|
if (!statsTimer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user