From 20768dc853ccbe22ef61575b61094d64f2dcfc22 Mon Sep 17 00:00:00 2001 From: ysn <2126564605@qq.com> Date: Mon, 1 Jun 2026 11:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7-=E6=95=B0=E6=8D=AE=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/cases/index.vue | 2 +- src/views/knowledge/index.vue | 80 +++++++++++++++++++++++++++++++++-- src/views/utility/index.vue | 47 ++++++++++---------- 3 files changed, 100 insertions(+), 29 deletions(-) diff --git a/src/views/cases/index.vue b/src/views/cases/index.vue index e403ce4..35b57cd 100644 --- a/src/views/cases/index.vue +++ b/src/views/cases/index.vue @@ -1177,7 +1177,7 @@ export default { }, // 查看按钮操作 handleView(row) { - this.$tab.openPage(row.patient_name + row.id, "/cases/detail/" + row.id); + this.$tab.openPage(row.patient_name + "-" + row.id, "/cases/detail/" + row.id); }, }, }; diff --git a/src/views/knowledge/index.vue b/src/views/knowledge/index.vue index 61d3d10..b894f94 100644 --- a/src/views/knowledge/index.vue +++ b/src/views/knowledge/index.vue @@ -674,14 +674,17 @@ export default { this.uploadProgressDialogVisible = true; this.uploadPercent = 0; + // 创建初始上传记录(无论成功失败都会保存) + const recordId = this.createTransferRecord(file); + // 执行 MinIO 上传 - this.uploadToMinio(file); + this.uploadToMinio(file, recordId); // 清空文件输入 event.target.value = ""; }, // 上传到 MinIO(支持 PDF 缩略图生成) - async uploadToMinio(file) { + async uploadToMinio(file, recordId) { try { // 确保 MinIO 客户端已初始化 await this.ensureMinioInitialized(); @@ -713,7 +716,8 @@ export default { result.objectName, file, result.thumbnailPath, - bucket + bucket, + recordId ); // 完成上传 @@ -727,6 +731,8 @@ export default { console.error("上传失败:", error); this.uploadProgressDialogVisible = false; this.$modal.msgError("上传失败: " + error.message); + // 更新上传记录为失败状态 + this.updateTransferRecord(recordId, false, ""); } }, // 确保 MinIO 客户端已初始化 @@ -738,7 +744,7 @@ export default { } }, // 保存知识库记录到业务数据库 - async saveKnowledgeToDB(filePath, file, thumbnailPath = "", bucket = "") { + async saveKnowledgeToDB(filePath, file, thumbnailPath = "", bucket = "", recordId = null) { console.log("saveKnowledgeToDB:", filePath, file, thumbnailPath, bucket); // 构建完整的文件路径(bucket/object 格式) @@ -764,6 +770,72 @@ export default { }; await postKnowledgeCreate(data); console.log("知识库记录保存成功"); + // 更新上传记录为成功状态,保存完整的可预览路径 + if (recordId) { + const minioEndpoint = this.$store.state.user.netConfig?.MINIO_ENDPOINT_HTTPS?.trim() || "http://47.92.6.51:9100/"; + const fileUrl = minioEndpoint + fullFilePath; + this.updateTransferRecord(recordId, true, fileUrl); + } + }, + // 创建初始上传记录(文件选择时调用,无论成功失败都会保存) + createTransferRecord(file) { + const STORAGE_KEY = "file_transfer_records"; + try { + // 获取现有记录 + const existingData = localStorage.getItem(STORAGE_KEY); + const records = existingData ? JSON.parse(existingData) : []; + + // 生成唯一记录 ID + const recordId = Date.now() + "_" + Math.random().toString(36).substr(2, 9); + + // 创建新记录(transfer_type: 3 表示上传) + const newRecord = { + id: recordId, + file_name: file.name, + file_size: file.size, + time: new Date().toISOString(), + transfer_type: 3, // 3 表示上传操作 + is_success: false, // 初始状态为未完成 + is_uploading: true, // 正在上传中 + file_url: "", + }; + + // 添加到记录数组 + records.unshift(newRecord); + + // 保存回 localStorage + localStorage.setItem(STORAGE_KEY, JSON.stringify(records)); + console.log("上传记录已创建:", newRecord); + return recordId; + } catch (e) { + console.error("创建上传记录失败", e); + return null; + } + }, + // 更新上传记录状态 + updateTransferRecord(recordId, isSuccess, fileUrl = "") { + const STORAGE_KEY = "file_transfer_records"; + try { + // 获取现有记录 + const existingData = localStorage.getItem(STORAGE_KEY); + const records = existingData ? JSON.parse(existingData) : []; + + // 查找并更新记录 + const recordIndex = records.findIndex(record => record.id === recordId); + if (recordIndex !== -1) { + records[recordIndex].is_success = isSuccess; + records[recordIndex].is_uploading = false; // 上传完成,不再是上传中 + if (fileUrl) { + records[recordIndex].file_url = fileUrl; + } + + // 保存回 localStorage + localStorage.setItem(STORAGE_KEY, JSON.stringify(records)); + console.log("上传记录已更新:", records[recordIndex]); + } + } catch (e) { + console.error("更新上传记录失败", e); + } }, }, }; diff --git a/src/views/utility/index.vue b/src/views/utility/index.vue index cca7a86..61f914c 100644 --- a/src/views/utility/index.vue +++ b/src/views/utility/index.vue @@ -71,7 +71,7 @@ :type=" getStatusType( scope.row.transfer_type, - scope.row.is_success + scope.row ) " size="mini" @@ -79,7 +79,7 @@ {{ getStatusText( scope.row.transfer_type, - scope.row.is_success + scope.row ) }} @@ -247,31 +247,30 @@ export default { return iconMap[suffix] || "el-icon-document"; }, - // 获取状态文字,与 Qt UpdateTransferStatus 逻辑一致 - // type: 1=upload, 3=download, 9=other - getStatusText(type, isSuccess) { - // 与 Qt 的 switch(type << isSuccess) 对应 - const key = type << (isSuccess ? 1 : 0); - const statusMap = { - 1: "上传中", // upload=1, is_success=false -> 1 << 0 = 1 (新插入时显示上传中) - 2: "上传成功", // upload=1, is_success=true -> 1 << 1 = 2 - 3: "下载中", // download=3, is_success=false -> 3 << 0 = 3 (新插入时显示下载中) - 6: "下载成功", // download=3, is_success=true -> 3 << 1 = 6 - 9: "其他", // other=9 - 18: "其他完成", // other=9, is_success=true -> 9 << 1 = 18 - }; - // 实际场景:已有的记录失败时 - if (!isSuccess && key === 1) return "上传失败"; - if (!isSuccess && key === 3) return "下载失败"; - return statusMap[key] || "未知"; + // 获取状态文字 + getStatusText(type, row) { + const isSuccess = row.is_success; + const isUploading = row.is_uploading; + + if (type === 3) { + // 知识库上传类型 + if (isUploading && !isSuccess) return "上传中"; + if (!isSuccess) return "上传失败"; + return "上传成功"; + } + // 其他类型 + if (!isSuccess) return "失败"; + return "成功"; }, // 获取状态标签类型(Element UI 样式) - getStatusType(type, isSuccess) { + getStatusType(type, row) { + const isSuccess = row.is_success; + const isUploading = row.is_uploading; + + if (isUploading && !isSuccess) return "warning"; if (!isSuccess) return "danger"; - if (type === 1) return "success"; - if (type === 3) return "success"; - return "info"; + return "success"; }, // 下载文件 @@ -284,7 +283,7 @@ export default { }, // 打开文件位置 handleOpenLocation(item) { - if (item.local_path) { + if (item.file_url) { this.$modal.msg("浏览器安全限制:请下载后在下载列表打开文件夹"); const a = document.createElement("a"); a.href = item.file_url;