Skip to content

Commit 554db19

Browse files
feat: document export
1 parent 801002d commit 554db19

42 files changed

Lines changed: 366 additions & 230 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ui/src/api/API_README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ API 枚举与类型统一在 `src/api` 范围内管理,相关规则由本文
311311
- GET 文件导出使用 `getExportFile`;需要通过 POST 同时传递查询参数和可选请求体的 Excel 导出
312312
使用 `postExportExcel`;Skill 压缩包等指定请求方法的文件下载使用 `downloadRequest`。请求层统一
313313
获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器下载;业务 API 只需传入接口地址及业务参数。
314+
`downloadRequest` 的第五个参数可指定回退文件名,缺省为 `download`;服务端文件名始终优先。
314315
- 业务代码通过 `api.method().then(...)` 处理接口成功后的状态变化;通用接口错误由请求层统一
315316
提示,不在调用处重复使用 `try/catch` 或 `.catch()` 提示相同错误。只有业务降级、状态恢复等
316317
非提示类失败处理可以按需保留失败分支。
@@ -520,6 +521,11 @@ System 接口由资源管理服务提供;本地开源后端没有对应扩展
520521
任务取消、生成问题、迁移、同步、导出、原文件下载/替换及标签关联。
521522
批量任务沿用 v2 的 `id_list` / `state_list`;生成问题使用 `document_id_list`,
522523
添加标签使用 `document_ids` / `tag_ids`,迁移和批量导出直接提交文档 ID 数组。
524+
文档导出分别提供四个接口,不以单元素批量请求代替单项接口:
525+
`exportDocument`、`exportDocumentZip` 使用 GET 请求 `/<documentId>/export`、`/<documentId>/export_zip`;
526+
`exportMulDocument`、`exportMulDocumentZip` 使用 POST 请求 `batch_export`、`batch_export_zip`,请求体直接为 ID 数组。
527+
单项参数为知识库 ID、文档 ID、文档名称;批量参数为知识库 ID、文档 ID 数组、知识库名称。
528+
服务端未提供文件名时,分别以文档名称或知识库名称加 `.xlsx` / `.zip` 回退,沿用 v2 下载命名。
523529
向量化、生成问题默认排除成功分段,也可选择全部分段。任务类型使用 `DOCUMENT_TASK_TYPE`。
524530
单项向量化使用 `putDocumentRefresh(knowledgeId, documentId, stateList)` 请求 `/<documentId>/refresh`;
525531
单项取消使用 `putCancelTask(knowledgeId, documentId, taskType)` 请求 `/<documentId>/cancel_task`,提交 `{ type }`。
@@ -529,7 +535,12 @@ System 接口由资源管理服务提供;本地开源后端没有对应扩展
529535
提交 `{ id_list, state_list }`。两者均包含全部七种分段状态;单项取消分词复用 `putCancelTask`,任务类型为 `TOKENIZE`。
530536
文档设置的共享载荷为 `DocumentSettingPayload`,生成问题使用 `DocumentGeneratePayload`;
531537
单项设置通过 `meta` 保留来源数据,批量设置将 `allow_download` 放在顶层。
532-
飞书同步沿用 v2 扩展接口 `/knowledge/lark/<knowledgeId>/_batch`,需部署环境支持。
538+
文档同步区分单项和批量,不以单元素批量请求代替单项接口:
539+
`putDocumentSync` 请求 `/<knowledgeId>/document/<documentId>/sync`,
540+
`putMulSyncDocument` 请求 `/<knowledgeId>/document/batch_sync`;
541+
`putLarkDocumentSync` 请求 `/lark/<knowledgeId>/document/<documentId>/sync`,
542+
`putMulLarkSyncDocument` 请求 `/lark/<knowledgeId>/_batch`。上述路径均相对工作空间的 `knowledge` 前缀,
543+
全部使用 PUT;单项不传请求体,批量提交 `{ id_list }`。飞书接口需部署环境支持。
533544
共享文档 API 继续仅提供查询,不增加写入方法。
534545

535546
`workspace/knowledge/document.ts` 维护文档分页查询,路径为

‎ui/src/api/admin/core/request.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export async function postExportExcel<TData = unknown>(fileName: string, url: st
178178
}
179179

