From 02ccc0a21dc85b15595c1aa561b79b56b223ee84 Mon Sep 17 00:00:00 2001 From: yuance <182865460@qq.com> Date: Wed, 24 Sep 2025 17:42:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=96=87=E6=A1=A3=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88=E7=9F=A5=E8=AF=86=E5=BA=93=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ai/auditReport/index.ts | 6 +- src/api/ai/knowledgeBase/index.ts | 59 +++++++ src/views/oa/oaCompany/components/Import.vue | 110 +++++++++++++ .../oa/oaCompany/components/oaCompanyEdit.vue | 12 +- src/views/oa/oaCompany/index.vue | 145 +++++++++++++++++- 5 files changed, 326 insertions(+), 6 deletions(-) create mode 100644 src/api/ai/knowledgeBase/index.ts create mode 100644 src/views/oa/oaCompany/components/Import.vue diff --git a/src/api/ai/auditReport/index.ts b/src/api/ai/auditReport/index.ts index ea944ef..2c00369 100644 --- a/src/api/ai/auditReport/index.ts +++ b/src/api/ai/auditReport/index.ts @@ -1,9 +1,7 @@ import request from '@/utils/request'; -import type { ApiResult, PageResult } from '@/api'; -import type { AuditReport, AuditReportParam } from './model'; +import type { ApiResult } from '@/api'; +import type { AuditReport } from './model'; import { MODULES_API_URL } from '@/config/setting'; -import {User} from "@/api/system/user/model"; - /** * 生成审计报告-单一模块 diff --git a/src/api/ai/knowledgeBase/index.ts b/src/api/ai/knowledgeBase/index.ts new file mode 100644 index 0000000..c93868d --- /dev/null +++ b/src/api/ai/knowledgeBase/index.ts @@ -0,0 +1,59 @@ +import request from '@/utils/request'; +import type { ApiResult } from '@/api'; +import { MODULES_API_URL } from '@/config/setting'; + +/** + * 获取知识库文档列表 + */ +export async function getKnowledgeBaseDocuments(kbId: string, pageSize: number, pageNumber: number) { + const res = await request.get>( + MODULES_API_URL + '/ai/knowledgeBase/documents', + { + params: { kbId, pageSize, pageNumber } + } + ); + if (res.data.code === 0) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 删除知识库文档 + */ +export async function deleteKnowledgeBaseDocument(kbId: string, fileIds: string) { + const res = await request.delete>( + MODULES_API_URL + '/ai/knowledgeBase/document', + { + params: { kbId, fileIds } + } + ); + if (res.data.code === 0) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 上传知识库文档 + */ +export async function uploadKnowledgeBaseDocument(kbId: string, files: File[]) { + const formData = new FormData(); + files.forEach(file => { + formData.append('files', file); + }); + const res = await request.post>( + MODULES_API_URL + '/ai/knowledgeBase/upload', + formData, + { + params: { kbId }, + headers: { + 'Content-Type': 'multipart/form-data' + } + } + ); + if (res.data.code === 0) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} \ No newline at end of file diff --git a/src/views/oa/oaCompany/components/Import.vue b/src/views/oa/oaCompany/components/Import.vue new file mode 100644 index 0000000..8ef7390 --- /dev/null +++ b/src/views/oa/oaCompany/components/Import.vue @@ -0,0 +1,110 @@ + + + + \ No newline at end of file diff --git a/src/views/oa/oaCompany/components/oaCompanyEdit.vue b/src/views/oa/oaCompany/components/oaCompanyEdit.vue index c757816..a22455d 100644 --- a/src/views/oa/oaCompany/components/oaCompanyEdit.vue +++ b/src/views/oa/oaCompany/components/oaCompanyEdit.vue @@ -49,6 +49,15 @@ v-model:value="form.companyCode" /> + + + @@ -260,7 +269,8 @@ oaCompanyName: '', status: 0, comments: '', - sortNumber: 100 + sortNumber: 100, + kbId: undefined, }); /* 更新visible */ diff --git a/src/views/oa/oaCompany/index.vue b/src/views/oa/oaCompany/index.vue index 27fb070..ac90b19 100644 --- a/src/views/oa/oaCompany/index.vue +++ b/src/views/oa/oaCompany/index.vue @@ -35,6 +35,13 @@ 修改 + + 文档管理 + + + + +
+ 新增文档 +
+ + + +
+ + + @@ -64,9 +113,13 @@ import type { } from 'ele-admin-pro/es/ele-pro-table/types'; import Search from './components/search.vue'; import OaCompanyEdit from './components/oaCompanyEdit.vue'; +// 导入Import组件和API +import Import from './components/Import.vue'; import {pageOaCompany, removeOaCompany, removeBatchOaCompany} from '@/api/oa/oaCompany'; import type {OaCompany, OaCompanyParam} from '@/api/oa/oaCompany/model'; import {getPageTitle,isImage} from "@/utils/common"; +// 导入知识库API +import {getKnowledgeBaseDocuments, deleteKnowledgeBaseDocument} from '@/api/ai/knowledgeBase'; // 请修改为正确的API路径 // 表格实例 const tableRef = ref | null>(null); @@ -79,8 +132,44 @@ const current = ref(null); const showEdit = ref(false); // 是否显示批量移动弹窗 const showMove = ref(false); +// 文档管理相关响应式变量 +const showDocManage = ref(false); // 是否显示文档管理弹窗 +const showImport = ref(false); // 是否显示导入弹窗 // 加载状态 const loading = ref(true); +// 新增分页状态变量 +const currentPage = ref(1); +const total = ref(0); + +// 文档管理相关变量 +const currentKbId = ref(''); // 当前知识库ID +const currentKbName = ref(''); // 当前知识库名称 +const docList = ref([]); // 文档列表数据 +const docLoading = ref(false); // 文档加载状态 +// 文档表格列配置 +const docColumns = ref([ + { + title: '文件名', + dataIndex: 'name', // 改为接口返回的name字段 + key: 'fileName', + }, + { + title: '文件大小', + dataIndex: 'size', // 改为接口返回的size字段 + key: 'fileSize', + }, + { + title: '上传时间', + dataIndex: 'gmtModified', // 改为接口返回的gmtModified字段 + key: 'createTime', + customRender: ({ text }) => toDateString(text) // 添加时间格式化 + }, + { + title: '操作', + key: 'action', + width: 100, + } +]); // 表格数据源 const datasource: DatasourceFunction = ({ @@ -170,7 +259,7 @@ const columns = ref([ { title: '操作', key: 'action', - width: 180, + width: 220, fixed: 'right', align: 'center', hideInSetting: true @@ -194,6 +283,60 @@ const openMove = () => { showMove.value = true; }; +// 打开文档管理弹窗 +const openDocManage = (record: OaCompany) => { + currentKbId.value = record.kbId; // 使用record中的kbId + currentKbName.value = record.companyName; // 使用单位名称作为知识库名称 + currentPage.value = 1; + showDocManage.value = true; + loadDocuments(); +}; + +// 加载文档列表 +const loadDocuments = async () => { + docLoading.value = true; + try { + const response = await getKnowledgeBaseDocuments( + currentKbId.value, + 10, + currentPage.value + ); + docList.value = Array.isArray(response?.list) ? response.list : []; + total.value = response?.count || 0; + } catch (error) { + message.error('加载文档列表失败'); + console.error('加载文档错误:', error); + } finally { + docLoading.value = false; + } +}; + +// 删除文档 +const deleteDoc = async (record: any) => { + try { + // 执行删除操作 + await deleteKnowledgeBaseDocument(currentKbId.value, record.id); + + // 立即本地删除(核心修改) + const index = docList.value.findIndex(item => item.id === record.id); + if (index > -1) { + docList.value.splice(index, 1); + total.value -= 1; + } + message.success('删除成功'); + // 阿里云异步删除,需等待异步删除完成再重新查询 + // await loadDocuments(); + } catch (error) { + message.error('删除失败'); + console.error(error); + } +}; + +// 打开导入弹窗 +const openImport = () => { + showImport.value = true; +}; + /* 删除单个 */ const remove = (row: OaCompany) => { const hide = message.loading('请求中..', 0);