知识库-上传文件在工具页面实时联动

main
ysn 4 days ago
parent 6cf5b20cc9
commit 71f75080a8
  1. 92
      src/views/knowledge/index.vue
  2. 28
      src/views/utility/index.vue

@ -579,13 +579,13 @@ export default {
// //
this.createVideoPlayer(videoUrl, row.title || "视频播放"); this.createVideoPlayer(videoUrl, row.title || "视频播放");
} }
}) });
} else { } else {
postKnowledgePlay({ knowledge_id: row.id }).then((res) => { postKnowledgePlay({ knowledge_id: row.id }).then((res) => {
if (res.code === 200) { if (res.code === 200) {
window.open(this.getFullFilePath(row.file_path), "_blank"); window.open(this.getFullFilePath(row.file_path), "_blank");
} }
}) });
} }
}, },
// //
@ -670,7 +670,9 @@ export default {
} }
} else { } else {
// 退 // 退
this.$modal.msgWarning("您的浏览器可能不支持视频流媒体播放,正在尝试直接打开..."); this.$modal.msgWarning(
"您的浏览器可能不支持视频流媒体播放,正在尝试直接打开..."
);
window.open(videoUrl, "_blank"); window.open(videoUrl, "_blank");
} }
} catch (error) { } catch (error) {
@ -682,9 +684,13 @@ export default {
// //
checkStreamingSupport() { checkStreamingSupport() {
try { try {
const video = document.createElement('video'); const video = document.createElement("video");
// MSE // 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) { } catch (e) {
return true; // return true; //
} }
@ -861,7 +867,14 @@ export default {
file, file,
{}, {},
(percent) => { (percent) => {
//
this.uploadPercent = percent; this.uploadPercent = percent;
//
if (recordId) {
this.updateTransferProgress(recordId, percent);
//
this.notifyTransferProgress(recordId, percent);
}
} }
); );
@ -943,7 +956,7 @@ export default {
}, },
// //
createTransferRecord(file) { createTransferRecord(file) {
const STORAGE_KEY = "file_transfer_records"; const STORAGE_KEY = "file_transfer_records" + this.userInfo.id;
try { try {
// //
const existingData = localStorage.getItem(STORAGE_KEY); const existingData = localStorage.getItem(STORAGE_KEY);
@ -979,7 +992,7 @@ export default {
}, },
// //
updateTransferRecord(recordId, isSuccess, fileUrl = "") { updateTransferRecord(recordId, isSuccess, fileUrl = "") {
const STORAGE_KEY = "file_transfer_records"; const STORAGE_KEY = "file_transfer_records" + this.userInfo.id;
try { try {
// //
const existingData = localStorage.getItem(STORAGE_KEY); const existingData = localStorage.getItem(STORAGE_KEY);
@ -999,11 +1012,76 @@ export default {
// localStorage // localStorage
localStorage.setItem(STORAGE_KEY, JSON.stringify(records)); localStorage.setItem(STORAGE_KEY, JSON.stringify(records));
console.log("上传记录已更新:", records[recordIndex]); console.log("上传记录已更新:", records[recordIndex]);
//
this.notifyTransferUpdate();
} }
} catch (e) { } catch (e) {
console.error("更新上传记录失败", 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);
}
},
}, },
}; };
</script> </script>

@ -120,6 +120,7 @@
</template> </template>
<script> <script>
const STORAGE_KEY = "file_transfer_records"; const STORAGE_KEY = "file_transfer_records";
import { mapGetters } from "vuex";
export default { export default {
name: "UtilityPage", name: "UtilityPage",
data() { data() {
@ -129,6 +130,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(["userInfo"]),
// Qt DisplayFiletransferinfo // Qt DisplayFiletransferinfo
groupedRecords() { groupedRecords() {
const groups = {}; const groups = {};
@ -147,13 +149,21 @@ export default {
}, },
mounted() { mounted() {
this.loadTransferRecords(); this.loadTransferRecords();
//
window.addEventListener('transferRecordsUpdate', this.handleTransferUpdate);
window.addEventListener('transferProgressUpdate', this.handleTransferProgress);
},
beforeUnmount() {
//
window.removeEventListener('transferRecordsUpdate', this.handleTransferUpdate);
window.removeEventListener('transferProgressUpdate', this.handleTransferProgress);
}, },
methods: { methods: {
// localStorage Qt SQLite // localStorage Qt SQLite
loadTransferRecords() { loadTransferRecords() {
this.loading = true; this.loading = true;
try { try {
const data = localStorage.getItem(STORAGE_KEY); const data = localStorage.getItem(STORAGE_KEY + this.userInfo.id);
if (data) { if (data) {
this.transferRecords = JSON.parse(data); this.transferRecords = JSON.parse(data);
} }
@ -339,6 +349,22 @@ export default {
this.saveTransferRecords(); this.saveTransferRecords();
} }
}, },
//
handleTransferUpdate(e) {
console.log('Transfer records update received:', e.detail);
this.loadTransferRecords();
},
//
handleTransferProgress(e) {
const { recordId, percent, userId } = e.detail;
console.log(`Transfer progress update: ${recordId} - ${percent}%`);
//
if (userId === this.userInfo?.id) {
this.loadTransferRecords();
}
},
}, },
}; };
</script> </script>

Loading…
Cancel
Save