feat(knowledge): enhance FAQ export functionality

- Updated the exportFAQEntries function to support exporting FAQ entries in both CSV and JSON formats.
- Modified the frontend to include options for selecting the export format.
- Enhanced localization files to reflect the new export options in English, Russian, and Chinese.
- Implemented new tests to validate the export functionality for both formats.

This commit improves the flexibility of FAQ exports, allowing users to choose their preferred format for better integration with other tools.
This commit is contained in:
wizardchen
2026-07-22 20:57:31 +08:00
committed by lyingbug
parent 135033e6df
commit b6a3b347da
18 changed files with 1041 additions and 137 deletions
+5 -4
View File
@@ -445,10 +445,11 @@ export function searchFAQEntries(
return post(`/api/v1/knowledge-bases/${kbId}/faq/search`, data);
}
// Export FAQ entries as CSV file
export async function exportFAQEntries(kbId: string): Promise<Blob> {
const response = await getDown(`/api/v1/knowledge-bases/${kbId}/faq/entries/export`);
return response as unknown as Blob;
// Export FAQ entries as CSV or JSON file
export async function exportFAQEntries(kbId: string, format: 'csv' | 'json' = 'csv'): Promise<Blob> {
const suffix = format === 'json' ? '?format=json' : ''
const response = await getDown(`/api/v1/knowledge-bases/${kbId}/faq/entries/export${suffix}`)
return response as unknown as Blob
}
// FAQ Import Progress API
+3 -1
View File
@@ -2992,7 +2992,9 @@ export default {
downloadExampleExcel: 'Download Excel Example',
},
faqExport: {
exportButton: 'Export CSV',
exportButton: 'Export',
exportCSV: 'Export CSV',
exportJSON: 'Export JSON',
exportSuccess: 'Export successful',
exportFailed: 'Export failed',
},
+3 -1
View File
@@ -3689,7 +3689,9 @@ export default {
downloadExampleExcel: 'Скачать пример Excel'
},
faqExport: {
exportButton: 'Экспорт CSV',
exportButton: 'Экспорт',
exportCSV: 'Экспорт CSV',
exportJSON: 'Экспорт JSON',
exportSuccess: 'Экспорт успешен',
exportFailed: 'Ошибка экспорта'
},
+3 -1
View File
@@ -4281,7 +4281,9 @@ export default {
downloadExampleExcel: "下载 Excel 示例",
},
faqExport: {
exportButton: "导出 CSV",
exportButton: "导出",
exportCSV: "导出 CSV",
exportJSON: "导出 JSON",
exportSuccess: "导出成功",
exportFailed: "导出失败",
},
@@ -238,12 +238,15 @@
</t-tooltip>
</template>
<!-- 导出 -->
<t-tooltip :content="$t('knowledgeEditor.faqExport.exportButton')" placement="top">
<t-button variant="text" theme="default" class="content-bar-icon-btn" size="small"
@click="handleFaqAction({ value: 'export' })">
<template #icon><t-icon name="download" size="16px" /></template>
</t-button>
</t-tooltip>
<t-dropdown :options="faqExportOptions" trigger="click" placement="bottom-right"
@click="handleFaqAction">
<t-tooltip :content="$t('knowledgeEditor.faqExport.exportButton')" placement="top">
<t-button variant="text" theme="default" class="content-bar-icon-btn" size="small"
:loading="exportLoading">
<template #icon><t-icon name="download" size="16px" /></template>
</t-button>
</t-tooltip>
</t-dropdown>
<!-- 检索 -->
<t-tooltip :content="$t('knowledgeEditor.faq.searchTest')" placement="top">
<t-button variant="text" theme="default" class="content-bar-icon-btn" size="small"
@@ -998,6 +1001,11 @@ const canManage = computed(() => {
return orgStore.canManageKB(props.kbId, false)
})
const faqExportOptions = computed(() => [
{ content: t('knowledgeEditor.faqExport.exportCSV'), value: 'export_csv' },
{ content: t('knowledgeEditor.faqExport.exportJSON'), value: 'export_json' },
])
// FAQ 操作:新建组(新建条目 + 导入)
const faqCreateOptions = computed(() => {
if (!canEdit.value) return []
@@ -1019,6 +1027,12 @@ const handleFaqAction = (data: { value: string }) => {
case 'search':
searchDrawerVisible.value = true
break
case 'export_csv':
handleExportCSV()
break
case 'export_json':
handleExportJSON()
break
case 'export':
handleExportCSV()
break
@@ -2647,9 +2661,19 @@ const downloadExcelExample = () => {
XLSX.writeFile(workbook, 'faq_example.xlsx')
}
// 导出 FAQ 数据为 CSV
// 导出 FAQ 数据
const exportLoading = ref(false)
const handleExportCSV = async () => {
const downloadExportBlob = (blob: Blob, ext: 'csv' | 'json') => {
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `faq_export_${new Date().toISOString().slice(0, 10)}.${ext}`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
const handleExportFAQ = async (format: 'csv' | 'json') => {
if (!props.kbId) {
MessagePlugin.warning(t('knowledgeBase.selectKnowledgeBase'))
return
@@ -2657,15 +2681,8 @@ const handleExportCSV = async () => {
exportLoading.value = true
try {
const blob = await exportFAQEntries(props.kbId)
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `faq_export_${new Date().toISOString().slice(0, 10)}.csv`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
const blob = await exportFAQEntries(props.kbId, format)
downloadExportBlob(blob, format)
MessagePlugin.success(t('knowledgeEditor.faqExport.exportSuccess'))
} catch (error: any) {
console.error('Export failed:', error)
@@ -2674,6 +2691,8 @@ const handleExportCSV = async () => {
exportLoading.value = false
}
}
const handleExportCSV = () => handleExportFAQ('csv')
const handleExportJSON = () => handleExportFAQ('json')
watch(
() => props.kbId,