From 71f75080a89ffac21b8422d2520a74df0180fac4 Mon Sep 17 00:00:00 2001 From: ysn <2126564605@qq.com> Date: Thu, 18 Jun 2026 16:07:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93-=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9C=A8=E5=B7=A5=E5=85=B7=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/knowledge/index.vue | 96 +++++++++++++++++++++++++++++++---- src/views/utility/index.vue | 28 +++++++++- 2 files changed, 114 insertions(+), 10 deletions(-) diff --git a/src/views/knowledge/index.vue b/src/views/knowledge/index.vue index c8a03b8..882cf6e 100644 --- a/src/views/knowledge/index.vue +++ b/src/views/knowledge/index.vue @@ -579,13 +579,13 @@ export default { // 创建视频播放页面(支持大文件流媒体) this.createVideoPlayer(videoUrl, row.title || "视频播放"); } - }) + }); } else { postKnowledgePlay({ knowledge_id: row.id }).then((res) => { if (res.code === 200) { window.open(this.getFullFilePath(row.file_path), "_blank"); } - }) + }); } }, // 创建视频播放器(支持大文件流媒体播放) @@ -593,7 +593,7 @@ export default { try { // 检查浏览器是否支持流媒体 const supportsStreaming = this.checkStreamingSupport(); - + if (supportsStreaming) { // 方式一:直接打开视频URL(支持流媒体) // 创建一个带有视频标签的页面,使用流式加载 @@ -670,7 +670,9 @@ export default { } } else { // 方式二:回退到直接下载或提示用户 - this.$modal.msgWarning("您的浏览器可能不支持视频流媒体播放,正在尝试直接打开..."); + this.$modal.msgWarning( + "您的浏览器可能不支持视频流媒体播放,正在尝试直接打开..." + ); window.open(videoUrl, "_blank"); } } catch (error) { @@ -682,9 +684,13 @@ export default { // 检查浏览器流媒体支持 checkStreamingSupport() { try { - const video = document.createElement('video'); + const video = document.createElement("video"); // 检查是否支持媒体源扩展(MSE) - return !!window.MediaSource || video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"') === 'probably'; + return ( + !!window.MediaSource || + video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"') === + "probably" + ); } catch (e) { return true; // 默认假设支持 } @@ -824,7 +830,7 @@ export default { } return { valid: true, message: "" }; }, - // 文件大小验证(根据需求启用) + // 文件大小验证(根据需求启用) validateFileSize(size) { // 例如:限制最大100MB const maxSize = 100 * 1024 * 1024; @@ -861,7 +867,14 @@ export default { file, {}, (percent) => { + // 更新界面进度 this.uploadPercent = percent; + // 更新传输记录进度(用于工具页面显示) + if (recordId) { + this.updateTransferProgress(recordId, percent); + // 触发自定义事件通知工具页面更新 + this.notifyTransferProgress(recordId, percent); + } } ); @@ -943,7 +956,7 @@ export default { }, // 创建初始上传记录(文件选择时调用,无论成功失败都会保存) createTransferRecord(file) { - const STORAGE_KEY = "file_transfer_records"; + const STORAGE_KEY = "file_transfer_records" + this.userInfo.id; try { // 获取现有记录 const existingData = localStorage.getItem(STORAGE_KEY); @@ -979,7 +992,7 @@ export default { }, // 更新上传记录状态 updateTransferRecord(recordId, isSuccess, fileUrl = "") { - const STORAGE_KEY = "file_transfer_records"; + const STORAGE_KEY = "file_transfer_records" + this.userInfo.id; try { // 获取现有记录 const existingData = localStorage.getItem(STORAGE_KEY); @@ -999,11 +1012,76 @@ export default { // 保存回 localStorage localStorage.setItem(STORAGE_KEY, JSON.stringify(records)); console.log("上传记录已更新:", records[recordIndex]); + // 通知工具页面更新 + this.notifyTransferUpdate(); } } catch (e) { console.error("更新上传记录失败", e); } }, + + // 更新上传进度 + updateTransferProgress(recordId, percent) { + const STORAGE_KEY = "file_transfer_records" + this.userInfo.id; + 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].upload_percent = percent; + records[recordIndex].is_uploading = percent < 100; + // 保存回 localStorage + localStorage.setItem(STORAGE_KEY, JSON.stringify(records)); + } + } catch (e) { + console.error("更新上传进度失败", e); + } + }, + + // 通知工具页面更新传输记录 + notifyTransferUpdate() { + try { + // 创建自定义事件 + const event = new CustomEvent("transferRecordsUpdate", { + detail: { + userId: this.userInfo.id, + }, + bubbles: true, + composed: true, + }); + // 触发事件 + window.dispatchEvent(event); + console.log("Notified transfer records update"); + } catch (e) { + console.error("Failed to notify transfer update", e); + } + }, + + // 通知工具页面更新传输进度 + notifyTransferProgress(recordId, percent) { + try { + // 创建自定义事件 + const event = new CustomEvent("transferProgressUpdate", { + detail: { + recordId, + percent, + userId: this.userInfo.id, + }, + bubbles: true, + composed: true, + }); + // 触发事件 + window.dispatchEvent(event); + console.log(`Notified transfer progress: ${recordId} - ${percent}%`); + } catch (e) { + console.error("Failed to notify transfer progress", e); + } + }, }, }; diff --git a/src/views/utility/index.vue b/src/views/utility/index.vue index e16aece..254118c 100644 --- a/src/views/utility/index.vue +++ b/src/views/utility/index.vue @@ -120,6 +120,7 @@