Merge branch 'main' into storage-allow-list
This commit is contained in:
@@ -28,11 +28,17 @@ import {
|
||||
createKnowledgeFromURL,
|
||||
listKnowledgeBases,
|
||||
reparseKnowledge,
|
||||
batchDeleteKnowledge,
|
||||
} from "@/api/knowledge-base/index";
|
||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||
import DocumentListView from './components/DocumentListView.vue';
|
||||
import DocumentBatchBar from './components/DocumentBatchBar.vue';
|
||||
import WikiBrowser from './wiki/WikiBrowser.vue';
|
||||
import { getWikiStats } from '@/api/wiki';
|
||||
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
||||
import { formatFileSize } from '@/utils/files';
|
||||
import { getParserEngines, type ParserEngineInfo } from '@/api/system';
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
@@ -44,6 +50,86 @@ const uploading = ref(false);
|
||||
const kbLoading = ref(false);
|
||||
const docListLoading = ref(true);
|
||||
const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq');
|
||||
const isWiki = computed(() => !!kbInfo.value?.indexing_strategy?.wiki_enabled);
|
||||
const validTabs = ['documents', 'wiki', 'graph'] as const
|
||||
type KbTab = typeof validTabs[number]
|
||||
const initTab = validTabs.includes(route.query.tab as any) ? (route.query.tab as KbTab) : 'documents'
|
||||
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
|
||||
let wikiStatusProbeTimers: Array<ReturnType<typeof setTimeout>> = []
|
||||
const stopWikiStatusPolling = () => {
|
||||
if (wikiStatusTimer) {
|
||||
clearInterval(wikiStatusTimer)
|
||||
wikiStatusTimer = null
|
||||
}
|
||||
}
|
||||
const clearWikiStatusProbes = () => {
|
||||
wikiStatusProbeTimers.forEach(t => clearTimeout(t))
|
||||
wikiStatusProbeTimers = []
|
||||
}
|
||||
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 */ }
|
||||
}
|
||||
// 用户刚触发了一个上传 / reparse / URL 导入之类的动作后,后台通常要过
|
||||
// 一小段时间才会把 wiki 任务真正塞进队列;如果这时空闲轮询刚好停了,
|
||||
// 面包屑的"索引中"会延迟很久才亮起。所以这里安排几次退避重试,
|
||||
// 主动把面包屑的 loading 尽快点亮,一旦探测到任务就会走正常的 5s 轮询。
|
||||
const scheduleWikiStatusProbes = () => {
|
||||
if (!kbId.value || !isWiki.value) return
|
||||
clearWikiStatusProbes()
|
||||
const delays = [500, 2000, 5000, 10000]
|
||||
delays.forEach(delay => {
|
||||
const timer = setTimeout(() => { fetchWikiStatusOnce() }, delay)
|
||||
wikiStatusProbeTimers.push(timer)
|
||||
})
|
||||
}
|
||||
watch([kbId, isWiki], ([newKbId, newIsWiki]) => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
wikiStatus.value = { pendingTasks: 0, isActive: false, pendingIssues: 0 }
|
||||
if (newKbId && newIsWiki) {
|
||||
fetchWikiStatusOnce()
|
||||
}
|
||||
}, { immediate: true })
|
||||
onUnmounted(() => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
})
|
||||
const missingStorageEngine = computed(() => {
|
||||
if (!kbInfo.value || isFAQ.value) return false
|
||||
const spc = kbInfo.value.storage_provider_config
|
||||
@@ -166,7 +252,7 @@ const onVisibleChange = (visible: boolean) => {
|
||||
}
|
||||
};
|
||||
let isCardDetails = ref(false);
|
||||
let timeout: ReturnType<typeof setInterval> | null = null;
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
let delDialog = ref(false)
|
||||
let rebuildDialog = ref(false)
|
||||
let rebuildKnowledgeItem = ref<KnowledgeCard>({ id: '', parse_status: '' })
|
||||
@@ -187,6 +273,26 @@ const moveMode = ref<'reuse_vectors' | 'reparse'>('reuse_vectors');
|
||||
const moveSubmitting = ref(false);
|
||||
let movePollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
// View mode (grid / list) — persisted per browser
|
||||
type DocViewMode = 'grid' | 'list';
|
||||
const VIEW_MODE_KEY = 'weknora.kb.docs.viewMode';
|
||||
const initViewMode = (): DocViewMode => {
|
||||
try {
|
||||
return localStorage.getItem(VIEW_MODE_KEY) === 'list' ? 'list' : 'grid';
|
||||
} catch { return 'grid'; }
|
||||
};
|
||||
const viewMode = ref<DocViewMode>(initViewMode());
|
||||
watch(viewMode, (v) => {
|
||||
try { localStorage.setItem(VIEW_MODE_KEY, v); } catch { /* ignore */ }
|
||||
});
|
||||
|
||||
// Multi-select state — shared between grid and list views.
|
||||
// Vue 3.5 tracks Set#add/delete natively, so direct mutation is reactive.
|
||||
const selectedIds = ref<Set<string>>(new Set());
|
||||
let lastSelectedIndex = -1;
|
||||
const batchDeleteDialog = ref(false);
|
||||
const batchDeleting = ref(false);
|
||||
|
||||
const selectedTagId = ref<string>('');
|
||||
const tagList = ref<any[]>([]);
|
||||
const tagLoading = ref(false);
|
||||
@@ -276,16 +382,6 @@ const formatDocTime = (time?: string) => {
|
||||
return formatted.slice(2, 16) // "YY-MM-DD HH:mm"
|
||||
}
|
||||
|
||||
// 格式化文件大小,用于气泡等展示
|
||||
const formatFileSize = (bytes?: number | string) => {
|
||||
if (bytes == null || bytes === '') return ''
|
||||
const n = typeof bytes === 'string' ? parseInt(bytes, 10) : bytes
|
||||
if (Number.isNaN(n) || n <= 0) return ''
|
||||
if (n < 1024) return `${n} B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
||||
}
|
||||
|
||||
const channelLabelMap: Record<string, string> = {
|
||||
web: 'knowledgeBase.channelWeb',
|
||||
api: 'knowledgeBase.channelApi',
|
||||
@@ -317,9 +413,9 @@ const getKnowledgeType = (item: any) => {
|
||||
return '--';
|
||||
}
|
||||
|
||||
const loadKnowledgeFiles = (kbIdValue: string) => {
|
||||
if (!kbIdValue) return;
|
||||
getKnowled(
|
||||
const loadKnowledgeFiles = (kbIdValue: string): Promise<void> => {
|
||||
if (!kbIdValue) return Promise.resolve();
|
||||
return getKnowled(
|
||||
{
|
||||
page: 1,
|
||||
page_size: pageSize,
|
||||
@@ -604,6 +700,17 @@ const loadKnowledgeList = async () => {
|
||||
};
|
||||
|
||||
// 监听路由参数变化,重新获取知识库内容
|
||||
// Sync activeKbTab to URL query so it survives page refresh
|
||||
watch(activeKbTab, (tab) => {
|
||||
const query = { ...route.query }
|
||||
if (tab === 'documents') {
|
||||
delete query.tab
|
||||
} else {
|
||||
query.tab = tab
|
||||
}
|
||||
router.replace({ query })
|
||||
})
|
||||
|
||||
watch(() => kbId.value, (newKbId, oldKbId) => {
|
||||
if (newKbId && newKbId !== oldKbId) {
|
||||
tagSearchQuery.value = '';
|
||||
@@ -666,6 +773,8 @@ const handleFileUploaded = (event: CustomEvent) => {
|
||||
page = 1; // Reset page counter when reloading files after upload
|
||||
loadKnowledgeFiles(uploadedKbId);
|
||||
loadTags(uploadedKbId);
|
||||
// 启动几次探测,尽快让面包屑的"索引中"亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -715,6 +824,10 @@ onUnmounted(() => {
|
||||
window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
stopMovePoll();
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
});
|
||||
watch(() => cardList.value, (newValue) => {
|
||||
if (isFAQ.value) return;
|
||||
@@ -734,7 +847,7 @@ watch(() => cardList.value, (newValue) => {
|
||||
return isParsing || isSummaryPending;
|
||||
})
|
||||
if (timeout !== null) {
|
||||
clearInterval(timeout);
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
if (analyzeList.length) {
|
||||
@@ -761,25 +874,59 @@ type KnowledgeCard = {
|
||||
tag_id?: string;
|
||||
};
|
||||
const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
if (!analyzeList.length) return;
|
||||
|
||||
let query = ``;
|
||||
for (let i = 0; i < analyzeList.length; i++) {
|
||||
query += `ids=${analyzeList[i].id}&`;
|
||||
}
|
||||
timeout = setInterval(() => {
|
||||
timeout = setTimeout(() => {
|
||||
batchQueryKnowledge(query).then((result: any) => {
|
||||
let hasChanges = false;
|
||||
if (result.success && result.data) {
|
||||
(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
||||
const index = cardList.value.findIndex(card => card.id == item.id);
|
||||
if (index == -1) return;
|
||||
|
||||
// Always update the card data
|
||||
cardList.value[index].parse_status = item.parse_status;
|
||||
cardList.value[index].summary_status = item.summary_status;
|
||||
cardList.value[index].description = item.description;
|
||||
if (cardList.value[index].parse_status !== item.parse_status ||
|
||||
cardList.value[index].summary_status !== item.summary_status ||
|
||||
cardList.value[index].description !== item.description) {
|
||||
|
||||
// Always update the card data
|
||||
cardList.value[index].parse_status = item.parse_status;
|
||||
cardList.value[index].summary_status = item.summary_status;
|
||||
cardList.value[index].description = item.description;
|
||||
hasChanges = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
// If there are no changes, the watch won't trigger, so we must manually poll again
|
||||
// Even if there are changes, we can manually poll again just to be safe.
|
||||
// The watch will clear this timeout if it triggers.
|
||||
const stillPending = cardList.value.filter(item => {
|
||||
const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';
|
||||
const isSummaryPending = item.parse_status == 'completed' &&
|
||||
(item.summary_status == 'pending' || item.summary_status == 'processing');
|
||||
return isParsing || isSummaryPending;
|
||||
});
|
||||
if (stillPending.length > 0) {
|
||||
updateStatus(stillPending);
|
||||
}
|
||||
}).catch((_err) => {
|
||||
// 错误处理
|
||||
const stillPending = cardList.value.filter(item => {
|
||||
const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';
|
||||
const isSummaryPending = item.parse_status == 'completed' &&
|
||||
(item.summary_status == 'pending' || item.summary_status == 'processing');
|
||||
return isParsing || isSummaryPending;
|
||||
});
|
||||
if (stillPending.length > 0) {
|
||||
updateStatus(stillPending);
|
||||
}
|
||||
});
|
||||
}, 1500);
|
||||
};
|
||||
@@ -795,6 +942,12 @@ const openCardDetails = (item: KnowledgeCard) => {
|
||||
getCardDetails(item);
|
||||
};
|
||||
|
||||
// Open source document preview from WikiBrowser
|
||||
const openSourceDoc = (knowledgeId: string) => {
|
||||
isCardDetails.value = true;
|
||||
getCardDetails({ id: knowledgeId });
|
||||
};
|
||||
|
||||
// 悬停知识卡片时跟随鼠标显示详情气泡
|
||||
const hoveredCardItem = ref<KnowledgeCard | null>(null);
|
||||
const cardPopoverPos = ref({ x: 0, y: 0 });
|
||||
@@ -984,7 +1137,14 @@ const ensureDocumentKbReady = () => {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'));
|
||||
return false;
|
||||
}
|
||||
if (!kbInfo.value || !kbInfo.value.embedding_model_id || !kbInfo.value.summary_model_id) {
|
||||
if (!kbInfo.value || !kbInfo.value.summary_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
// Embedding model only required when RAG indexing is enabled
|
||||
const strategy = (kbInfo.value as any).indexing_strategy
|
||||
const needsEmbedding = !strategy || strategy.vector_enabled || strategy.keyword_enabled
|
||||
if (needsEmbedding && !kbInfo.value.embedding_model_id) {
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return false;
|
||||
}
|
||||
@@ -1419,6 +1579,8 @@ const rebuildConfirm = async () => {
|
||||
MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));
|
||||
page = 1; // Reset page counter when reloading files after reparse
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
// reparse 同样会触发 wiki 重入队,探测一下让面包屑尽快亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('knowledgeBase.rebuildFailed'));
|
||||
}
|
||||
@@ -1452,6 +1614,113 @@ const delCardConfirm = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const toggleSelectRow = (id: string, checked: boolean, shiftKey?: boolean) => {
|
||||
const items = cardList.value || [];
|
||||
const idx = items.findIndex((i: KnowledgeCard) => i.id === id);
|
||||
if (shiftKey && lastSelectedIndex >= 0 && idx >= 0) {
|
||||
const [s, e] = idx < lastSelectedIndex
|
||||
? [idx, lastSelectedIndex]
|
||||
: [lastSelectedIndex, idx];
|
||||
for (let i = s; i <= e; i++) {
|
||||
if (checked) selectedIds.value.add(items[i].id);
|
||||
else selectedIds.value.delete(items[i].id);
|
||||
}
|
||||
} else {
|
||||
if (checked) selectedIds.value.add(id);
|
||||
else selectedIds.value.delete(id);
|
||||
}
|
||||
lastSelectedIndex = idx;
|
||||
};
|
||||
|
||||
const onCardGridCheckboxChange = (id: string, checked: boolean, ctx?: { e?: Event }) => {
|
||||
const me = ctx?.e as MouseEvent | undefined;
|
||||
toggleSelectRow(id, checked, !!me?.shiftKey);
|
||||
};
|
||||
|
||||
const toggleSelectAll = (checked: boolean) => {
|
||||
if (checked) {
|
||||
for (const item of cardList.value || []) selectedIds.value.add(item.id);
|
||||
} else {
|
||||
for (const item of cardList.value || []) selectedIds.value.delete(item.id);
|
||||
}
|
||||
};
|
||||
|
||||
const clearSelection = () => {
|
||||
selectedIds.value.clear();
|
||||
lastSelectedIndex = -1;
|
||||
};
|
||||
|
||||
const openBatchDeleteDialog = () => {
|
||||
if (selectedIds.value.size === 0) return;
|
||||
batchDeleteDialog.value = true;
|
||||
};
|
||||
|
||||
const confirmBatchDelete = async () => {
|
||||
if (batchDeleting.value || selectedIds.value.size === 0) return;
|
||||
const ids = Array.from(selectedIds.value);
|
||||
const deletedIdSet = new Set(ids);
|
||||
batchDeleting.value = true;
|
||||
try {
|
||||
const res: any = await batchDeleteKnowledge(kbId.value, ids);
|
||||
if (res?.success) {
|
||||
MessagePlugin.success(t('knowledgeBase.batchDeleteSuccess', { count: ids.length }));
|
||||
clearSelection();
|
||||
batchDeleteDialog.value = false;
|
||||
page = 1;
|
||||
// 后端将批量删除放入异步队列,立刻拉列表仍可能包含待删项;短轮询直到列表与后端一致或超时
|
||||
const maxPolls = 30;
|
||||
const delayMs = 400;
|
||||
for (let i = 0; i < maxPolls; i++) {
|
||||
await loadKnowledgeFiles(kbId.value);
|
||||
const stillPresent = (cardList.value || []).some((c: KnowledgeCard) => deletedIdSet.has(c.id));
|
||||
if (!stillPresent) break;
|
||||
await new Promise<void>((r) => setTimeout(r, delayMs));
|
||||
}
|
||||
loadTags(kbId.value);
|
||||
} else {
|
||||
MessagePlugin.error(res?.message || t('knowledgeBase.batchDeleteFailed'));
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('knowledgeBase.batchDeleteFailed'));
|
||||
} finally {
|
||||
batchDeleting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Bridge list-view actions back to existing per-card handlers.
|
||||
const handleListAction = (
|
||||
action: 'edit' | 'reparse' | 'move' | 'delete',
|
||||
item: KnowledgeCard,
|
||||
) => {
|
||||
const idx = (cardList.value || []).findIndex((i: KnowledgeCard) => i.id === item.id);
|
||||
if (action === 'edit') return handleManualEdit(idx, item);
|
||||
if (action === 'reparse') return handleKnowledgeReparse(idx, item);
|
||||
if (action === 'move') return handleMoveKnowledge(item);
|
||||
if (action === 'delete') return delCard(idx, item);
|
||||
};
|
||||
|
||||
// Clear selection on filter/tag/kb change to avoid acting on hidden items.
|
||||
watch([selectedTagId, docSearchKeyword, selectedFileType, kbId], () => {
|
||||
clearSelection();
|
||||
});
|
||||
|
||||
// After cardList reloads: stable keys rely on correct indices for shift-range; clamp anchor index.
|
||||
watch(cardList, () => {
|
||||
const items = cardList.value || [];
|
||||
const n = items.length;
|
||||
if (lastSelectedIndex >= n) {
|
||||
lastSelectedIndex = n > 0 ? n - 1 : -1;
|
||||
}
|
||||
if (moreIndex.value >= n) {
|
||||
moreIndex.value = -1;
|
||||
}
|
||||
if (selectedIds.value.size === 0) return;
|
||||
const visible = new Set(items.map((i: KnowledgeCard) => i.id));
|
||||
for (const id of selectedIds.value) {
|
||||
if (!visible.has(id)) selectedIds.value.delete(id);
|
||||
}
|
||||
}, { deep: false });
|
||||
|
||||
// 处理知识库编辑成功后的回调
|
||||
const handleKBEditorSuccess = (kbIdValue: string) => {
|
||||
if (kbIdValue === kbId.value) {
|
||||
@@ -1539,7 +1808,33 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</template>
|
||||
</button>
|
||||
<t-icon name="chevron-right" class="breadcrumb-separator" />
|
||||
<span class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||
<template v-if="isWiki">
|
||||
<span
|
||||
:class="['breadcrumb-tab', { active: activeKbTab === 'documents' }]"
|
||||
@click="activeKbTab = 'documents'"
|
||||
>{{ $t('knowledgeEditor.wikiBrowser.tabDocuments') }}</span>
|
||||
<span class="breadcrumb-tab-sep">/</span>
|
||||
<span
|
||||
:class="['breadcrumb-tab', { active: activeKbTab === 'wiki', indexing: wikiIsIndexing }]"
|
||||
@click="activeKbTab = 'wiki'"
|
||||
>
|
||||
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', { active: activeKbTab === 'graph', indexing: wikiIsIndexing }]"
|
||||
@click="activeKbTab = 'graph'"
|
||||
>
|
||||
{{ $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>
|
||||
<span v-else class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||
</h2>
|
||||
<!-- 身份与最后更新:紧凑单行,置于标题行右侧,悬停显示权限说明 -->
|
||||
<div v-if="kbInfo && !authStore.isLiteMode" class="kb-access-meta">
|
||||
@@ -1590,7 +1885,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Wiki Browser / Graph (shown when wiki or graph tab is active) -->
|
||||
<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" @status-change="onWikiStatusChange" />
|
||||
</div>
|
||||
|
||||
<template v-if="activeKbTab === 'documents' || !isWiki">
|
||||
<input
|
||||
ref="uploadInputRef"
|
||||
type="file"
|
||||
@@ -1799,6 +2100,30 @@ async function createNewSession(value: string): Promise<void> {
|
||||
class="doc-type-select"
|
||||
clearable
|
||||
/>
|
||||
<div class="doc-view-toggle" role="group" :aria-label="$t('knowledgeBase.viewModeToggle')">
|
||||
<t-tooltip :content="$t('knowledgeBase.viewModeGrid')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="doc-view-toggle-btn"
|
||||
:class="{ active: viewMode === 'grid' }"
|
||||
@click="viewMode = 'grid'"
|
||||
:aria-pressed="viewMode === 'grid'"
|
||||
>
|
||||
<t-icon name="view-module" size="16px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
<t-tooltip :content="$t('knowledgeBase.viewModeList')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="doc-view-toggle-btn"
|
||||
:class="{ active: viewMode === 'list' }"
|
||||
@click="viewMode = 'list'"
|
||||
:aria-pressed="viewMode === 'list'"
|
||||
>
|
||||
<t-icon name="view-list" size="16px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<div v-if="canEdit" class="doc-filter-actions">
|
||||
<t-tooltip :content="$t('knowledgeBase.addDocument')" placement="top">
|
||||
<t-dropdown
|
||||
@@ -1834,13 +2159,14 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else-if="cardList.length">
|
||||
<template v-else-if="cardList.length && viewMode === 'grid'">
|
||||
<div class="doc-card-list doc-card-list-animated">
|
||||
<!-- 现有文档卡片 -->
|
||||
<div
|
||||
class="knowledge-card"
|
||||
:class="{ 'is-selected': selectedIds.has(item.id), 'has-selection': selectedIds.size > 0 }"
|
||||
v-for="(item, index) in cardList"
|
||||
:key="index"
|
||||
:key="item.id"
|
||||
@click="openCardDetails(item)"
|
||||
@mouseenter="onCardMouseEnter($event, item)"
|
||||
@mousemove="onCardMouseMove($event)"
|
||||
@@ -1848,6 +2174,20 @@ async function createNewSession(value: string): Promise<void> {
|
||||
>
|
||||
<div class="card-content">
|
||||
<div class="card-content-nav">
|
||||
<div
|
||||
v-if="canEdit"
|
||||
class="card-nav-check"
|
||||
:class="{ active: selectedIds.has(item.id) }"
|
||||
@click.stop
|
||||
>
|
||||
<t-checkbox
|
||||
class="card-select-checkbox"
|
||||
size="small"
|
||||
:checked="selectedIds.has(item.id)"
|
||||
:title="item.file_name"
|
||||
@change="(checked, ctx) => onCardGridCheckboxChange(item.id, checked, ctx)"
|
||||
/>
|
||||
</div>
|
||||
<span class="card-content-title" :title="item.file_name">{{ item.file_name }}</span>
|
||||
<t-popup
|
||||
v-if="canEdit"
|
||||
@@ -2054,12 +2394,32 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
<template v-else-if="cardList.length && viewMode === 'list'">
|
||||
<DocumentListView
|
||||
:items="cardList"
|
||||
:selected-ids="selectedIds"
|
||||
:tag-list="tagList"
|
||||
:can-edit="canEdit"
|
||||
@open="(item: any) => openCardDetails(item)"
|
||||
@toggle-row="toggleSelectRow"
|
||||
@toggle-all="toggleSelectAll"
|
||||
@action="(action: any, item: any) => handleListAction(action, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="!docListLoading">
|
||||
<div class="doc-empty-state">
|
||||
<EmptyKnowledge />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="doc-batch-bar-anchor" v-show="selectedIds.size > 0">
|
||||
<DocumentBatchBar
|
||||
:count="selectedIds.size"
|
||||
:loading="batchDeleting"
|
||||
@clear="clearSelection"
|
||||
@delete="openBatchDeleteDialog"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<t-dialog
|
||||
v-model:visible="delDialog"
|
||||
@@ -2085,6 +2445,41 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 批量删除确认弹窗 -->
|
||||
<t-dialog
|
||||
v-model:visible="batchDeleteDialog"
|
||||
dialogClassName="del-knowledge"
|
||||
:closeBtn="false"
|
||||
:cancelBtn="null"
|
||||
:confirmBtn="null"
|
||||
>
|
||||
<div class="circle-wrap">
|
||||
<div class="header">
|
||||
<img class="circle-img" src="@/assets/img/circle.png" alt="" />
|
||||
<span class="circle-title">{{ t('knowledgeBase.batchDeleteConfirmation') }}</span>
|
||||
</div>
|
||||
<span class="del-circle-txt">
|
||||
{{ t('knowledgeBase.confirmBatchDeleteDocument', { count: selectedIds.size }) }}
|
||||
</span>
|
||||
<div class="circle-btn">
|
||||
<span
|
||||
class="circle-btn-txt"
|
||||
:class="{ disabled: batchDeleting }"
|
||||
@click="batchDeleting ? null : (batchDeleteDialog = false)"
|
||||
>
|
||||
{{ t('common.cancel') }}
|
||||
</span>
|
||||
<span
|
||||
class="circle-btn-txt confirm"
|
||||
:class="{ disabled: batchDeleting }"
|
||||
@click="confirmBatchDelete"
|
||||
>
|
||||
{{ batchDeleting ? '...' : t('knowledgeBase.confirmDelete') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 重建知识确认弹窗 -->
|
||||
<t-dialog
|
||||
v-model:visible="rebuildDialog"
|
||||
@@ -2136,10 +2531,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<div class="url-input-tip">{{ $t('knowledgeBase.urlTip') }}</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<DocContent :visible="isCardDetails" :details="details" @closeDoc="closeDoc" @getDoc="getDoc"></DocContent>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- DocContent drawer (shared by documents tab and wiki source refs) -->
|
||||
<DocContent :visible="isCardDetails" :details="details" @closeDoc="closeDoc" @getDoc="getDoc"></DocContent>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
@@ -2171,10 +2569,54 @@ async function createNewSession(value: string): Promise<void> {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 24px 32px 32px;
|
||||
padding: 24px 32px 0px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
// Breadcrumb tab switch (文档/Wiki in breadcrumb)
|
||||
.breadcrumb-tab {
|
||||
cursor: pointer;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-weight: 400;
|
||||
transition: color 0.15s;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: var(--td-brand-color);
|
||||
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 {
|
||||
margin: 0 6px;
|
||||
color: var(--td-text-color-disabled);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.wiki-main-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// 与列表页一致:浅灰底圆角区,左侧筛选为白底卡片
|
||||
.knowledge-main {
|
||||
display: flex;
|
||||
@@ -2601,6 +3043,38 @@ async function createNewSession(value: string): Promise<void> {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-view-toggle {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 6px;
|
||||
gap: 0;
|
||||
|
||||
.doc-view-toggle-btn {
|
||||
width: 28px;
|
||||
height: 24px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
color: var(--td-text-color-secondary, #888);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.12s ease, color 0.12s ease;
|
||||
|
||||
&:hover { color: var(--td-text-color-primary, #232323); }
|
||||
|
||||
&.active {
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
color: var(--td-brand-color, #0052d9);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.doc-filter-actions {
|
||||
flex-shrink: 0;
|
||||
:deep(.content-bar-icon-btn) {
|
||||
@@ -2663,6 +3137,12 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/* 批量条在滚动区外,始终贴主内容列底部,不随列表高度在列内上下漂移 */
|
||||
.doc-batch-bar-anchor {
|
||||
flex-shrink: 0;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
// Header 样式(无底部分割线,留更多空间给下方内容区)
|
||||
.document-header {
|
||||
display: flex;
|
||||
@@ -2939,6 +3419,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.faq-manager-wrapper {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 24px 32px;
|
||||
overflow-y: auto;
|
||||
margin: 0 16px 0 4px;
|
||||
@@ -2993,7 +3474,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
|
||||
gap: 14px;
|
||||
gap: 16px;
|
||||
align-content: flex-start;
|
||||
width: 100%;
|
||||
|
||||
@@ -3004,14 +3485,24 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.knowledge-card-skeleton {
|
||||
cursor: default;
|
||||
.card-content { padding: 15px 17px 13px; }
|
||||
.card-content-nav { margin-bottom: 14px; }
|
||||
|
||||
.card-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 12px 16px 8px;
|
||||
}
|
||||
|
||||
.card-content-nav {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
flex-shrink: 0;
|
||||
margin-top: auto;
|
||||
width: 100%;
|
||||
padding: 0 17px;
|
||||
padding: 0 16px;
|
||||
box-sizing: border-box;
|
||||
height: 34px;
|
||||
display: flex;
|
||||
@@ -3099,6 +3590,11 @@ async function createNewSession(value: string): Promise<void> {
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
cursor: pointer;
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.confirm {
|
||||
@@ -3293,6 +3789,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.card-draft-tip {
|
||||
@@ -3302,22 +3799,77 @@ async function createNewSession(value: string): Promise<void> {
|
||||
|
||||
.knowledge-card {
|
||||
min-width: 248px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid color-mix(in srgb, var(--td-component-stroke) 82%, var(--td-bg-color-secondarycontainer));
|
||||
height: 148px;
|
||||
border-radius: 9px;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.035);
|
||||
background: var(--td-bg-color-container);
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
|
||||
|
||||
/* 初始态略可见,悬停/多选/已选时再强调,避免「凭空多一列」的突兀感 */
|
||||
.card-nav-check {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 29px;
|
||||
opacity: 0.4;
|
||||
transition: opacity 0.2s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&.active,
|
||||
&:focus-within {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.card-select-checkbox {
|
||||
margin: 0;
|
||||
line-height: 0;
|
||||
|
||||
:deep(.t-checkbox) {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
display: none !important;
|
||||
width: 0 !important;
|
||||
min-width: 0 !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input-wrapper) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:hover .card-nav-check,
|
||||
&.has-selection .card-nav-check {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
padding: 15px 17px 13px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 12px 16px 8px;
|
||||
}
|
||||
|
||||
.card-analyze {
|
||||
flex-shrink: 0;
|
||||
height: 52px;
|
||||
display: flex;
|
||||
}
|
||||
@@ -3341,11 +3893,11 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-content-nav {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 11px;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-content-title {
|
||||
@@ -3389,6 +3941,8 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-content-txt {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
@@ -3402,9 +3956,9 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
padding: 0 17px;
|
||||
flex-shrink: 0;
|
||||
margin-top: auto;
|
||||
padding: 0 16px;
|
||||
box-sizing: border-box;
|
||||
height: 34px;
|
||||
width: 100%;
|
||||
@@ -3423,19 +3977,19 @@ async function createNewSession(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
.card-type {
|
||||
color: var(--td-text-color-secondary);
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-family: "PingFang SC";
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
padding: 3px 8px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 4px;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
}
|
||||
|
||||
.knowledge-card:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
box-shadow: 0 2px 8px rgba(7, 192, 95, 0.12);
|
||||
border-color: color-mix(in srgb, var(--td-component-stroke) 55%, var(--td-brand-color));
|
||||
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
|
||||
}
|
||||
|
||||
/* 悬停知识卡片时跟随鼠标的详情气泡 */
|
||||
|
||||
@@ -52,6 +52,69 @@
|
||||
</t-radio-group>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.basic.typeDescription') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 索引策略 (紧跟类型选择) -->
|
||||
<div v-if="!isFAQ" class="form-item">
|
||||
<label class="form-label required">{{ $t('knowledgeEditor.indexing.title') }}</label>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.indexing.description') }}</p>
|
||||
<div class="indexing-checks" :class="{ 'is-locked': isIndexingLocked }">
|
||||
<div
|
||||
class="indexing-check-item"
|
||||
:class="{ 'is-checked': formData.indexingStrategy.vectorEnabled, 'is-disabled': isIndexingLocked }"
|
||||
@click="toggleVectorIndexing"
|
||||
>
|
||||
<t-checkbox
|
||||
:checked="formData.indexingStrategy.vectorEnabled"
|
||||
:disabled="isIndexingLocked"
|
||||
class="indexing-check-box"
|
||||
>{{ $t('knowledgeEditor.indexing.searchTitle') }}</t-checkbox>
|
||||
<p class="indexing-check-desc">{{ $t('knowledgeEditor.indexing.searchDesc') }}</p>
|
||||
</div>
|
||||
<div
|
||||
class="indexing-check-item"
|
||||
:class="{ 'is-checked': formData.indexingStrategy.wikiEnabled, 'is-disabled': isIndexingLocked }"
|
||||
@click="toggleWikiIndexing"
|
||||
>
|
||||
<t-checkbox
|
||||
:checked="formData.indexingStrategy.wikiEnabled"
|
||||
:disabled="isIndexingLocked"
|
||||
class="indexing-check-box"
|
||||
>
|
||||
<span class="indexing-check-title">
|
||||
{{ $t('knowledgeEditor.indexing.wikiTitle') }}
|
||||
<span class="indexing-new-badge">NEW</span>
|
||||
</span>
|
||||
</t-checkbox>
|
||||
<p class="indexing-check-desc">{{ $t('knowledgeEditor.indexing.wikiDesc') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="isIndexingLocked" class="form-tip locked-tip">
|
||||
{{ $t('knowledgeEditor.indexing.lockedTip') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 提取粒度 (仅当 Wiki 启用时显示) -->
|
||||
<div v-if="!isFAQ && formData.indexingStrategy.wikiEnabled" class="form-item">
|
||||
<label class="form-label">{{ $t('knowledgeEditor.wiki.extractionGranularityLabel') }}</label>
|
||||
<p class="form-tip">{{ $t('knowledgeEditor.wiki.extractionGranularityTip') }}</p>
|
||||
<t-radio-group
|
||||
:value="resolvedGranularity"
|
||||
class="granularity-radio-group"
|
||||
@change="handleGranularityChange"
|
||||
>
|
||||
<t-radio-button value="focused">
|
||||
{{ $t('knowledgeEditor.wiki.granularityFocused') }}
|
||||
</t-radio-button>
|
||||
<t-radio-button value="standard">
|
||||
{{ $t('knowledgeEditor.wiki.granularityStandard') }}
|
||||
</t-radio-button>
|
||||
<t-radio-button value="exhaustive">
|
||||
{{ $t('knowledgeEditor.wiki.granularityExhaustive') }}
|
||||
</t-radio-button>
|
||||
</t-radio-group>
|
||||
<p class="form-tip granularity-hint">{{ granularityHint }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label required">{{ $t('knowledgeEditor.basic.nameLabel') }}</label>
|
||||
<t-input
|
||||
@@ -62,13 +125,15 @@
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('knowledgeEditor.basic.descriptionLabel') }}</label>
|
||||
<t-textarea
|
||||
v-model="formData.description"
|
||||
<t-textarea
|
||||
v-model="formData.description"
|
||||
:placeholder="$t('knowledgeEditor.basic.descriptionPlaceholder')"
|
||||
:maxlength="200"
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 合成模型移至模型配置页 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -80,6 +145,8 @@
|
||||
v-if="formData"
|
||||
:config="formData.modelConfig"
|
||||
:has-files="hasFiles"
|
||||
:wiki-enabled="formData.indexingStrategy?.wikiEnabled"
|
||||
:rag-enabled="formData.indexingStrategy?.vectorEnabled || formData.indexingStrategy?.keywordEnabled"
|
||||
:all-models="allModels"
|
||||
@update:config="handleModelConfigUpdate"
|
||||
/>
|
||||
@@ -146,17 +213,6 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 图谱设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'graph'" class="section">
|
||||
<GraphSettings
|
||||
v-if="formData"
|
||||
:graph-extract="formData.nodeExtractConfig"
|
||||
:model-id="formData.modelConfig.llmModelId"
|
||||
:all-models="allModels"
|
||||
@update:graphExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 多模态配置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'multimodal'" class="section">
|
||||
<div v-if="formData" class="kb-multimodal-settings">
|
||||
@@ -202,7 +258,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 音视频语音识别(ASR)设置 -->
|
||||
<!-- 音频处理(ASR)设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'asr'" class="section">
|
||||
<div v-if="formData" class="kb-multimodal-settings">
|
||||
<div class="section-header">
|
||||
@@ -246,12 +302,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 知识图谱 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'graph'" class="section">
|
||||
<GraphSettings
|
||||
v-if="formData"
|
||||
:graph-extract="formData.nodeExtractConfig"
|
||||
:model-id="formData.modelConfig.llmModelId"
|
||||
:all-models="allModels"
|
||||
@update:graphExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 高级设置 -->
|
||||
<div v-if="!isFAQ" v-show="currentSection === 'advanced'" class="section">
|
||||
<KBAdvancedSettings
|
||||
ref="advancedSettingsRef"
|
||||
v-if="formData"
|
||||
:question-generation="formData.questionGenerationConfig"
|
||||
:rag-enabled="formData.indexingStrategy?.vectorEnabled || formData.indexingStrategy?.keywordEnabled"
|
||||
:all-models="allModels"
|
||||
@update:question-generation="handleQuestionGenerationUpdate"
|
||||
/>
|
||||
@@ -288,7 +356,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase, rebuildKBIndex } from '@/api/knowledge-base'
|
||||
import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
|
||||
import { listModels } from '@/api/model'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
@@ -328,7 +396,25 @@ const loading = ref(false)
|
||||
const allModels = ref<any[]>([])
|
||||
const hasFiles = ref(false)
|
||||
const initialStorageProvider = ref<string>('')
|
||||
const initialIndexingStrategy = ref<any>(null)
|
||||
const dsCount = ref(0)
|
||||
// 用户是否在分块设置中手动改过任何值。一旦为 true,就不再根据索引策略自动调整默认分块参数。
|
||||
const chunkingDirty = ref(false)
|
||||
|
||||
// 仅 Wiki 索引模式下的分块预设:更大 chunk、无 overlap、关闭父子分块。
|
||||
// 该预设只在「创建模式」下、且用户尚未手动调整分块参数时生效,避免覆盖既有 KB 的配置。
|
||||
const WIKI_ONLY_CHUNKING_PRESET = {
|
||||
chunkSize: 2048,
|
||||
chunkOverlap: 0,
|
||||
enableParentChild: false,
|
||||
} as const
|
||||
|
||||
// 非 Wiki-only 场景下回落到的默认值(与 initFormData 保持一致)。
|
||||
const DEFAULT_CHUNKING_PRESET = {
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 100,
|
||||
enableParentChild: true,
|
||||
} as const
|
||||
|
||||
const navItems = computed(() => {
|
||||
const items: { key: string; icon: string; label: string; badge?: number }[] = [
|
||||
@@ -394,7 +480,8 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
},
|
||||
modelConfig: {
|
||||
llmModelId: '',
|
||||
embeddingModelId: ''
|
||||
embeddingModelId: '',
|
||||
wikiSynthesisModelId: '',
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: 512,
|
||||
@@ -433,6 +520,17 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
enabled: true,
|
||||
questionCount: 3
|
||||
},
|
||||
wikiConfig: {
|
||||
synthesisModelId: '',
|
||||
maxPagesPerIngest: 0,
|
||||
extractionGranularity: 'standard' as 'focused' | 'standard' | 'exhaustive',
|
||||
},
|
||||
indexingStrategy: {
|
||||
vectorEnabled: true,
|
||||
keywordEnabled: true,
|
||||
wikiEnabled: false,
|
||||
graphEnabled: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,7 +577,8 @@ const loadKBData = async () => {
|
||||
},
|
||||
modelConfig: {
|
||||
llmModelId: kb.summary_model_id || '',
|
||||
embeddingModelId: kb.embedding_model_id || ''
|
||||
embeddingModelId: kb.embedding_model_id || '',
|
||||
wikiSynthesisModelId: kb.wiki_config?.synthesis_model_id || ''
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: kb.chunking_config?.chunk_size || 512,
|
||||
@@ -514,8 +613,25 @@ const loadKBData = async () => {
|
||||
enabled: kb.question_generation_config?.enabled || false,
|
||||
questionCount: kb.question_generation_config?.question_count || 3
|
||||
},
|
||||
wikiConfig: {
|
||||
synthesisModelId: kb.wiki_config?.synthesis_model_id || '',
|
||||
maxPagesPerIngest: kb.wiki_config?.max_pages_per_ingest || 0,
|
||||
extractionGranularity: (
|
||||
kb.wiki_config?.extraction_granularity === 'focused' ||
|
||||
kb.wiki_config?.extraction_granularity === 'exhaustive'
|
||||
? kb.wiki_config.extraction_granularity
|
||||
: 'standard'
|
||||
) as 'focused' | 'standard' | 'exhaustive',
|
||||
},
|
||||
indexingStrategy: {
|
||||
vectorEnabled: kb.indexing_strategy?.vector_enabled ?? true,
|
||||
keywordEnabled: kb.indexing_strategy?.keyword_enabled ?? true,
|
||||
wikiEnabled: kb.indexing_strategy?.wiki_enabled ?? false,
|
||||
graphEnabled: kb.indexing_strategy?.graph_enabled ?? false,
|
||||
},
|
||||
}
|
||||
initialStorageProvider.value = formData.value.storageProvider
|
||||
initialIndexingStrategy.value = { ...formData.value.indexingStrategy }
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge base data:', error)
|
||||
MessagePlugin.error(t('knowledgeEditor.messages.loadDataFailed'))
|
||||
@@ -532,12 +648,83 @@ const handleModelConfigUpdate = (config: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 粒度选择器:从 formData.wikiConfig 读出并规范化,未知值回退到 'standard',
|
||||
// 与后端 WikiExtractionGranularity.Normalize() 的契约保持一致。
|
||||
const resolvedGranularity = computed<'focused' | 'standard' | 'exhaustive'>(() => {
|
||||
const g = formData.value?.wikiConfig?.extractionGranularity
|
||||
if (g === 'focused' || g === 'standard' || g === 'exhaustive') {
|
||||
return g
|
||||
}
|
||||
return 'standard'
|
||||
})
|
||||
|
||||
const granularityHint = computed<string>(() => {
|
||||
switch (resolvedGranularity.value) {
|
||||
case 'focused':
|
||||
return t('knowledgeEditor.wiki.granularityFocusedHint')
|
||||
case 'exhaustive':
|
||||
return t('knowledgeEditor.wiki.granularityExhaustiveHint')
|
||||
default:
|
||||
return t('knowledgeEditor.wiki.granularityStandardHint')
|
||||
}
|
||||
})
|
||||
|
||||
const handleGranularityChange = (value: string | number | boolean) => {
|
||||
if (!formData.value) return
|
||||
const next: 'focused' | 'standard' | 'exhaustive' =
|
||||
value === 'focused' || value === 'exhaustive'
|
||||
? (value as 'focused' | 'exhaustive')
|
||||
: 'standard'
|
||||
formData.value.wikiConfig = {
|
||||
...formData.value.wikiConfig,
|
||||
extractionGranularity: next,
|
||||
}
|
||||
}
|
||||
|
||||
const isIndexingLocked = computed(() => props.mode === 'edit' && hasFiles.value)
|
||||
|
||||
const toggleVectorIndexing = () => {
|
||||
if (!formData.value) return
|
||||
if (isIndexingLocked.value) return
|
||||
const next = !formData.value.indexingStrategy.vectorEnabled
|
||||
formData.value.indexingStrategy.vectorEnabled = next
|
||||
formData.value.indexingStrategy.keywordEnabled = next
|
||||
}
|
||||
|
||||
const toggleWikiIndexing = () => {
|
||||
if (!formData.value) return
|
||||
if (isIndexingLocked.value) return
|
||||
formData.value.indexingStrategy.wikiEnabled = !formData.value.indexingStrategy.wikiEnabled
|
||||
}
|
||||
|
||||
const handleChunkingConfigUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.chunkingConfig = { ...config }
|
||||
// 用户已经手动触达分块设置,后续索引策略切换不再覆盖这些值
|
||||
chunkingDirty.value = true
|
||||
}
|
||||
}
|
||||
|
||||
// 判断当前是否为「仅 Wiki 索引」:只开了 Wiki,关了向量/关键词检索
|
||||
const isWikiOnlyStrategy = computed(() => {
|
||||
const s = formData.value?.indexingStrategy
|
||||
if (!s) return false
|
||||
return !!s.wikiEnabled && !s.vectorEnabled && !s.keywordEnabled
|
||||
})
|
||||
|
||||
// 仅在创建模式、用户未改过分块设置时,随索引策略自动应用/撤销 Wiki-only 预设。
|
||||
// 编辑模式严格保持后端已有配置不变,避免误改。
|
||||
watch(isWikiOnlyStrategy, (wikiOnly) => {
|
||||
if (props.mode !== 'create') return
|
||||
if (!formData.value) return
|
||||
if (chunkingDirty.value) return
|
||||
const preset = wikiOnly ? WIKI_ONLY_CHUNKING_PRESET : DEFAULT_CHUNKING_PRESET
|
||||
formData.value.chunkingConfig = {
|
||||
...formData.value.chunkingConfig,
|
||||
...preset,
|
||||
}
|
||||
})
|
||||
|
||||
const handleParserEngineRulesUpdate = (rules: any[]) => {
|
||||
if (formData.value) {
|
||||
formData.value.chunkingConfig.parserEngineRules = rules?.length ? rules : undefined
|
||||
@@ -564,6 +751,10 @@ const handleAddASRModel = () => {
|
||||
uiStore.openSettings('models', 'asr')
|
||||
}
|
||||
|
||||
const handleAddWikiModel = () => {
|
||||
uiStore.openSettings('models', 'knowledgeqa')
|
||||
}
|
||||
|
||||
const handleStorageProviderUpdate = (value: string) => {
|
||||
if (formData.value) {
|
||||
formData.value.storageProvider = value || 'local'
|
||||
@@ -593,9 +784,20 @@ const validateForm = (): boolean => {
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证模型配置 - 必须配置 embedding 和 summary 模型
|
||||
if (!formData.value.modelConfig.embeddingModelId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.embeddingRequired'))
|
||||
// 验证索引策略 — 文档类型至少需要开启一种
|
||||
if (formData.value.type !== 'faq') {
|
||||
const s = formData.value.indexingStrategy
|
||||
if (s && !s.vectorEnabled && !s.keywordEnabled && !s.wikiEnabled && !s.graphEnabled) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.indexing.atLeastOne'))
|
||||
currentSection.value = 'basic'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 验证模型配置 - embedding 模型仅在检索索引启用时必须
|
||||
const needsEmbedding = formData.value.indexingStrategy?.vectorEnabled || formData.value.indexingStrategy?.keywordEnabled
|
||||
if (needsEmbedding && !formData.value.modelConfig.embeddingModelId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.indexing.embeddingRequired'))
|
||||
currentSection.value = 'models'
|
||||
return false
|
||||
}
|
||||
@@ -672,16 +874,8 @@ const buildSubmitData = () => {
|
||||
provider: formData.value.storageProvider || 'local'
|
||||
}
|
||||
|
||||
// 添加知识图谱配置
|
||||
if (formData.value.nodeExtractConfig.enabled) {
|
||||
data.extract_config = {
|
||||
enabled: true,
|
||||
text: formData.value.nodeExtractConfig.text,
|
||||
tags: formData.value.nodeExtractConfig.tags,
|
||||
nodes: formData.value.nodeExtractConfig.nodes,
|
||||
relations: formData.value.nodeExtractConfig.relations
|
||||
}
|
||||
}
|
||||
// 添加知识图谱配置 — now synced via indexingStrategy.graphEnabled
|
||||
// extract_config is sent below along with indexing_strategy
|
||||
|
||||
// 添加问题生成配置
|
||||
if (formData.value.questionGenerationConfig?.enabled) {
|
||||
@@ -698,6 +892,37 @@ const buildSubmitData = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Wiki enablement is carried solely by indexing_strategy.wiki_enabled.
|
||||
// wiki_config only holds wiki-specific tunables.
|
||||
if (formData.value.type !== 'faq') {
|
||||
data.wiki_config = {
|
||||
synthesis_model_id: formData.value.modelConfig?.wikiSynthesisModelId || '',
|
||||
max_pages_per_ingest: formData.value.wikiConfig?.maxPagesPerIngest || 0,
|
||||
extraction_granularity: formData.value.wikiConfig?.extractionGranularity || 'standard',
|
||||
}
|
||||
}
|
||||
|
||||
// Send indexing strategy
|
||||
if (formData.value.type !== 'faq') {
|
||||
data.indexing_strategy = {
|
||||
vector_enabled: formData.value.indexingStrategy?.vectorEnabled ?? true,
|
||||
keyword_enabled: formData.value.indexingStrategy?.keywordEnabled ?? true,
|
||||
wiki_enabled: formData.value.indexingStrategy?.wikiEnabled ?? false,
|
||||
graph_enabled: formData.value.indexingStrategy?.graphEnabled ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
// Sync extract_config.enabled from indexingStrategy.graphEnabled
|
||||
if (formData.value.indexingStrategy?.graphEnabled && formData.value.nodeExtractConfig?.enabled) {
|
||||
data.extract_config = {
|
||||
enabled: true,
|
||||
text: formData.value.nodeExtractConfig.text,
|
||||
tags: formData.value.nodeExtractConfig.tags,
|
||||
nodes: formData.value.nodeExtractConfig.nodes,
|
||||
relations: formData.value.nodeExtractConfig.relations
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -756,7 +981,7 @@ const doSubmit = async () => {
|
||||
throw new Error(t('knowledgeEditor.messages.missingId'))
|
||||
}
|
||||
|
||||
// 1. 更新基本信息(名称、描述)和 FAQ 配置
|
||||
// 1. 更新基本信息(名称、描述)和 FAQ/Wiki 配置
|
||||
const updateConfig: any = {}
|
||||
if (formData.value.type === 'faq' && formData.value.faqConfig) {
|
||||
updateConfig.faq_config = {
|
||||
@@ -764,6 +989,21 @@ const doSubmit = async () => {
|
||||
question_index_mode: formData.value.faqConfig.questionIndexMode || 'separate'
|
||||
}
|
||||
}
|
||||
if (formData.value.wikiConfig && formData.value.type !== 'faq') {
|
||||
updateConfig.wiki_config = {
|
||||
synthesis_model_id: formData.value.modelConfig?.wikiSynthesisModelId || '',
|
||||
max_pages_per_ingest: formData.value.wikiConfig.maxPagesPerIngest || 0,
|
||||
extraction_granularity: formData.value.wikiConfig.extractionGranularity || 'standard',
|
||||
}
|
||||
}
|
||||
if (formData.value.type !== 'faq') {
|
||||
updateConfig.indexing_strategy = {
|
||||
vector_enabled: formData.value.indexingStrategy?.vectorEnabled ?? true,
|
||||
keyword_enabled: formData.value.indexingStrategy?.keywordEnabled ?? true,
|
||||
wiki_enabled: formData.value.indexingStrategy?.wikiEnabled ?? false,
|
||||
graph_enabled: formData.value.indexingStrategy?.graphEnabled ?? false,
|
||||
}
|
||||
}
|
||||
await updateKnowledgeBase(props.kbId, {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
@@ -804,6 +1044,41 @@ const doSubmit = async () => {
|
||||
|
||||
await updateKBConfig(props.kbId, config)
|
||||
MessagePlugin.success(t('knowledgeEditor.messages.updateSuccess'))
|
||||
|
||||
// Check if indexing strategy changed and offer rebuild
|
||||
if (hasFiles.value && initialIndexingStrategy.value && formData.value) {
|
||||
const curr = formData.value.indexingStrategy
|
||||
const prev = initialIndexingStrategy.value
|
||||
const strategyChanged = (
|
||||
curr.vectorEnabled !== prev.vectorEnabled ||
|
||||
curr.keywordEnabled !== prev.keywordEnabled ||
|
||||
curr.wikiEnabled !== prev.wikiEnabled ||
|
||||
curr.graphEnabled !== prev.graphEnabled
|
||||
)
|
||||
if (strategyChanged) {
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('knowledgeEditor.indexing.rebuildConfirmTitle'),
|
||||
body: t('knowledgeEditor.indexing.rebuildConfirmBody', { count: '...' }),
|
||||
confirmBtn: t('common.confirm'),
|
||||
cancelBtn: t('common.cancel'),
|
||||
onConfirm: async () => {
|
||||
dialog.destroy()
|
||||
try {
|
||||
const result: any = await rebuildKBIndex(props.kbId!)
|
||||
const count = result?.data?.document_count ?? 0
|
||||
MessagePlugin.success(t('knowledgeEditor.indexing.rebuildSuccess', { count }))
|
||||
} catch (e) {
|
||||
console.error('Rebuild index failed:', e)
|
||||
}
|
||||
},
|
||||
onCancel: () => {
|
||||
dialog.destroy()
|
||||
MessagePlugin.info(t('knowledgeEditor.indexing.rebuildSkip'))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
emit('success', props.kbId)
|
||||
}
|
||||
|
||||
@@ -822,8 +1097,10 @@ const resetState = () => {
|
||||
formData.value = null
|
||||
hasFiles.value = false
|
||||
initialStorageProvider.value = ''
|
||||
initialIndexingStrategy.value = null
|
||||
saving.value = false
|
||||
loading.value = false
|
||||
chunkingDirty.value = false
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
@@ -1069,7 +1346,7 @@ watch(
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
@@ -1097,6 +1374,103 @@ watch(
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.granularity-radio-group {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.granularity-hint {
|
||||
margin-top: 8px;
|
||||
line-height: 1.6;
|
||||
color: var(--td-text-color-secondary);
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.indexing-checks {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.indexing-check-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
background: var(--td-bg-color-container);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&.is-checked {
|
||||
border-color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
&.is-disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.7;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
&.is-checked:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.locked-tip {
|
||||
color: var(--td-warning-color);
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
// 禁用内部 checkbox 自身的点击事件,统一由卡片处理
|
||||
.indexing-check-box {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.indexing-check-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.indexing-new-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0 6px;
|
||||
height: 16px;
|
||||
border-radius: 3px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
letter-spacing: 0.4px;
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
.indexing-check-desc {
|
||||
margin: 0;
|
||||
padding-left: 24px;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.faq-guide {
|
||||
margin-top: 20px;
|
||||
padding: 12px 16px;
|
||||
|
||||
@@ -1004,8 +1004,13 @@ const confirmDelete = () => {
|
||||
}
|
||||
|
||||
const isInitialized = (kb: KB) => {
|
||||
return !!(kb.embedding_model_id && kb.embedding_model_id !== '' &&
|
||||
kb.summary_model_id && kb.summary_model_id !== '')
|
||||
// LLM (summary) model is always required
|
||||
if (!kb.summary_model_id || kb.summary_model_id === '') return false
|
||||
// Embedding model only required when RAG indexing is enabled (vector or keyword)
|
||||
const strategy = (kb as any).indexing_strategy
|
||||
const needsEmbedding = !strategy || strategy.vector_enabled || strategy.keyword_enabled
|
||||
if (needsEmbedding && (!kb.embedding_model_id || kb.embedding_model_id === '')) return false
|
||||
return true
|
||||
}
|
||||
|
||||
// 计算是否有未初始化的知识库
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
defineProps<{
|
||||
count: number;
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'clear'): void;
|
||||
(e: 'delete'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<transition name="batch-bar-fade">
|
||||
<div v-if="count > 0" class="doc-batch-bar" role="region" :aria-label="t('knowledgeBase.selectedCount', { count })">
|
||||
<div class="batch-bar-inner">
|
||||
<div class="batch-bar-left">
|
||||
<span class="batch-bar-count">{{ t('knowledgeBase.selectedCount', { count }) }}</span>
|
||||
<t-button variant="text" theme="default" size="small" class="batch-bar-clear" @click="emit('clear')">
|
||||
{{ t('knowledgeBase.clearSelection') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="batch-bar-actions">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="small"
|
||||
:loading="loading"
|
||||
@click="emit('delete')"
|
||||
>
|
||||
<template #icon><t-icon name="delete" size="14px" /></template>
|
||||
{{ t('knowledgeBase.batchDelete') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.doc-batch-bar {
|
||||
position: relative;
|
||||
z-index: 5;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
padding: 0 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.batch-bar-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.batch-bar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.batch-bar-count {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.batch-bar-clear {
|
||||
flex-shrink: 0;
|
||||
padding: 0 6px !important;
|
||||
height: 28px !important;
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary) !important;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.batch-bar-actions {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.batch-bar-fade-enter-active,
|
||||
.batch-bar-fade-leave-active {
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.batch-bar-fade-enter-from,
|
||||
.batch-bar-fade-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,562 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatFileSize, getFileIcon } from '@/utils/files';
|
||||
|
||||
interface Tag {
|
||||
id: string;
|
||||
name: string;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
interface KnowledgeItem {
|
||||
id: string;
|
||||
file_name: string;
|
||||
file_type?: string;
|
||||
file_size?: number | string;
|
||||
type?: string;
|
||||
tag_id?: string | number;
|
||||
parse_status?: string;
|
||||
summary_status?: string;
|
||||
updated_at?: string;
|
||||
source?: string;
|
||||
isMore?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
items: KnowledgeItem[];
|
||||
selectedIds: Set<string>;
|
||||
canEdit: boolean;
|
||||
tagList: Tag[];
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'open', item: KnowledgeItem): void;
|
||||
(e: 'toggle-row', id: string, checked: boolean, shiftKey: boolean): void;
|
||||
(e: 'toggle-all', checked: boolean): void;
|
||||
(e: 'action', action: 'edit' | 'reparse' | 'move' | 'delete', item: KnowledgeItem): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const tagMap = computed(() => {
|
||||
const map: Record<string, Tag> = {};
|
||||
for (const tag of props.tagList) map[String(tag.id)] = tag;
|
||||
return map;
|
||||
});
|
||||
const getTagName = (tagId?: string | number) => {
|
||||
if (!tagId && tagId !== 0) return '';
|
||||
return tagMap.value[String(tagId)]?.name || '';
|
||||
};
|
||||
|
||||
const formatTime = (time?: string) => {
|
||||
if (!time) return '--';
|
||||
const d = new Date(time);
|
||||
if (Number.isNaN(d.getTime())) return '--';
|
||||
const yy = String(d.getFullYear()).slice(2);
|
||||
const MM = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(d.getDate()).padStart(2, '0');
|
||||
const hh = String(d.getHours()).padStart(2, '0');
|
||||
const mm = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${yy}-${MM}-${dd} ${hh}:${mm}`;
|
||||
};
|
||||
|
||||
const getTypeLabel = (item: KnowledgeItem) => {
|
||||
if (item.type === 'url') return 'URL';
|
||||
if (item.type === 'manual') return t('knowledgeBase.typeManual');
|
||||
if (item.file_type) return item.file_type.toUpperCase();
|
||||
return '--';
|
||||
};
|
||||
|
||||
interface StatusInfo {
|
||||
label: string;
|
||||
theme: 'success' | 'warning' | 'danger' | 'primary' | 'default';
|
||||
icon?: string;
|
||||
spin?: boolean;
|
||||
}
|
||||
const computeStatus = (item: KnowledgeItem): StatusInfo => {
|
||||
if (item.parse_status === 'pending' || item.parse_status === 'processing') {
|
||||
return { label: t('knowledgeBase.statusProcessing'), theme: 'primary', icon: 'loading', spin: true };
|
||||
}
|
||||
if (item.parse_status === 'failed') {
|
||||
return { label: t('knowledgeBase.statusFailed'), theme: 'danger', icon: 'close-circle' };
|
||||
}
|
||||
if (item.parse_status === 'draft') {
|
||||
return { label: t('knowledgeBase.statusDraft'), theme: 'warning' };
|
||||
}
|
||||
if (
|
||||
item.parse_status === 'completed' &&
|
||||
(item.summary_status === 'pending' || item.summary_status === 'processing')
|
||||
) {
|
||||
return { label: t('knowledgeBase.generatingSummary'), theme: 'primary', icon: 'loading', spin: true };
|
||||
}
|
||||
if (item.parse_status === 'completed') {
|
||||
return { label: t('knowledgeBase.statusCompleted'), theme: 'success' };
|
||||
}
|
||||
return { label: '--', theme: 'default' };
|
||||
};
|
||||
|
||||
const statusByRow = computed(() => {
|
||||
const map = new Map<string, StatusInfo>();
|
||||
for (const item of props.items) map.set(item.id, computeStatus(item));
|
||||
return map;
|
||||
});
|
||||
|
||||
const allSelected = computed(() => {
|
||||
return props.items.length > 0 && props.items.every(i => props.selectedIds.has(i.id));
|
||||
});
|
||||
const someSelected = computed(() => {
|
||||
return props.items.some(i => props.selectedIds.has(i.id)) && !allSelected.value;
|
||||
});
|
||||
|
||||
const onHeaderCheckboxChange = (checked: boolean) => {
|
||||
emit('toggle-all', checked);
|
||||
};
|
||||
|
||||
const onRowCheckboxChange = (item: KnowledgeItem, checked: boolean, ctx?: { e?: Event }) => {
|
||||
const me = ctx?.e as MouseEvent | undefined;
|
||||
emit('toggle-row', item.id, checked, !!me?.shiftKey);
|
||||
};
|
||||
|
||||
const moreOpen = ref<string | null>(null);
|
||||
const onMoreVisible = (id: string, visible: boolean) => {
|
||||
moreOpen.value = visible ? id : null;
|
||||
};
|
||||
|
||||
const handleAction = (action: 'edit' | 'reparse' | 'move' | 'delete', item: KnowledgeItem) => {
|
||||
moreOpen.value = null;
|
||||
item.isMore = false;
|
||||
emit('action', action, item);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="doc-list-view" :class="{ 'is-loading': loading }">
|
||||
<div class="doc-list-header" role="row">
|
||||
<div class="cell cell-check" role="columnheader" @click.stop>
|
||||
<t-checkbox
|
||||
class="doc-list-check"
|
||||
size="small"
|
||||
:checked="allSelected"
|
||||
:indeterminate="someSelected"
|
||||
:disabled="!items.length"
|
||||
:title="t('knowledgeBase.selectAll')"
|
||||
@change="onHeaderCheckboxChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="cell cell-name" role="columnheader">{{ t('knowledgeBase.columnName') }}</div>
|
||||
<div class="cell cell-tag" role="columnheader">{{ t('knowledgeBase.columnTag') }}</div>
|
||||
<div class="cell cell-size" role="columnheader">{{ t('knowledgeBase.columnSize') }}</div>
|
||||
<div class="cell cell-type" role="columnheader">{{ t('knowledgeBase.columnType') }}</div>
|
||||
<div class="cell cell-status" role="columnheader">{{ t('knowledgeBase.columnStatus') }}</div>
|
||||
<div class="cell cell-time" role="columnheader">{{ t('knowledgeBase.columnUpdatedAt') }}</div>
|
||||
<div class="cell cell-actions" role="columnheader" v-if="canEdit"></div>
|
||||
</div>
|
||||
|
||||
<div class="doc-list-body">
|
||||
<div
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="doc-list-row"
|
||||
:class="{ selected: selectedIds.has(item.id), 'menu-open': moreOpen === item.id }"
|
||||
role="row"
|
||||
@click="emit('open', item)"
|
||||
>
|
||||
<div class="cell cell-check" @click.stop>
|
||||
<t-checkbox
|
||||
class="doc-list-check"
|
||||
size="small"
|
||||
:checked="selectedIds.has(item.id)"
|
||||
:title="item.file_name"
|
||||
@change="(c, ctx) => onRowCheckboxChange(item, c, ctx)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-name">
|
||||
<span class="row-file-icon-wrap">
|
||||
<t-icon :name="getFileIcon(item)" />
|
||||
</span>
|
||||
<span class="row-file-name" :title="item.file_name">{{ item.file_name }}</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cell cell-tag">
|
||||
<t-tag v-if="getTagName(item.tag_id)" size="small" variant="light-outline" class="row-tag">
|
||||
{{ getTagName(item.tag_id) }}
|
||||
</t-tag>
|
||||
<span v-else class="row-muted">--</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-size">
|
||||
<span class="row-mono">{{ formatFileSize(item.file_size) || '--' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-type">
|
||||
<span class="row-mono">{{ getTypeLabel(item) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-status">
|
||||
<template v-if="statusByRow.get(item.id) as StatusInfo | undefined">
|
||||
<t-tag
|
||||
v-if="statusByRow.get(item.id)!.label !== '--'"
|
||||
size="small"
|
||||
:theme="statusByRow.get(item.id)!.theme"
|
||||
variant="light-outline"
|
||||
class="row-status-tag"
|
||||
>
|
||||
<template v-if="statusByRow.get(item.id)!.icon" #icon>
|
||||
<t-icon
|
||||
:name="statusByRow.get(item.id)!.icon!"
|
||||
:class="{ 'icon-spin': statusByRow.get(item.id)!.spin }"
|
||||
/>
|
||||
</template>
|
||||
{{ statusByRow.get(item.id)!.label }}
|
||||
</t-tag>
|
||||
<span v-else class="row-muted">--</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-time">
|
||||
<span class="row-mono">{{ formatTime(item.updated_at) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-actions" v-if="canEdit" @click.stop>
|
||||
<t-popup
|
||||
placement="bottom-right"
|
||||
trigger="click"
|
||||
destroy-on-close
|
||||
:on-visible-change="(v: boolean) => onMoreVisible(item.id, v)"
|
||||
>
|
||||
<button class="row-more-btn" :class="{ active: moreOpen === item.id }" type="button" :aria-label="t('knowledgeBase.columnActions')">
|
||||
<t-icon name="more" size="16px" />
|
||||
</button>
|
||||
<template #content>
|
||||
<div class="row-menu">
|
||||
<div
|
||||
v-if="item.type === 'manual'"
|
||||
class="row-menu-item"
|
||||
@click.stop="handleAction('edit', item)"
|
||||
>
|
||||
<t-icon class="icon" name="edit" />
|
||||
<span>{{ t('knowledgeBase.editDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item" @click.stop="handleAction('reparse', item)">
|
||||
<t-icon class="icon" name="refresh" />
|
||||
<span>{{ t('knowledgeBase.rebuildDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item" @click.stop="handleAction('move', item)">
|
||||
<t-icon class="icon" name="swap" />
|
||||
<span>{{ t('knowledgeBase.moveDocument') }}</span>
|
||||
</div>
|
||||
<div class="row-menu-item danger" @click.stop="handleAction('delete', item)">
|
||||
<t-icon class="icon" name="delete" />
|
||||
<span>{{ t('knowledgeBase.deleteDocument') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
@keyframes doc-list-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.doc-list-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 9px;
|
||||
/* 不能用 overflow:hidden,否则表头 position:sticky 相对外层滚动区失效 */
|
||||
overflow: visible;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
animation: doc-list-fade-in 0.32s ease-out;
|
||||
}
|
||||
|
||||
.doc-list-header,
|
||||
.doc-list-row {
|
||||
display: grid;
|
||||
grid-template-columns:
|
||||
44px // checkbox
|
||||
minmax(220px, 2.4fr) // name
|
||||
minmax(100px, 0.9fr) // tag
|
||||
96px // size
|
||||
72px // type
|
||||
minmax(96px, 0.7fr) // status
|
||||
140px // updated_at
|
||||
48px; // actions
|
||||
align-items: center;
|
||||
column-gap: 0;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.doc-list-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 3;
|
||||
height: 40px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px 8px 0 0;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.doc-list-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 0 0 8px 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.doc-list-row {
|
||||
position: relative;
|
||||
min-height: 52px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-primary);
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover:not(.selected),
|
||||
&.menu-open:not(.selected) {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
&:hover .row-more-btn,
|
||||
&.menu-open .row-more-btn,
|
||||
&.selected .row-more-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding: 0 8px;
|
||||
&:first-child { padding-left: 0; }
|
||||
&:last-child { padding-right: 0; }
|
||||
}
|
||||
|
||||
.cell-check {
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.cell-name {
|
||||
gap: 10px;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
}
|
||||
|
||||
.cell-size,
|
||||
.cell-time {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.cell-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* TDesign 勾选框:去掉空白 label、与表格行对齐 */
|
||||
.doc-list-check {
|
||||
margin: 0;
|
||||
|
||||
:deep(.t-checkbox) {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__label) {
|
||||
display: none !important;
|
||||
width: 0 !important;
|
||||
min-width: 0 !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.t-checkbox__input-wrapper) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.row-file-icon-wrap {
|
||||
flex-shrink: 0;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 6px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.row-file-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.01em;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.row-tag {
|
||||
max-width: 100%;
|
||||
:deep(.t-tag__text) {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 120px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
.row-muted {
|
||||
color: var(--td-text-color-disabled, #bbb);
|
||||
}
|
||||
|
||||
.row-mono {
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 12px;
|
||||
font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.row-status-tag :deep(.t-icon) {
|
||||
margin-right: 2px;
|
||||
}
|
||||
.icon-spin {
|
||||
animation: doc-list-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes doc-list-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.row-more-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
border-radius: 5px;
|
||||
color: var(--td-text-color-secondary);
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-component-stroke);
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
opacity: 1;
|
||||
background: var(--td-component-stroke);
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.row-menu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 140px;
|
||||
gap: 2px;
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.row-menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
color: var(--td-text-color-primary);
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
transition: background-color 0.15s cubic-bezier(0.2, 0, 0, 1), transform 0.12s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--td-bg-color-container-active);
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 16px;
|
||||
color: var(--td-text-color-secondary);
|
||||
transition: color 0.15s ease;
|
||||
}
|
||||
|
||||
&:hover .icon {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.danger {
|
||||
color: var(--td-error-color-6);
|
||||
margin-top: 4px;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -3px;
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
height: 1px;
|
||||
background: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: var(--td-error-color-6);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--td-error-color-1);
|
||||
color: var(--td-error-color-6);
|
||||
|
||||
.icon {
|
||||
color: var(--td-error-color-6);
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--td-error-color-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -149,7 +149,7 @@ interface ConnectorDef {
|
||||
permissionDocUrl: string
|
||||
permissionPageUrl: string
|
||||
requiredPermissions: string[]
|
||||
fields: { key: string; labelKey: string; placeholder: string; secret?: boolean }[]
|
||||
fields: { key: string; labelKey: string; placeholder: string; secret?: boolean; optional?: boolean; hintKey?: string }[]
|
||||
}
|
||||
|
||||
const connectorDefs = computed<ConnectorDef[]>(() => [
|
||||
@@ -183,13 +183,17 @@ const connectorDefs = computed<ConnectorDef[]>(() => [
|
||||
},
|
||||
{
|
||||
type: 'yuque',
|
||||
available: false,
|
||||
docUrl: 'https://www.yuque.com/settings/tokens',
|
||||
permissionDocUrl: '',
|
||||
permissionPageUrl: '',
|
||||
requiredPermissions: [],
|
||||
available: true,
|
||||
docUrl: 'https://www.yuque.com/yuque/developer/api',
|
||||
permissionDocUrl: 'https://www.yuque.com/yuque/developer/api',
|
||||
permissionPageUrl: 'https://www.yuque.com/settings/tokens',
|
||||
requiredPermissions: [
|
||||
'repo:read',
|
||||
'doc:read',
|
||||
],
|
||||
fields: [
|
||||
{ key: 'api_token', labelKey: 'datasource.field.apiToken', placeholder: '', secret: true },
|
||||
{ key: 'base_url', labelKey: 'datasource.field.baseUrl', placeholder: 'https://www.yuque.com', optional: true, hintKey: 'datasource.field.baseUrlHint' },
|
||||
],
|
||||
},
|
||||
])
|
||||
@@ -244,6 +248,7 @@ function selectType(def: ConnectorDef) {
|
||||
async function testConnection() {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (f.optional) continue
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return
|
||||
@@ -373,6 +378,7 @@ function toggleResource(id: string) {
|
||||
function validateStep1Fields(): boolean {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (f.optional) continue
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return false
|
||||
@@ -458,6 +464,7 @@ async function handleClose() {
|
||||
const resourceTypeLabelMap: Record<string, string> = {
|
||||
wiki_space: 'datasource.resourceType.wikiSpace',
|
||||
doc_category: 'datasource.resourceType.docCategory',
|
||||
book: 'datasource.resourceType.book',
|
||||
}
|
||||
|
||||
function resourceTypeLabel(type: string): string {
|
||||
@@ -549,7 +556,7 @@ const stepTitles = computed(() => [
|
||||
</div>
|
||||
</div>
|
||||
<a :href="currentDef.permissionPageUrl" target="_blank" rel="noopener" class="ds-prereq-link">
|
||||
{{ t('datasource.prereqOpenConsole') }}
|
||||
{{ t(`datasource.prereqOpenConsole_${form.type}`, t('datasource.prereqOpenConsole')) }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -565,12 +572,16 @@ const stepTitles = computed(() => [
|
||||
</div>
|
||||
|
||||
<div v-for="field in currentDef?.fields || []" :key="field.key" class="form-item">
|
||||
<label class="form-label">{{ t(field.labelKey) }}</label>
|
||||
<label class="form-label">
|
||||
{{ t(field.labelKey) }}
|
||||
<span v-if="!field.optional" class="required-mark">*</span>
|
||||
</label>
|
||||
<t-input
|
||||
v-model="form.config.credentials[field.key]"
|
||||
:placeholder="field.placeholder"
|
||||
:type="field.secret ? 'password' : 'text'"
|
||||
/>
|
||||
<div v-if="field.hintKey" class="form-hint">{{ t(field.hintKey) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
@@ -871,7 +882,9 @@ const stepTitles = computed(() => [
|
||||
|
||||
.form-item { margin-bottom: 16px; }
|
||||
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--td-text-color-primary); }
|
||||
.required-mark { color: var(--td-error-color); margin-left: 2px; }
|
||||
.form-tip { font-size: 12px; color: var(--td-text-color-placeholder); margin: 4px 0 12px; }
|
||||
.form-hint { font-size: 12px; color: var(--td-text-color-placeholder); margin-top: 6px; line-height: 1.5; }
|
||||
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
|
||||
.test-ok { color: var(--td-success-color); font-size: 13px; display: flex; align-items: center; gap: 4px; }
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Question Generation feature -->
|
||||
<!-- Question Generation feature (only useful for RAG indexing) -->
|
||||
<template v-if="ragEnabled !== false">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.questionGeneration.label') }}</label>
|
||||
@@ -41,6 +42,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -56,6 +58,7 @@ interface QuestionGenerationConfig {
|
||||
|
||||
interface Props {
|
||||
questionGeneration?: QuestionGenerationConfig
|
||||
ragEnabled?: boolean
|
||||
allModels?: any[]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<div class="kb-multimodal-settings">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('knowledgeEditor.indexing.title') }}</h2>
|
||||
<p class="section-description">{{ $t('knowledgeEditor.indexing.description') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Hybrid Search (vector + keyword combined) -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.searchTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.searchDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="searchEnabled"
|
||||
@change="handleSearchToggle"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.wikiTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.wikiDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="modelValue.wikiEnabled"
|
||||
@change="(val: boolean) => update('wikiEnabled', val)"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki sub-settings (inline when enabled) -->
|
||||
<template v-if="modelValue.wikiEnabled">
|
||||
<slot name="wiki-settings" />
|
||||
</template>
|
||||
|
||||
<!-- Knowledge Graph -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.indexing.graphTitle') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.indexing.graphDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
:model-value="modelValue.graphEnabled"
|
||||
@change="(val: boolean) => update('graphEnabled', val)"
|
||||
size="medium"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Graph sub-settings (inline when enabled) -->
|
||||
<template v-if="modelValue.graphEnabled">
|
||||
<slot name="graph-settings" />
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
export interface IndexingStrategy {
|
||||
vectorEnabled: boolean
|
||||
keywordEnabled: boolean
|
||||
wikiEnabled: boolean
|
||||
graphEnabled: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: IndexingStrategy
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: IndexingStrategy): void
|
||||
}>()
|
||||
|
||||
// Search = vector + keyword combined (the system always uses hybrid search internally)
|
||||
const searchEnabled = computed(() => props.modelValue.vectorEnabled || props.modelValue.keywordEnabled)
|
||||
|
||||
const handleSearchToggle = (val: boolean) => {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
vectorEnabled: val,
|
||||
keywordEnabled: val,
|
||||
})
|
||||
}
|
||||
|
||||
const update = (field: keyof IndexingStrategy, value: boolean) => {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
[field]: value,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
/* NOT scoped — these classes must match the parent modal's scoped styles.
|
||||
Since slot content is rendered in the parent scope, only the wrapper
|
||||
elements defined HERE need their own styles. We replicate the same
|
||||
design tokens used by .kb-multimodal-settings in the parent. */
|
||||
</style>
|
||||
@@ -25,15 +25,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding 嵌入模型 -->
|
||||
<div class="setting-row">
|
||||
<!-- Embedding 嵌入模型 (仅 RAG 检索启用时必填) -->
|
||||
<div v-if="ragEnabled !== false" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.models.embeddingLabel') }} <span class="required">*</span></label>
|
||||
<label>{{ $t('knowledgeEditor.models.embeddingLabel') }} <span v-if="ragEnabled" class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.models.embeddingDesc') }}</p>
|
||||
<t-alert
|
||||
v-if="hasFiles"
|
||||
theme="warning"
|
||||
:message="$t('knowledgeEditor.models.embeddingLocked')"
|
||||
<t-alert
|
||||
v-if="hasFiles"
|
||||
theme="warning"
|
||||
:message="$t('knowledgeEditor.models.embeddingLocked')"
|
||||
style="margin-top: 8px;"
|
||||
/>
|
||||
</div>
|
||||
@@ -51,6 +51,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wiki 合成模型 (仅当 Wiki 启用时显示) -->
|
||||
<div v-if="wikiEnabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.wiki.synthesisModelLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.wiki.synthesisModelTip') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<ModelSelector
|
||||
model-type="KnowledgeQA"
|
||||
:selected-model-id="config.wikiSynthesisModelId"
|
||||
:all-models="allModels"
|
||||
@update:selected-model-id="handleWikiModelChange"
|
||||
@add-model="handleAddModel('knowledgeqa')"
|
||||
:placeholder="$t('knowledgeEditor.wiki.synthesisModelPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -65,11 +83,14 @@ interface ModelConfig {
|
||||
llmModelId?: string
|
||||
embeddingModelId?: string
|
||||
vllmModelId?: string
|
||||
wikiSynthesisModelId?: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
config: ModelConfig
|
||||
hasFiles: boolean
|
||||
wikiEnabled?: boolean
|
||||
ragEnabled?: boolean
|
||||
allModels?: any[]
|
||||
}
|
||||
|
||||
@@ -82,11 +103,9 @@ const emit = defineEmits<{
|
||||
const uiStore = useUIStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
// 引用各个模型选择器
|
||||
const llmSelectorRef = ref<InstanceType<typeof ModelSelector>>()
|
||||
const embeddingSelectorRef = ref<InstanceType<typeof ModelSelector>>()
|
||||
|
||||
// 处理LLM模型变化
|
||||
const handleLLMChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
@@ -94,7 +113,6 @@ const handleLLMChange = (modelId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 处理Embedding模型变化
|
||||
const handleEmbeddingChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
@@ -102,13 +120,16 @@ const handleEmbeddingChange = (modelId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 处理添加模型按钮点击
|
||||
const handleAddModel = (subSection: string) => {
|
||||
// 打开全局设置对话框,并导航到对应的模型子页面
|
||||
uiStore.openSettings('models', subSection)
|
||||
const handleWikiModelChange = (modelId: string) => {
|
||||
emit('update:config', {
|
||||
...props.config,
|
||||
wikiSynthesisModelId: modelId
|
||||
})
|
||||
}
|
||||
|
||||
// 由于使用了 allModels prop,不再需要单独刷新各个选择器
|
||||
const handleAddModel = (subSection: string) => {
|
||||
uiStore.openSettings('models', subSection)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user