180180
/** 发送指定方法的 Blob 请求并触发浏览器下载。 */
181-
export async function downloadRequest(url: string, method: string, data?: unknown, params?: Dict<unknown>): Promise<boolean> {
181+
export async function downloadRequest(url: string, method: string, data?: unknown, params?: Dict<unknown>, fileName = 'download'): Promise<boolean> {
182182
const response = await request.request<Blob>({
183183
url,
184184
method,
@@ -188,7 +188,7 @@ export async function downloadRequest(url: string, method: string, data?: unknow
188188
skipGlobalErrorMessage: true,
189189
} as ExportRequestConfig)
190190

191-
return downloadExportResponse(response, 'download')
191+
return downloadExportResponse(response, fileName)
192192
}
193193

194194
/** 发送 POST 请求并返回可逐块读取的原始响应。 */

‎ui/src/api/admin/workspace/knowledge/document.ts‎

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { del, downloadRequest, get, getExportFile, post, put } from '../../core/request'
1+
import { del, downloadRequest, get, getExportFile, post, postExportExcel, put } from '../../core/request'
22
import type { ParamsPage, ResponsePage } from '../../core/types'
33
import type {
44
Dict,
@@ -8,7 +8,6 @@ import type {
88
DocumentSettingPayload,
99
DocumentTaskState,
1010
DocumentTaskType,
11-
KnowledgeTagGroup,
1211
} from '@/api/types'
1312
import { getWorkspaceId } from '@/utils/resource-context'
1413

@@ -49,6 +48,10 @@ const putDocumentTokenize = (knowledgeId: string, documentId: string, stateList:
4948
const putBatchTokenizeDocuments = (knowledgeId: string, documentIds: string[], stateList: DocumentTaskState[]) =>
5049
put(`${getPrefix(knowledgeId)}/batch_tokenize`, { id_list: documentIds, state_list: stateList })
5150

51+
/** 单个/批量生成关联问题。 */
52+
const putGenerateDocumentQuestions = (knowledgeId: string, data: DocumentGeneratePayload) =>
53+
put(`${getPrefix(knowledgeId)}/batch_generate_related`, data)
54+
5255
/** 单个取消文档任务。 */
5356
const putCancelTask = (knowledgeId: string, documentId: string, taskType: DocumentTaskType) =>
5457
put(`${getPrefix(knowledgeId)}/${documentId}/cancel_task`, { type: taskType })
@@ -57,6 +60,21 @@ const putCancelTask = (knowledgeId: string, documentId: string, taskType: Docume
5760
const putBatchCancelDocumentTask = (knowledgeId: string, documentIds: string[], taskType: DocumentTaskType) =>
5861
put(`${getPrefix(knowledgeId)}/batch_cancel_task`, { id_list: documentIds, type: taskType })
5962

63+
/** 同步单个 Web 文档。 */
64+
const putDocumentSync = (knowledgeId: string, documentId: string) => put(`${getPrefix(knowledgeId)}/${documentId}/sync`)
65+
66+
/** 批量同步 Web 文档。 */
67+
const putMulSyncDocument = (knowledgeId: string, documentIds: string[]) =>
68+
put<{ id_list: string[] }, boolean>(`${getPrefix(knowledgeId)}/batch_sync`, { id_list: documentIds })
69+
70+
/** 同步单个飞书文档。 */
71+
const putLarkDocumentSync = (knowledgeId: string, documentId: string) =>
72+
put(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/document/${documentId}/sync`)
73+
74+
/** 批量同步飞书文档。 */
75+
const putMulLarkSyncDocument = (knowledgeId: string, documentIds: string[]) =>
76+
put<{ id_list: string[] }, boolean>(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/_batch`, { id_list: documentIds })
77+
6078
/** 保存单个文档的召回及来源设置。 */
6179
const putDocumentSetting = (knowledgeId: string, documentId: string, data: DocumentSettingPayload) =>
6280
put(`${getPrefix(knowledgeId)}/${documentId}`, data)
@@ -65,24 +83,25 @@ const putDocumentSetting = (knowledgeId: string, documentId: string, data: Docum
6583
const putBatchDocumentSetting = (knowledgeId: string, documentIds: string[], data: DocumentSettingPayload) =>
6684
put(`${getPrefix(knowledgeId)}/batch_hit_handling`, { ...data, id_list: documentIds })
6785

68-
/** 根据文档内容生成关联问题。 */
69-
const putGenerateDocumentQuestions = (knowledgeId: string, data: DocumentGeneratePayload) =>
70-
put(`${getPrefix(knowledgeId)}/batch_generate_related`, data)
71-
7286
/** 将选中文档迁移至目标知识库。 */
7387
const putMigrateDocuments = (knowledgeId: string, targetKnowledgeId: string, documentIds: string[]) =>
7488
put(`${getPrefix(knowledgeId)}/migrate/${targetKnowledgeId}`, documentIds)
7589

76-
/** 同步 Web 文档。 */
77-
const putSyncDocuments = (knowledgeId: string, documentIds: string[]) => put(`${getPrefix(knowledgeId)}/batch_sync`, { id_list: documentIds })
90+
/** 将单个文档导出为 Excel。 */
91+
const exportDocument = (knowledgeId: string, documentId: string, documentName: string) =>
92+
getExportFile(`${documentName.trim()}.xlsx`, `${getPrefix(knowledgeId)}/${documentId}/export`)
93+
94+
/** 将选中文档批量导出为 Excel。 */
95+
const exportMulDocument = (knowledgeId: string, documentIds: string[], knowledgeName: string) =>
96+
postExportExcel(`${knowledgeName.trim()}.xlsx`, `${getPrefix(knowledgeId)}/batch_export`, undefined, documentIds)
7897

79-
/** 同步飞书文档。 */
80-
const putSyncLarkDocuments = (knowledgeId: string, documentIds: string[]) =>
81-
put(`/workspace/${getWorkspaceId()}/knowledge/lark/${knowledgeId}/_batch`, { id_list: documentIds })
98+
/** 将单个文档及图片导出为 ZIP。 */
99+
const exportDocumentZip = (knowledgeId: string, documentId: string, documentName: string) =>
100+
getExportFile(`${documentName.trim()}.zip`, `${getPrefix(knowledgeId)}/${documentId}/export_zip`)
82101

83-
/** 导出所选文档为 Excel 或 ZIP。 */
84-
const exportDocuments = (knowledgeId: string, documentIds: string[], format: 'excel' | 'zip') =>
85-
downloadRequest(`${getPrefix(knowledgeId)}/${format === 'excel' ? 'batch_export' : 'batch_export_zip'}`, 'POST', documentIds)
102+
/** 将选中文档及图片批量导出为 ZIP。 */
103+
const exportMulDocumentZip = (knowledgeId: string, documentIds: string[], knowledgeName: string) =>
104+
downloadRequest(`${getPrefix(knowledgeId)}/batch_export_zip`, 'POST', documentIds, undefined, `${knowledgeName.trim()}.zip`)
86105

87106
/** 下载文档原文件。 */
88107
const downloadDocumentSource = (knowledgeId: string, document: DocumentItem) =>
@@ -95,17 +114,6 @@ const postReplaceDocumentSource = (knowledgeId: string, documentId: string, file
95114
return post(`${getPrefix(knowledgeId)}/${documentId}/replace_source_file`, data)
96115
}
97116

98-
/** 查询文档当前标签。 */
99-
const getDocumentTags = (knowledgeId: string, documentId: string) => get<KnowledgeTagGroup[]>(`${getPrefix(knowledgeId)}/${documentId}/tags`)
100-
101-
/** 批量添加文档标签。 */
102-
const postAddDocumentTags = (knowledgeId: string, documentIds: string[], tagIds: string[]) =>
103-
post(`${getPrefix(knowledgeId)}/batch_add_tag`, { document_ids: documentIds, tag_ids: tagIds })
104-
105-
/** 移除文档标签关联。 */
106-
const putDeleteDocumentTags = (knowledgeId: string, documentId: string, tagIds: string[]) =>
107-
put(`${getPrefix(knowledgeId)}/${documentId}/tags/batch_delete`, tagIds)
108-
109117
export default {
110118
getDocumentPage,
111119
putQuickCreateDocuments,
@@ -122,12 +130,14 @@ export default {
122130
putBatchDocumentSetting,
123131
putGenerateDocumentQuestions,
124132
putMigrateDocuments,
125-
putSyncDocuments,
126-
putSyncLarkDocuments,
127-
exportDocuments,
133+
putDocumentSync,
134+
putMulSyncDocument,
135+
putLarkDocumentSync,
136+
putMulLarkSyncDocument,
137+
exportDocument,
138+
exportMulDocument,
139+
exportDocumentZip,
140+
exportMulDocumentZip,
128141
downloadDocumentSource,
129142
postReplaceDocumentSource,
130-
getDocumentTags,
131-
postAddDocumentTags,
132-
putDeleteDocumentTags,
133143
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** 查询文档当前标签。 */
2+
const getDocumentTags = (knowledgeId: string, documentId: string) => get<KnowledgeTagGroup[]>(`${getPrefix(knowledgeId)}/${documentId}/tags`)
3+
4+
/** 批量添加文档标签。 */
5+
const postAddDocumentTags = (knowledgeId: string, documentIds: string[], tagIds: string[]) =>
6+
post(`${getPrefix(knowledgeId)}/batch_add_tag`, { document_ids: documentIds, tag_ids: tagIds })
7+
8+
/** 移除文档标签关联。 */
9+
const putDeleteDocumentTags = (knowledgeId: string, documentId: string, tagIds: string[]) =>
10+
put(`${getPrefix(knowledgeId)}/${documentId}/tags/batch_delete`, tagIds)

‎ui/src/assets/iconfont.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ui/src/components/business/generate-questions/GenerateQuestionsDialog.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ defineExpose({ open, close })
9595

9696
<template>
9797
<MkDialog v-model="visible" title="生成问题" @closed="emit('closed')">
98-
<el-form ref="formRef" :model="form" label-position="top" :disabled="loading || modelLoading" @submit.prevent>
98+
<el-form ref="formRef" :model="form" label-position="top" v-loading="loading || modelLoading" @submit.prevent>
9999
<el-alert :closable="false" :title="promptTip" type="primary" class="mb-4! items-start! whitespace-pre-line" show-icon>
100100
<template #icon><MkIcon name="icon_info_filled" class="mt-2" /></template>
101101
</el-alert>

‎ui/src/constants/CONSTANT_README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const knowledgeTypeLabel = KNOWLEDGE_TYPE_LABELS[knowledgeType]
4040
`state.ts` 的 `EXECUTION_STATUS_OPTIONS` 维护触发器、工具和知识库工作流执行记录共用的
4141
中文文案与图标类型,仅包含 `PENDING`、`STARTED`、`SUCCESS`、`FAILURE`、`REVOKE`、
4242
`REVOKED`、`TRIGGER_ERROR` 七种接口状态,列表筛选及执行详情复用该配置。新增状态只需在业务配置中补齐展示,
43-
不修改 `MkStatusLabel`。文档任务使用 `views/knowledge-detail/document/status.ts` 的独立配置,
43+
不修改 `MkStatusLabel`。文档任务使用 `views/knowledge-detail/library/document/status.ts` 的独立配置,
4444
筛选查询仍映射 `DOCUMENT_TASK_STATE` 与 `DOCUMENT_TASK_TYPE`,不提交展示状态键。
4545

4646
`document.ts` 的 `DOCUMENT_HIT_HANDLING_LABELS` 维护文档命中处理方式的展示文案,

‎ui/src/router/ROUTE_README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ System 共享资源页面:
340340
详情容器复用 `ResourceDetailLayout`,菜单依次为“资料库(文档、图片、标签管理)”、
341341
“工作流”、“检索优化(召回测试、问题、自定义分词)”、“授权与集成(对话用户、外部检索服务)”、
342342
“设置”。资料库分组使用空 path,保留原 `/document` 地址;图片和标签分别使用 `/image`、`/tag`。
343+
对应 View 统一位于 `views/knowledge-detail/library/` 下的 `document/`、`image/`、`tag/`;
344+
普通和共享文档路由均引用 `library/document/index.vue`,文件分组不增加 URL 层级。
343345
检索优化使用 `/retrieval/recall`、`/retrieval/question`、`/retrieval/dictionary`;
344346
授权与集成使用 `/integration/chat-user`、`/integration/external-retrieval`。
345347
分组不挂载页面组件,直接访问分组时重定向到首个子页。新增七个页面暂为占位 View。`setting`

‎ui/src/router/admin/workspace/modules/knowledge-shared.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const sharedKnowledgeRoutes: RouteRecordRaw[] = [
1818
{
1919
path: 'document',
2020
name: 'workspace-shared-knowledge-document-list',
21-
component: () => import('@/views/knowledge-detail/document/index.vue'),
21+
component: () => import('@/views/knowledge-detail/library/document/index.vue'),
2222
meta: { title: '文档', order: 10 },
2323
},
2424
],

‎ui/src/router/admin/workspace/modules/knowledge.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ export const knowledgeRoutes: RouteRecordRaw[] = [
2929
{
3030
path: 'document',
3131
name: 'workspace-knowledge-document-list',
32-
component: () => import('@/views/knowledge-detail/document/index.vue'),
32+
component: () => import('@/views/knowledge-detail/library/document/index.vue'),
3333
meta: { title: '文档', order: 10 },
3434
},
3535
{
3636
path: 'image',
3737
name: 'workspace-knowledge-image-list',
38-
component: () => import('@/views/knowledge-detail/image/index.vue'),
38+
component: () => import('@/views/knowledge-detail/library/image/index.vue'),
3939
meta: { title: '图片', order: 20 },
4040
},
4141
{
4242
path: 'tag',
4343
name: 'workspace-knowledge-tag',
44-
component: () => import('@/views/knowledge-detail/tag/index.vue'),
44+
component: () => import('@/views/knowledge-detail/library/tag/index.vue'),
4545
meta: { title: '标签管理', order: 30 },
4646
},
4747
],

0 commit comments

Comments
 (0)