From 5d8fe1cbd65bf119b7f2d3e9799e6e40957f6a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A8=9C?= Date: Fri, 16 May 2025 16:12:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B5=84=E4=BA=A7=E5=BA=93=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/kbApp.ts | 71 ++++- src/api/kfApp.ts | 44 ++- src/components/KnowledgeForm/index.vue | 27 +- src/components/Upload/index.vue | 110 ++++++- src/components/Upload/uploadProgress.vue | 24 +- src/lang/package/en.ts | 3 + src/lang/package/zh-cn.ts | 3 + src/styles/grouInfo.scss | 4 +- src/styles/knowledgeFile.scss | 63 ++-- src/styles/knowledgeFileSection.scss | 14 +- src/styles/knowledgeLibrary.scss | 1 + src/views/knowledgeFile/fileConfig.ts | 10 +- src/views/knowledgeLibrary/index.vue | 384 ++++++++++++++--------- 13 files changed, 503 insertions(+), 255 deletions(-) diff --git a/src/api/kbApp.ts b/src/api/kbApp.ts index 2d7dc6a..2bb90b5 100644 --- a/src/api/kbApp.ts +++ b/src/api/kbApp.ts @@ -1,7 +1,16 @@ import request from '@/utils/request'; import { CreateKbRequest, QueryKbRequest, UpdateKbRequest } from './apiType'; import { ModelForm } from '@/components/UserHeaderBar/modelConfig'; - +import qs from 'qs'; + +export type ITaskType = + | 'doc_parse' + | 'kb_export' + | 'kb_import' + | 'dataset_export' + | 'dataset_import' + | 'dataset_generate' + | 'tetsing_run'; class KbAppAPI { /** 获取用户所有知识库*/ static getKbLibrary(data: QueryKbRequest) { @@ -13,10 +22,10 @@ class KbAppAPI { } /** 删除用户知识库*/ - static delKbLibrary(data: { id: string; task_id: string }) { + static delKbLibrary(data: string[]) { return request({ - url: `/kb/rm`, - method: 'post', + url: `/kb`, + method: 'delete', data: data, }); } @@ -32,7 +41,7 @@ class KbAppAPI { } /**更新资产库 */ - static updateKbLibrary(params: { teamId: string }, data: UpdateKbRequest) { + static updateKbLibrary(params: { kbId: string }, data: UpdateKbRequest) { return request({ url: `/kb`, method: 'put', @@ -41,29 +50,53 @@ class KbAppAPI { }); } - /** 获取导入知识库状态*/ - static queryKbTaskList(data: { types: any[]; page_size: number; page_number: number }) { + /** 获取导入/导出任务列表*/ + static queryTaskList(data: { + teamId: string; + taskType: ITaskType; + pageSize: number; + page: number; + }) { return request({ - url: `/kb/task/list`, + url: `/task`, method: 'post', data: data, }); } - static stopKbTaskList(data: { task_id?: string; types?: any[] }) { + static stopKbTaskList(params: { taskId?: string; taskType?: ITaskType }, data: string[]) { return request({ - url: `/kb/task/rm`, - method: 'post', + url: `/task`, + method: 'delete', + params, data: data, }); } + /** 删除任务列表一条任务 */ + static stopOneTaskList(params: { taskId: string }) { + return request({ + url: `/task/one`, + method: 'delete', + params, + }); + } + /** 删除任务列表所有任务 */ + static stopAllTaskList(params: { teamId: string; taskType: ITaskType }) { + return request({ + url: `/task/all`, + method: 'delete', + params, + }); + } + /**导入资产库 */ - static importKbLibrary(payload: { data: any }, options: any) { + static importKbLibrary(payload: { data: any; params: any }, options: any) { return request({ url: `/kb/import`, method: 'post', data: payload.data, + params: payload.params, headers: { 'Content-Type': 'multipart/form-data', }, @@ -78,12 +111,13 @@ class KbAppAPI { /**打包资产库 */ - static savebLibrary(id: string, options: any) { + static savebLibrary(kbIds: string[], options: any) { return request({ url: `/kb/export`, - data: { - id, + params: { + kbIds, }, + paramsSerializer: (params) => qs.stringify(params, { indices: false }), method: 'post', onUploadProgress(e) { const rate = Math.floor((e.loaded / (e.total as number)) * 100); @@ -126,6 +160,13 @@ class KbAppAPI { }); } + static querySearchMethodList() { + return request({ + url: `/other/search_method`, + method: 'get', + }); + } + /** 是否启用文件*/ static addUserModel(data: ModelForm) { return request({ diff --git a/src/api/kfApp.ts b/src/api/kfApp.ts index a2675e0..9bcf516 100644 --- a/src/api/kfApp.ts +++ b/src/api/kfApp.ts @@ -11,10 +11,11 @@ class KfAppAPI { }); } /** 修改资产库里的文件*/ - static updateLibraryFile(data: DocRenameRequest) { + static updateLibraryFile(params: { docId: string }, data: DocRenameRequest) { return request({ - url: `/doc/update`, - method: 'post', + url: `/doc`, + method: 'put', + params, data: data, }); } @@ -29,28 +30,30 @@ class KfAppAPI { } /** 是否删除文件*/ - static delLibraryFile(data: { ids: any[] }) { + static delLibraryFile(data: string[]) { return request({ - url: `/doc/rm`, - method: 'post', + url: `/doc`, + method: 'delete', data: data, }); } /** 是否重启/取消文件*/ - static runLibraryFile(data: { ids: string[]; run: string }) { + static runLibraryFile(params: { parse: boolean }, data: string[]) { return request({ - url: `/doc/run`, + url: `/doc/parse`, method: 'post', - data: data, + params, + data, }); } /**导入资产库文档 */ static importKbLibraryFile(payload: { data: any; params: any }, options: any) { return request({ - url: `/doc/upload?kb_id=${payload.params.kb_id}`, + url: `/doc`, method: 'post', + params: payload.params, data: payload.data, headers: { 'Content-Type': 'multipart/form-data', @@ -99,19 +102,30 @@ class KfAppAPI { }); } - /** 是否启用文件*/ - static switchLibraryFileSection(data: { enabled: boolean; ids: string[]; document_id: string }) { + /** 更新文本块内容 */ + static updateFileSection(params: { chunkId: string }, data: { enabled?: boolean; text: string }) { + return request({ + url: `/chunk`, + method: 'put', + params, + data: data, + }); + } + + /** 批量启用文本块内容 */ + static switchFileSection(params: { enabled: boolean }, data: string[]) { return request({ url: `/chunk/switch`, - method: 'post', + method: 'put', + params, data: data, }); } /** 查询文档日志*/ - static documentLog(data: { docId: string }) { + static getDocumentLog(data: { docId: string }) { return request({ - url: `/doc/task_report`, + url: `/doc/report`, method: 'get', params: data, }); diff --git a/src/components/KnowledgeForm/index.vue b/src/components/KnowledgeForm/index.vue index 655948a..58fe61f 100644 --- a/src/components/KnowledgeForm/index.vue +++ b/src/components/KnowledgeForm/index.vue @@ -201,7 +201,7 @@ label="domain" class="domain-config"> { JSON.stringify({ ...props.formData, docTypes: props.formData?.docTypes.filter( - (item: any) => item?.type?.length + (item: any) => item?.docTypeName?.length ), defaultChunkSize: props.formData.defaultChunkSize || 512, uploadSizeLimit: props.formData?.uploadSizeLimit || 512, @@ -434,7 +435,6 @@ onMounted(() => { } }); }); - const submitForm = async (formEl: FormInstance | undefined) => { if (!formEl) return; await formEl.validate((valid) => { @@ -447,14 +447,14 @@ const submitForm = async (formEl: FormInstance | undefined) => { defaultChunkSize: ruleForm.value.defaultChunkSize, uploadCountLimit: ruleForm.value.uploadCountLimit, uploadSizeLimit: ruleForm.value.uploadSizeLimit, - docTypes: ruleForm.value.docTypes.filter((item) => item.type.length > 0), + docTypes: ruleForm.value.docTypes.filter((item) => item.docTypeName.length > 0), }; if (valid) { loading.visible.value = true; createLoading.value = true; - if (ruleForm.value?.id) { + if (ruleForm.value?.kbId) { KbAppAPI.updateKbLibrary({ - teamId: ruleForm.value.id, + kbId: ruleForm.value.kbId, },payload) .then((res) => { props.handleOpsKbForm(); @@ -475,9 +475,16 @@ const submitForm = async (formEl: FormInstance | undefined) => { createLoading.value = false; }); } else { - KbAppAPI.createKbLibrary({teamId:ruleForm.value.teamId},{ + let docArr:any = [] + ruleForm.value.docTypes.map((item) => { + docArr.push({ + docTypeId:item.docTypeId, + docTypeName:item.docTypeName + }) + } ) + KbAppAPI.createKbLibrary({teamId:route.query.id?.toString() ?? ''},{ ...payload, - docTypes: ruleForm.value.docTypes.map((item) => item.type), + docTypes: docArr }) .then(() => { props.handleOpsKbForm(); @@ -508,8 +515,8 @@ const handleRemoveAllDocType = () => { const handleAddDocType = () => { ruleForm.value.docTypes.push({ - id: uuidv4(), - type: '', + docTypeId: uuidv4(), + docTypeName: '', }); }; diff --git a/src/components/Upload/index.vue b/src/components/Upload/index.vue index c868239..0756f51 100644 --- a/src/components/Upload/index.vue +++ b/src/components/Upload/index.vue @@ -30,7 +30,7 @@ props.maxFileNum }} -
+
{{ $t('dialogTipText.fileSizes') }}:{{ allFileSizesInfo }}/{{ maxFileSizesInfo }}
@@ -130,7 +130,7 @@ class="resetBtn" type="primary" :disabled="btnDisabled" - @click="uploadType === 'file' ? uploadKnowledgeFile() : uploadFiles()"> + @click="handleFileType(uploadType)"> {{ $t('btnText.confirm') }} { + switch(type){ + case 'file': + uploadKnowledgeFile(); + break; + case 'dataset': + uploadDatasetFile(); + break; + case 'kbfile': + uploadFiles(); + break; + default: + break; + } +} const doUpload = (options: any) => { props.handleUploadMyFile(options); }; @@ -221,6 +236,7 @@ const props = defineProps({ }, uploadType: { type: String, + default:'kbfile' }, }); const fileTableList = reactive<{ @@ -308,6 +324,7 @@ const handlsSuccess = () => { }; const handleUploadRestart = (item: any) => { + console.log(item,uploadingList.value) uploadingList.value = uploadingList.value.map((up) => { if (up.id === item.id) { return { ...item, error: false, uploadStatus: 'error' }; @@ -369,13 +386,12 @@ watch( () => { uploadingList.value = props.taskList?.map((item: any) => { return { - id: item.id, + id: item.opId, newUploadTask: false, - taskId: item.task.id, - name: item.name, - size: item?.document_size, - percent: item?.task?.status && item?.task?.status !== 'pending' ? 100 : 99, - uploadStatus: item?.task?.status, + taskId: item.taskId, + name: item.opName, + percent: item?.taskStatus && item?.taskStatus !== 'pending' ? 100 : 99, + uploadStatus: item?.taskStatus, }; }); handleToggleUploadNotify(); @@ -450,19 +466,19 @@ const uploadFiles = () => { uploadingList.value = [ ...uploadingList.value, ...res?.map((item: any) => { + console.log(item) let reportDetail = item?.task?.reports?.[0]; return { - id: item.id, - taskId: item.task.id, - name: item.name, - size: item?.document_size, + id: item.opId, + taskId: item.taskId, + name: item.opName, percent: - item?.task?.status === 'success' + item?.taskStatus === 'success' ? 100 : reportDetail?.current_stage ? ((reportDetail?.current_stage / reportDetail?.stage_cnt) * 100).toFixed(1) : 0, - uploadStatus: item?.task?.status, + uploadStatus: item?.taskStatus, }; }), ]; @@ -553,6 +569,72 @@ const uploadKnowledgeFile = () => { allFileSizes.value = 0; }; +// 提交数据集 +const uploadDatasetFile = () => { + props?.handleImportLoading(true); + let uploadFileNumber = 0; + uploadingList.value = fileTableList.data.map((item) => { + return { + id: item.id, + name: item.name, + file: item.file, + percent: 0, + newUploadTask: true, + }; + }); + const uploadPromises = uploadingList.value.map((item) => { + return new Promise((resolve, reject) => { + doUpload({ + file: item.file, + onProgress: (evt: any) => { + if (evt < 100) { + item.percent = evt; + } + }, + onError: (e: any) => { + uploadingList.value = uploadingList.value.map((up) => { + if (up.id === e.id) { + return { ...e, uploadStatus: 'error' }; + } + return up; + }); + reject(e); // 传递错误 + }, + onSuccess: () => { + uploadFileNumber += 1; + item.percent = 100; + item.uploadStatus = 'success'; + resolve(true); // 标记成功 + }, + fileInfo: item, + }); + }); + }); + + // 所有上传完成后统一更新列表 + Promise.allSettled(uploadPromises).then((results) => { + const successCount = results.filter((result) => result.status === 'fulfilled').length; + const errorCount = results.length - successCount; + + // 统一更新列表 + props?.handleImportLoading(false); + if (errorCount > 0) { + handleToggleUploadNotify(); + } + + // 所有成功后的回调 + if (errorCount === 0) { + props.handleQueryTaskList(fileTableList.data); // 统一更新列表 + } + }); + + uploadingList.value.length && handleToggleUploadNotify(); + props.handleCancelVisible(); + fileTableList.data = []; + uploadRef.value?.clearFiles(); + allFileSizes.value = 0; +} + const handleToggleUploadNotify = () => { props.toggleUploadNotify({ showUploadNotify: true, diff --git a/src/components/Upload/uploadProgress.vue b/src/components/Upload/uploadProgress.vue index 32c89d5..1185755 100644 --- a/src/components/Upload/uploadProgress.vue +++ b/src/components/Upload/uploadProgress.vue @@ -40,13 +40,7 @@
- -
-
{{ `,${$t('assetLibrary.uploadIng')}...` }}
@@ -72,7 +66,7 @@ {{ $t('uploadText.uploadSuccess') }}
@@ -105,7 +99,6 @@ @@ -155,4 +109,4 @@ border-radius: 8px; } } - + \ No newline at end of file diff --git a/src/views/knowledgeFile/index.vue b/src/views/knowledgeFile/index.vue index 9d265f9..65474ff 100644 --- a/src/views/knowledgeFile/index.vue +++ b/src/views/knowledgeFile/index.vue @@ -5,6 +5,7 @@ class="kf-container-right" v-if="menuType === MenuType.KL_FILE">
+
+ +
- @@ -137,7 +112,7 @@ @@ -161,16 +136,16 @@
@@ -215,11 +190,11 @@
@@ -310,7 +275,7 @@ @@ -335,17 +300,12 @@ @@ -397,20 +357,13 @@ fixed="right"> -
+
- - {{ textType[scope.row.type] }} + + {{ textType[scope.row.chunkType] }} @@ -195,6 +195,9 @@
+ + 编辑 +
-
+
-
+
-
+
+ + + + -- Gitee