refactor(frontend): 前端重构 V3
This commit is contained in:
1 parent
8d8b40812d
commit
ec97ea8787
80 files changed
+6887
-3733
No files matched your search
@@ -135,7 +135,7 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
await pendingDeleteAction();
|
||||
} catch (err) {
|
||||
console.error('[deleteConfirm]', err);
|
||||
feedback.value = String(err) || '操作失败';
|
||||
feedback.value = String(err) || t('kbWorkspace.msg.operationFailed');
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
closeDeleteConfirmDialog();
|
||||
|
||||
@@ -47,6 +47,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
selectedPathUploadHistoryJobId,
|
||||
selectedPathUploadHistoryItemKeys,
|
||||
groups,
|
||||
t,
|
||||
} = state;
|
||||
|
||||
const selectedDocument = computed(() =>
|
||||
@@ -60,7 +61,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
);
|
||||
const markdownModalTitle = computed(() => {
|
||||
const current = documents.value.find((item) => item.id === markdownDocumentId.value);
|
||||
return current ? getDocumentDisplayTitle(current) : 'Markdown 编辑器';
|
||||
return current ? getDocumentDisplayTitle(current, t) : t('kbWorkspace.markdownModal.editorTitle');
|
||||
});
|
||||
const activeGroupJobs = computed(() =>
|
||||
jobs.value.filter((item) => item.group_id === selectedGroupId.value),
|
||||
@@ -68,13 +69,13 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const getLatestJobForDocument = buildGetLatestJobForDocument(() => activeGroupJobs.value);
|
||||
const resolveWorkflowState = (doc: KbDocumentItem) =>
|
||||
getDocumentWorkflowState(doc, getLatestJobForDocument);
|
||||
getDocumentWorkflowState(doc, getLatestJobForDocument, t);
|
||||
const getWorkflowBadgesForDoc = (doc: KbDocumentItem) =>
|
||||
getWorkflowBadges(doc, getLatestJobForDocument);
|
||||
getWorkflowBadges(doc, getLatestJobForDocument, t);
|
||||
const getMarkdownUnavailableMessageForDoc = (
|
||||
doc: KbDocumentItem,
|
||||
fallback?: string | null,
|
||||
) => getMarkdownUnavailableMessage(doc, getLatestJobForDocument, fallback);
|
||||
) => getMarkdownUnavailableMessage(doc, getLatestJobForDocument, t, fallback);
|
||||
|
||||
const groupSummaryItems = computed(() => {
|
||||
const docItems = documents.value;
|
||||
@@ -86,12 +87,12 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const syncFailedCount = workflowStates.filter((item) => item.sync.code === 'failed').length;
|
||||
|
||||
return [
|
||||
{ label: '当前知识库分组', value: groupName, wide: true, clickable: false },
|
||||
{ label: '文档数量', value: String(docItems.length), wide: false, clickable: false },
|
||||
{ label: '待同步数量', value: String(pendingSyncCount), wide: false, clickable: false },
|
||||
{ label: '上传失败数量', value: String(uploadFailedCount), wide: false, clickable: uploadFailedCount > 0, failureType: 'upload' as const },
|
||||
{ label: '清洗失败数量', value: String(cleanFailedCount), wide: false, clickable: cleanFailedCount > 0, failureType: 'clean' as const },
|
||||
{ label: '同步失败数量', value: String(syncFailedCount), wide: false, clickable: syncFailedCount > 0, failureType: 'sync' as const },
|
||||
{ label: t('kbWorkspace.summary.currentGroup'), value: groupName, wide: true, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.documentCount'), value: String(docItems.length), wide: false, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.pendingSync'), value: String(pendingSyncCount), wide: false, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.uploadFailed'), value: String(uploadFailedCount), wide: false, clickable: uploadFailedCount > 0, failureType: 'upload' as const },
|
||||
{ label: t('kbWorkspace.summary.cleanFailed'), value: String(cleanFailedCount), wide: false, clickable: cleanFailedCount > 0, failureType: 'clean' as const },
|
||||
{ label: t('kbWorkspace.summary.syncFailed'), value: String(syncFailedCount), wide: false, clickable: syncFailedCount > 0, failureType: 'sync' as const },
|
||||
];
|
||||
});
|
||||
|
||||
@@ -114,8 +115,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const normalizedKeyword = keyword.trim().toLowerCase();
|
||||
if (!normalizedKeyword) return true;
|
||||
const candidates = [
|
||||
getDocumentDisplayTitle(doc),
|
||||
getDocumentDisplayDescription(doc),
|
||||
getDocumentDisplayTitle(doc, t),
|
||||
getDocumentDisplayDescription(doc, t),
|
||||
doc.title,
|
||||
doc.description,
|
||||
doc.latest_version?.source_file_name,
|
||||
@@ -125,10 +126,10 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const stageFilterTabs = computed(() => {
|
||||
const filters: Array<{ key: 'all' | 'upload' | 'clean' | 'sync'; label: string }> = [
|
||||
{ key: 'all', label: '全部' },
|
||||
{ key: 'upload', label: '上传' },
|
||||
{ key: 'clean', label: '清洗' },
|
||||
{ key: 'sync', label: '同步' },
|
||||
{ key: 'all', label: t('kbWorkspace.filters.all') },
|
||||
{ key: 'upload', label: t('kbWorkspace.filters.upload') },
|
||||
{ key: 'clean', label: t('kbWorkspace.filters.clean') },
|
||||
{ key: 'sync', label: t('kbWorkspace.filters.sync') },
|
||||
];
|
||||
return filters.map((item) => ({
|
||||
...item,
|
||||
@@ -189,8 +190,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-clean`,
|
||||
document: doc,
|
||||
stage: 'clean',
|
||||
stageLabel: '清洗失败',
|
||||
errorMessage: workflow.clean.errorMessage || workflow.primaryError || '清洗失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageCleanFailed'),
|
||||
errorMessage: workflow.clean.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageCleanFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'clean'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -200,8 +201,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-sync`,
|
||||
document: doc,
|
||||
stage: 'sync',
|
||||
stageLabel: '同步失败',
|
||||
errorMessage: workflow.sync.errorMessage || workflow.primaryError || '同步失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageSyncFailed'),
|
||||
errorMessage: workflow.sync.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageSyncFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'sync_dify'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -211,8 +212,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-upload`,
|
||||
document: doc,
|
||||
stage: 'upload',
|
||||
stageLabel: '上传失败',
|
||||
errorMessage: workflow.upload.errorMessage || workflow.primaryError || '上传失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageUploadFailed'),
|
||||
errorMessage: workflow.upload.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageUploadFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'upload'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -232,11 +233,11 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const failureModalTitle = computed(() => {
|
||||
const map = {
|
||||
upload: '上传失败数据',
|
||||
clean: '清洗失败数据',
|
||||
sync: '同步失败数据',
|
||||
upload: t('kbWorkspace.failureModal.uploadData'),
|
||||
clean: t('kbWorkspace.failureModal.cleanData'),
|
||||
sync: t('kbWorkspace.failureModal.syncData'),
|
||||
};
|
||||
return failureModalType.value ? map[failureModalType.value] : '失败数据';
|
||||
return failureModalType.value ? map[failureModalType.value] : t('kbWorkspace.failureModal.generic');
|
||||
});
|
||||
|
||||
const documentById = computed(() =>
|
||||
@@ -273,7 +274,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
);
|
||||
|
||||
const selectedPathUploadHistoryItems = computed(() =>
|
||||
getPathUploadJobItems(selectedPathUploadHistoryJob.value),
|
||||
getPathUploadJobItems(selectedPathUploadHistoryJob.value, t),
|
||||
);
|
||||
|
||||
const selectedPathUploadHistorySelectedItems = computed(() => {
|
||||
@@ -290,7 +291,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
if (item.status === 'failed') {
|
||||
return {
|
||||
normalized: 'failed',
|
||||
label: '失败',
|
||||
label: t('kbWorkspace.status.failed'),
|
||||
className: getStatusBadgeClass('failed'),
|
||||
};
|
||||
}
|
||||
@@ -299,27 +300,27 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const latestStatus = String(doc?.latest_version?.status || doc?.status || '').toLowerCase();
|
||||
|
||||
if (latestStatus === 'processing') {
|
||||
return { normalized: 'processing', label: '清洗中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'processing', label: t('kbWorkspace.status.cleaning'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
if (['cleaned', 'ready'].includes(latestStatus)) {
|
||||
return { normalized: latestStatus, label: '已清洗', className: getStatusBadgeClass(latestStatus) };
|
||||
return { normalized: latestStatus, label: t('kbWorkspace.status.cleaned'), className: getStatusBadgeClass(latestStatus) };
|
||||
}
|
||||
if (latestStatus === 'syncing') {
|
||||
return { normalized: 'syncing', label: '同步中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'syncing', label: t('kbWorkspace.status.syncing'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
if (latestStatus === 'synced') {
|
||||
return { normalized: 'synced', label: '已同步', className: getStatusBadgeClass('synced') };
|
||||
return { normalized: 'synced', label: t('kbWorkspace.status.synced'), className: getStatusBadgeClass('synced') };
|
||||
}
|
||||
if (latestStatus === 'uploaded') {
|
||||
return { normalized: 'uploaded', label: '待清洗', className: getStatusBadgeClass('uploaded') };
|
||||
return { normalized: 'uploaded', label: t('kbWorkspace.status.pendingClean'), className: getStatusBadgeClass('uploaded') };
|
||||
}
|
||||
if (item.status === 'success' || item.documentId) {
|
||||
return { normalized: 'success', label: '已上传', className: getStatusBadgeClass('success') };
|
||||
return { normalized: 'success', label: t('kbWorkspace.status.uploaded'), className: getStatusBadgeClass('success') };
|
||||
}
|
||||
if (item.status === 'uploading') {
|
||||
return { normalized: 'uploading', label: '上传中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'uploading', label: t('kbWorkspace.status.uploading'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
return { normalized: 'queued', label: '待上传', className: getStatusBadgeClass('queued') };
|
||||
return { normalized: 'queued', label: t('kbWorkspace.status.draft'), className: getStatusBadgeClass('queued') };
|
||||
};
|
||||
|
||||
const pathUploadSummary = computed(() => {
|
||||
|
||||
@@ -48,6 +48,8 @@ export function useKbWorkspaceData(
|
||||
selectedPathUploadHistoryJobId,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
kbJobPollingActive,
|
||||
latestPathUploadJob,
|
||||
@@ -63,7 +65,7 @@ export function useKbWorkspaceData(
|
||||
try {
|
||||
const result = await getKbGroupsSafe();
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载知识库分组失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ export function useKbWorkspaceData(
|
||||
}
|
||||
const result = await getKbGroupFilesSafe(groupId);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载文档列表失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadDocumentsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -126,13 +128,13 @@ export function useKbWorkspaceData(
|
||||
const hadActiveKbJobs = kbJobPollingActive.value;
|
||||
const result = await getKbJobsSafe();
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载任务列表失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadJobsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
jobs.value = result.data;
|
||||
applyPathUploadJob(latestPathUploadJob.value);
|
||||
if (latestPathUploadJob.value && getPathUploadJobSummary(latestPathUploadJob.value).failed > 0) {
|
||||
if (latestPathUploadJob.value && getPathUploadJobSummary(latestPathUploadJob.value, t).failed > 0) {
|
||||
showPathUploadDetails.value = true;
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -48,6 +48,8 @@ export function useKbWorkspaceDocuments(
|
||||
openDeleteConfirmDialog,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
filteredDocuments,
|
||||
selectedDocuments,
|
||||
@@ -86,10 +88,10 @@ export function useKbWorkspaceDocuments(
|
||||
};
|
||||
|
||||
const handleDeleteDocument = async (doc: KbDocumentItem) => {
|
||||
openDeleteConfirmDialog(`确认删除文档「${getDocumentDisplayTitle(doc)}」吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.deleteDocumentConfirm', { name: getDocumentDisplayTitle(doc, t) }), async () => {
|
||||
const result = await deleteKbDocument(doc.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '删除文档失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.deleteDocumentFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +100,7 @@ export function useKbWorkspaceDocuments(
|
||||
selectedDocumentId.value = null;
|
||||
showRecordModal.value = false;
|
||||
}
|
||||
feedback.value = '文档已删除';
|
||||
feedback.value = t('kbWorkspace.msg.documentDeleted');
|
||||
feedbackType.value = 'success';
|
||||
await Promise.all([loadGroups(), loadDocuments(selectedGroupId.value), loadJobs()]);
|
||||
selectedDocumentVersions.value = [];
|
||||
@@ -108,7 +110,7 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchSync = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要批量同步的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToSync');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -123,10 +125,12 @@ export function useKbWorkspaceDocuments(
|
||||
const successCount = results.filter(({ result }) => result.ok).length;
|
||||
const failResults = results.filter(({ result }) => !result.ok);
|
||||
const failCount = failResults.length;
|
||||
const errors = failResults.map(({ doc, result }) => `${getDocumentDisplayTitle(doc)}: ${result.error || '同步失败'}`);
|
||||
const errors = failResults.map(({ doc, result }) =>
|
||||
`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.failureModal.stageSyncFailed')}`,
|
||||
);
|
||||
feedback.value = failCount
|
||||
? `批量同步任务已提交:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量同步任务已提交:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchSyncResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchSyncSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
if (successCount > 0) {
|
||||
startPathUploadPolling();
|
||||
@@ -139,12 +143,12 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchClean = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要清洗的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToClean');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!selectedCleanableDocuments.value.length) {
|
||||
feedback.value = '当前所选文档没有可重新清洗的项';
|
||||
feedback.value = t('kbWorkspace.msg.noDocumentsToClean');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -159,10 +163,12 @@ export function useKbWorkspaceDocuments(
|
||||
const successCount = results.filter(({ result }) => result.ok).length;
|
||||
const failResults = results.filter(({ result }) => !result.ok);
|
||||
const failCount = failResults.length;
|
||||
const errors = failResults.map(({ doc, result }) => `${getDocumentDisplayTitle(doc)}: ${result.error || '提交清洗失败'}`);
|
||||
const errors = failResults.map(({ doc, result }) =>
|
||||
`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.failureModal.stageCleanFailed')}`,
|
||||
);
|
||||
feedback.value = failCount
|
||||
? `批量清洗任务已提交:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量清洗任务已提交:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchCleanResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchCleanSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
if (successCount > 0) {
|
||||
startPathUploadPolling();
|
||||
@@ -175,12 +181,12 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要批量删除的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToDelete');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
openDeleteConfirmDialog(
|
||||
`确认批量删除已选中的 ${selectedDocuments.value.length} 条文档吗?会同步删除 Dify 对应文档。`,
|
||||
t('kbWorkspace.msg.batchDeleteDocumentsConfirm', { count: selectedDocuments.value.length }),
|
||||
async () => {
|
||||
batchSubmitting.value = true;
|
||||
let successCount = 0;
|
||||
@@ -193,12 +199,12 @@ export function useKbWorkspaceDocuments(
|
||||
successCount += 1;
|
||||
} else {
|
||||
failCount += 1;
|
||||
errors.push(`${getDocumentDisplayTitle(doc)}: ${result.error || '删除失败'}`);
|
||||
errors.push(`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.msg.deleteDocumentFailed')}`);
|
||||
}
|
||||
}
|
||||
feedback.value = failCount
|
||||
? `批量删除完成:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量删除完成:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchDeleteResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchDeleteSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
selectedDocumentIds.value = [];
|
||||
await Promise.all([loadGroups(), loadDocuments(selectedGroupId.value), loadJobs()]);
|
||||
@@ -223,28 +229,30 @@ export function useKbWorkspaceDocuments(
|
||||
try {
|
||||
if (action === 'submit') {
|
||||
triggerUploadForDocument(item.document.id);
|
||||
feedback.value = `请重新为「${getDocumentDisplayTitle(item.document)}」选择文件后提交`;
|
||||
feedback.value = t('kbWorkspace.msg.reselectFile', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
return;
|
||||
}
|
||||
if (action === 'clean') {
|
||||
const result = await submitKbDocumentClean(item.document.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '重新清洗失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.recleanFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.message || `已重新提交清洗:${getDocumentDisplayTitle(item.document)}`;
|
||||
feedback.value = result.message || t('kbWorkspace.msg.recleanSubmitted', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
} else {
|
||||
const result = await syncKbDocumentToDify(item.document.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error ? `重新同步失败:${result.error}` : '重新同步失败';
|
||||
feedback.value = result.error
|
||||
? t('kbWorkspace.msg.resyncFailed', { detail: result.error })
|
||||
: t('kbWorkspace.failureModal.stageSyncFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.job?.message || `已重新提交同步:${getDocumentDisplayTitle(item.document)}`;
|
||||
feedback.value = result.job?.message || t('kbWorkspace.msg.resyncSubmitted', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
}
|
||||
@@ -270,7 +278,7 @@ export function useKbWorkspaceDocuments(
|
||||
}
|
||||
|
||||
isSubmitting.value = true;
|
||||
feedback.value = '开始处理文件...';
|
||||
feedback.value = t('kbWorkspace.msg.processingFile');
|
||||
feedbackType.value = 'success';
|
||||
|
||||
if (activeUploadDocumentId.value) {
|
||||
@@ -278,10 +286,10 @@ export function useKbWorkspaceDocuments(
|
||||
if (!file) return;
|
||||
const result = await uploadKbDocumentVersion(activeUploadDocumentId.value, file);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '文件上传失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.uploadFailed');
|
||||
feedbackType.value = 'error';
|
||||
} else {
|
||||
feedback.value = result.message || `版本文件「${file.name}」上传成功,清洗已排队`;
|
||||
feedback.value = result.message || t('kbWorkspace.msg.versionUploaded', { file: file.name });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
}
|
||||
@@ -296,7 +304,11 @@ export function useKbWorkspaceDocuments(
|
||||
for (let i = 0; i < fileArray.length; i++) {
|
||||
const file = fileArray[i];
|
||||
if (!file) continue;
|
||||
feedback.value = `正在上传 ${i + 1}/${fileArray.length}: ${file.name}`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadingProgress', {
|
||||
current: i + 1,
|
||||
total: fileArray.length,
|
||||
file: file.name,
|
||||
});
|
||||
|
||||
const createResult = await createKbDocument(selectedGroupId.value, {
|
||||
title: file.name,
|
||||
@@ -305,18 +317,21 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
if (!createResult.ok || !createResult.document) {
|
||||
failCount++;
|
||||
errors.push(`${file.name}: ${normalizeDuplicateDocumentError(createResult.error || '创建文档失败')}`);
|
||||
const createError = createResult.error
|
||||
? normalizeDuplicateDocumentError(createResult.error, t)
|
||||
: t('kbWorkspace.msg.createDocumentFailed');
|
||||
errors.push(`${file.name}: ${createError}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const uploadResult = await uploadKbDocumentVersion(createResult.document.id, file);
|
||||
if (!uploadResult.ok) {
|
||||
failCount++;
|
||||
const uploadError = uploadResult.error || '上传文档版本失败';
|
||||
const uploadError = uploadResult.error || t('kbWorkspace.msg.uploadVersionFailed');
|
||||
errors.push(`${file.name}: ${uploadError}`);
|
||||
const cleanupResult = await deleteKbDocument(createResult.document.id);
|
||||
if (!cleanupResult.ok) {
|
||||
errors.push(`${file.name}: 上传失败后未能自动清理空文档(${cleanupResult.error || '删除失败'})`);
|
||||
errors.push(`${file.name}: ${t('kbWorkspace.msg.uploadCleanupFailed', { detail: cleanupResult.error || t('kbWorkspace.msg.deleteDocumentFailed') })}`);
|
||||
}
|
||||
} else {
|
||||
successCount++;
|
||||
@@ -324,10 +339,14 @@ export function useKbWorkspaceDocuments(
|
||||
}
|
||||
|
||||
if (failCount > 0) {
|
||||
feedback.value = `上传完成:成功 ${successCount} 个,失败 ${failCount} 个。${errors[0] || ''}`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadSummary', {
|
||||
success: successCount,
|
||||
fail: failCount,
|
||||
detail: errors[0] || '',
|
||||
});
|
||||
feedbackType.value = successCount > 0 ? 'success' : 'error';
|
||||
} else {
|
||||
feedback.value = `成功上传 ${successCount} 个文件,清洗任务已排队`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadAllSuccess', { count: successCount });
|
||||
feedbackType.value = 'success';
|
||||
}
|
||||
if (successCount > 0) {
|
||||
@@ -355,14 +374,16 @@ export function useKbWorkspaceDocuments(
|
||||
syncingDocumentId.value = null;
|
||||
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error ? `同步到 Dify 失败:${result.error}` : '同步到 Dify 失败';
|
||||
feedback.value = result.error
|
||||
? t('kbWorkspace.msg.syncDifyFailed', { detail: result.error })
|
||||
: t('kbWorkspace.msg.syncDifyFailedGeneric');
|
||||
feedbackType.value = 'error';
|
||||
await loadDocuments(selectedGroupId.value, { silent: true });
|
||||
await loadJobs();
|
||||
return;
|
||||
}
|
||||
|
||||
feedback.value = result.job?.message || '同步任务已提交,等待后台处理';
|
||||
feedback.value = result.job?.message || t('kbWorkspace.msg.syncSubmitted');
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
await loadDocuments(selectedGroupId.value, { silent: true });
|
||||
|
||||
@@ -46,6 +46,7 @@ export function useKbWorkspaceModals(
|
||||
selectedGroupId,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
const { getMarkdownUnavailableMessageForDoc } = computed;
|
||||
const { loadDocumentVersions, loadSourceInfoVersions, loadDocuments, loadJobs } = data;
|
||||
|
||||
@@ -78,7 +79,7 @@ export function useKbWorkspaceModals(
|
||||
const result = await getKbDocumentVersionSourceFile(version.id);
|
||||
openingSourceVersionId.value = null;
|
||||
if (!result.ok || !result.blob) {
|
||||
feedback.value = result.error || '读取原始文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.readSourceFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -112,7 +113,7 @@ export function useKbWorkspaceModals(
|
||||
markdownKind.value = payload.kind;
|
||||
markdownVersionLabel.value = payload.version
|
||||
? `v${payload.version.version_no} · ${payload.version.source_file_name}`
|
||||
: '暂无版本';
|
||||
: t('kbWorkspace.msg.noVersion');
|
||||
};
|
||||
|
||||
const openMarkdownEditor = async (doc: KbDocumentItem) => {
|
||||
@@ -127,7 +128,10 @@ export function useKbWorkspaceModals(
|
||||
const result = await getKbDocumentMarkdown(doc.id);
|
||||
isMarkdownLoading.value = false;
|
||||
if (!result.ok || !result.data) {
|
||||
markdownError.value = getMarkdownUnavailableMessageForDoc(doc, result.error || '读取清洗后的 Markdown 失败');
|
||||
markdownError.value = getMarkdownUnavailableMessageForDoc(
|
||||
doc,
|
||||
result.error || t('kbWorkspace.msg.readMarkdownFailed'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
applyMarkdownPayload(result.data);
|
||||
@@ -156,13 +160,13 @@ export function useKbWorkspaceModals(
|
||||
if (!result.ok || !result.data) {
|
||||
const currentDoc = documents.value.find((item) => item.id === markdownDocumentId.value) || null;
|
||||
markdownError.value = currentDoc
|
||||
? getMarkdownUnavailableMessageForDoc(currentDoc, result.error || '保存 Markdown 失败')
|
||||
: (result.error || '保存 Markdown 失败');
|
||||
? getMarkdownUnavailableMessageForDoc(currentDoc, result.error || t('kbWorkspace.msg.saveMarkdownFailed'))
|
||||
: (result.error || t('kbWorkspace.msg.saveMarkdownFailed'));
|
||||
return;
|
||||
}
|
||||
|
||||
applyMarkdownPayload(result.data);
|
||||
feedback.value = '清洗后的 Markdown 已保存';
|
||||
feedback.value = t('kbWorkspace.msg.markdownSaved');
|
||||
feedbackType.value = 'success';
|
||||
await loadDocuments(selectedGroupId.value);
|
||||
await loadJobs();
|
||||
|
||||
@@ -50,6 +50,8 @@ export function useKbWorkspacePathUpload(
|
||||
openDeleteConfirmDialog,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
pathUploadRunning,
|
||||
kbJobPollingActive,
|
||||
@@ -77,7 +79,12 @@ export function useKbWorkspacePathUpload(
|
||||
const updatePathUploadFeedback = () => {
|
||||
const summary = pathUploadSummary.value;
|
||||
if (!pathUploadTask.value.total) return;
|
||||
feedback.value = `路径上传进度:总计 ${summary.total} 条,待上传 ${summary.pending} 条,已上传 ${summary.uploaded} 条,失败 ${summary.failed} 条`;
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadProgress', {
|
||||
total: summary.total,
|
||||
pending: summary.pending,
|
||||
uploaded: summary.uploaded,
|
||||
failed: summary.failed,
|
||||
});
|
||||
feedbackType.value = summary.failed > 0 ? 'error' : 'success';
|
||||
};
|
||||
|
||||
@@ -102,9 +109,9 @@ export function useKbWorkspacePathUpload(
|
||||
const items = Array.isArray(payload.files)
|
||||
? payload.files.map((item: Record<string, unknown>, index: number) => ({
|
||||
key: String(item.relative_path || item.original_name || index),
|
||||
title: String(item.original_name || item.relative_path || `文件${index + 1}`),
|
||||
title: String(item.original_name || item.relative_path || t('kbWorkspace.errors.fileFallback', { index: index + 1 })),
|
||||
displayPath: String(item.relative_path || item.original_name || ''),
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || '本地目录',
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || t('kbWorkspace.errors.localFolder'),
|
||||
status: (['queued', 'uploading', 'success', 'failed'].includes(String(item.status)) ? item.status : 'queued') as PathUploadStatus,
|
||||
error: item.error as string | undefined,
|
||||
documentId: item.document_id as number | undefined,
|
||||
@@ -148,7 +155,7 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const openPathUploadModal = () => {
|
||||
if (pathUploadRunning.value) {
|
||||
feedback.value = '有文件正在上传请稍等再试~';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadBusy');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -224,17 +231,17 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const handleConfirmPathUpload = async () => {
|
||||
if (pathUploadRunning.value) {
|
||||
feedback.value = '有文件正在上传请稍等再试~';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadBusy');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!selectedGroupId.value) {
|
||||
feedback.value = '请先选择知识库分组';
|
||||
feedback.value = t('kbWorkspace.msg.selectGroupFirst');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!pathUploadSelectedFiles.value.length) {
|
||||
feedback.value = '请先选择至少一个本地目录或文件';
|
||||
feedback.value = t('kbWorkspace.msg.selectPathFiles');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -249,13 +256,13 @@ export function useKbWorkspacePathUpload(
|
||||
})),
|
||||
});
|
||||
if (!createResult.ok || !createResult.job) {
|
||||
feedback.value = createResult.error || '创建上传路径任务失败';
|
||||
feedback.value = createResult.error || t('kbWorkspace.msg.createPathJobFailed');
|
||||
feedbackType.value = 'error';
|
||||
isPathUploadStaging.value = false;
|
||||
return;
|
||||
}
|
||||
const createdJob = createResult.job;
|
||||
const existingJobItems = getPathUploadJobItems(createdJob);
|
||||
const existingJobItems = getPathUploadJobItems(createdJob, t);
|
||||
const existingItemMap = new Map(existingJobItems.map((item) => [item.displayPath, item]));
|
||||
const selectedPathSet = new Set(pathUploadSelectedFiles.value.map((item) => item.displayPath));
|
||||
const pendingFiles = pathUploadSelectedFiles.value.filter((item) => {
|
||||
@@ -302,7 +309,9 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const stageResult = await uploadKbPathJobFile(createdJob.id, item.file, item.displayPath);
|
||||
if (!stageResult.ok) {
|
||||
const errorMessage = normalizeDuplicateDocumentError(stageResult.error || '路径文件暂存失败');
|
||||
const errorMessage = stageResult.error
|
||||
? normalizeDuplicateDocumentError(stageResult.error, t)
|
||||
: t('kbWorkspace.msg.pathStageFailed');
|
||||
const failedResult = await markKbPathJobFileFailed(createdJob.id, {
|
||||
relative_path: item.displayPath,
|
||||
original_name: item.file.name,
|
||||
@@ -345,7 +354,7 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
isPathUploadStaging.value = false;
|
||||
pathUploadTask.value.currentFile = '';
|
||||
feedback.value = '路径文件已逐个上传并提交清洗';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadDone');
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
resetPathUploadDraft();
|
||||
@@ -354,14 +363,16 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const handleDeletePathUploadItem = async (job: KbJob | null, item: PathUploadTaskItem) => {
|
||||
if (!job) return;
|
||||
openDeleteConfirmDialog(`确认删除路径文件「${item.displayPath || item.title}」吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.deletePathFileConfirm', { path: item.displayPath || item.title }), async () => {
|
||||
const result = await deleteKbPathJobFile(job.id, item.displayPath);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '删除路径上传文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.deletePathFileFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.document_deleted ? '已删除路径记录,并同步删除对应文档' : '已删除路径记录';
|
||||
feedback.value = result.document_deleted
|
||||
? t('kbWorkspace.msg.pathRecordDeletedWithDoc')
|
||||
: t('kbWorkspace.msg.pathRecordDeleted');
|
||||
feedbackType.value = 'success';
|
||||
if (pathUploadTask.value.items.length <= 1) {
|
||||
showPathUploadDetails.value = false;
|
||||
@@ -374,11 +385,11 @@ export function useKbWorkspacePathUpload(
|
||||
const job = selectedPathUploadHistoryJob.value;
|
||||
const items = selectedPathUploadHistorySelectedItems.value;
|
||||
if (!job || !items.length) {
|
||||
feedback.value = '请先选择要删除的文件';
|
||||
feedback.value = t('kbWorkspace.msg.selectPathFilesToDelete');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
openDeleteConfirmDialog(`确认批量删除已选中的 ${items.length} 条路径文件吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.batchDeletePathConfirm', { count: items.length }), async () => {
|
||||
deletingPathUploadBatch.value = true;
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
@@ -391,11 +402,11 @@ export function useKbWorkspacePathUpload(
|
||||
continue;
|
||||
}
|
||||
failCount += 1;
|
||||
errors.push(`${item.displayPath}: ${result.error || '删除失败'}`);
|
||||
errors.push(`${item.displayPath}: ${result.error || t('kbWorkspace.msg.deleteDocumentFailed')}`);
|
||||
}
|
||||
feedback.value = failCount
|
||||
? `批量删除完成:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量删除完成:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchDeletePathResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchDeletePathSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
selectedPathUploadHistoryItemKeys.value = [];
|
||||
await Promise.all([
|
||||
@@ -419,13 +430,15 @@ export function useKbWorkspacePathUpload(
|
||||
const result = await retryFailedKbPathUploadJob(job.id, relativePaths?.length ? { relative_paths: relativePaths } : {});
|
||||
retryingPathUploadKey.value = '';
|
||||
if (!result.ok || !result.job) {
|
||||
feedback.value = result.error || '重试失败文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.retryPathFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
applyPathUploadJob(result.job);
|
||||
startPathUploadPolling();
|
||||
feedback.value = relativePaths?.length === 1 ? '已重新提交该失败文件' : '已重新提交失败文件';
|
||||
feedback.value = relativePaths?.length === 1
|
||||
? t('kbWorkspace.msg.retryPathOne')
|
||||
: t('kbWorkspace.msg.retryPathAll');
|
||||
feedbackType.value = 'success';
|
||||
await bridge.refreshWorkflowStatusOnly();
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ import { useKbWorkspaceData } from './kb-workspace/useKbWorkspaceData';
|
||||
import { useKbWorkspaceDocuments } from './kb-workspace/useKbWorkspaceDocuments';
|
||||
import { useKbWorkspaceModals } from './kb-workspace/useKbWorkspaceModals';
|
||||
import { useKbWorkspacePathUpload } from './kb-workspace/useKbWorkspacePathUpload';
|
||||
import type { KbDocumentItem } from '../api/kb.api';
|
||||
|
||||
export interface UseKbWorkspaceOptions {
|
||||
embedded?: boolean;
|
||||
@@ -108,7 +109,7 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
});
|
||||
|
||||
watch(selectedPathUploadHistoryJob, (job) => {
|
||||
const validKeys = new Set(getPathUploadJobItems(job).map((item) => item.key));
|
||||
const validKeys = new Set(getPathUploadJobItems(job, t).map((item) => item.key));
|
||||
selectedPathUploadHistoryItemKeys.value = selectedPathUploadHistoryItemKeys.value.filter((key) => validKeys.has(key));
|
||||
if (!job) {
|
||||
selectedPathUploadHistoryItemKeys.value = [];
|
||||
@@ -128,6 +129,37 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
pathUpload.stopPathUploadPollTimer();
|
||||
});
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const batchActionLabel = (action: 'clean' | 'sync' | 'delete', submitting: boolean, count: number) => {
|
||||
if (submitting) return t('kbWorkspace.common.processing');
|
||||
const keys = {
|
||||
clean: ['batchClean', 'batchCleanCount'],
|
||||
sync: ['batchSync', 'batchSyncCount'],
|
||||
delete: ['batchDelete', 'batchDeleteCount'],
|
||||
} as const;
|
||||
const [base, withCount] = keys[action];
|
||||
return count > 0
|
||||
? t(`kbWorkspace.documents.${withCount}`, { count })
|
||||
: t(`kbWorkspace.documents.${base}`);
|
||||
};
|
||||
|
||||
const pathUploadBatchDeleteLabel = (submitting: boolean, count: number) => {
|
||||
if (submitting) return t('kbWorkspace.pathUpload.deleting');
|
||||
return count > 0
|
||||
? t('kbWorkspace.pathUpload.batchDeleteCount', { count })
|
||||
: t('kbWorkspace.pathUpload.batchDelete');
|
||||
};
|
||||
|
||||
const documentEmptyMessage = (documentsLength: number, hasKeyword: boolean) => {
|
||||
if (documentsLength === 0) return t('kbWorkspace.documents.emptyNoDocs');
|
||||
if (hasKeyword) return t('kbWorkspace.documents.emptyNoSearchMatch');
|
||||
return t('kbWorkspace.documents.emptyNoFilterMatch');
|
||||
};
|
||||
|
||||
const documentDisplayName = (doc: KbDocumentItem | null | undefined, id: number | null) =>
|
||||
doc ? getDocumentDisplayTitle(doc, t) : t('kbWorkspace.documents.documentFallback', { id });
|
||||
|
||||
// reactive 便于模板以 kb.xxx 统一访问,ref/computed 在属性读取时自动解包
|
||||
return reactive({
|
||||
...state,
|
||||
@@ -140,17 +172,22 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
getDocumentWorkflowState: computed.resolveWorkflowState,
|
||||
formatDateTime,
|
||||
formatFileSize,
|
||||
getDocumentDisplayTitle,
|
||||
getDocumentDisplayDescription,
|
||||
getStatusLabel,
|
||||
getDocumentDisplayTitle: (doc: KbDocumentItem) => getDocumentDisplayTitle(doc, t),
|
||||
getDocumentDisplayDescription: (doc: KbDocumentItem) => getDocumentDisplayDescription(doc, t),
|
||||
getStatusLabel: (status: string | null | undefined) => getStatusLabel(status, t),
|
||||
getStatusBadgeClass,
|
||||
getPathUploadJobItems,
|
||||
hasRetryablePathUploadFailure,
|
||||
getPathUploadJobSummary,
|
||||
getPathUploadJobItems: (job: Parameters<typeof getPathUploadJobItems>[0]) => getPathUploadJobItems(job, t),
|
||||
hasRetryablePathUploadFailure: (job: Parameters<typeof hasRetryablePathUploadFailure>[0]) =>
|
||||
hasRetryablePathUploadFailure(job, t),
|
||||
getPathUploadJobSummary: (job: Parameters<typeof getPathUploadJobSummary>[0]) => getPathUploadJobSummary(job, t),
|
||||
DOCUMENT_PAGE_SIZE_OPTIONS,
|
||||
FAILURE_PAGE_SIZE,
|
||||
PATH_UPLOAD_BATCH_SIZE,
|
||||
PATH_UPLOAD_BATCH_INTERVAL_MS,
|
||||
PATH_UPLOAD_CONCURRENCY,
|
||||
batchActionLabel,
|
||||
pathUploadBatchDeleteLabel,
|
||||
documentEmptyMessage,
|
||||
documentDisplayName,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user