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

main
ysn 3 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 || "视频播放");
}
})
});
} else {
postKnowledgePlay({ knowledge_id: row.id }).then((res) => {
if (res.code === 200) {
window.open(this.getFullFilePath(row.file_path), "_blank");
}
})
});
}
},
//
@ -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; //
}
@ -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);
}
},
},
};
</script>

@ -120,6 +120,7 @@
</template>
<script>
const STORAGE_KEY = "file_transfer_records";
import { mapGetters } from "vuex";
export default {
name: "UtilityPage",
data() {
@ -129,6 +130,7 @@ export default {
};
},
computed: {
...mapGetters(["userInfo"]),
// Qt DisplayFiletransferinfo
groupedRecords() {
const groups = {};
@ -147,13 +149,21 @@ export default {
},
mounted() {
this.loadTransferRecords();
//
window.addEventListener('transferRecordsUpdate', this.handleTransferUpdate);
window.addEventListener('transferProgressUpdate', this.handleTransferProgress);
},
beforeUnmount() {
//
window.removeEventListener('transferRecordsUpdate', this.handleTransferUpdate);
window.removeEventListener('transferProgressUpdate', this.handleTransferProgress);
},
methods: {
// localStorage Qt SQLite
loadTransferRecords() {
this.loading = true;
try {
const data = localStorage.getItem(STORAGE_KEY);
const data = localStorage.getItem(STORAGE_KEY + this.userInfo.id);
if (data) {
this.transferRecords = JSON.parse(data);
}
@ -339,6 +349,22 @@ export default {
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>

Loading…
Cancel
Save