guoyu/frontend-uniapp/dist/build/h5/assets/pages-course-detail.Cxv9sB-l.js

2 lines
12 KiB
JavaScript
Raw Normal View History

2025-11-14 17:34:32 +08:00
import{E as e,l as t,s,G as o,H as i,I as r,J as a,_ as n,c as l,w as d,C as u,K as c,L as h,M as p,i as g,r as f,y as w,d as m,o as y,z as v,h as T,N as I,O as P,j as U,k as C,P as D,Q as R,u as _,D as S}from"./index-LOi95lww.js";const k=new class{constructor(){this.screenshotTimer=null,this.uploadQueue=[],this.isUploading=!1,this.interval=3e4,this.currentCourseId=null,this.isEnabled=!1}start(e=null,t=3e4){this.isEnabled?console.log("监控已启动"):(this.currentCourseId=e,this.interval=t,this.isEnabled=!0,console.log("启动学习监控,间隔:",t/1e3,"秒"),this.captureAndUpload(),this.screenshotTimer=setInterval(()=>{this.isEnabled&&this.captureAndUpload()},this.interval))}stop(){this.isEnabled=!1,this.screenshotTimer&&(clearInterval(this.screenshotTimer),this.screenshotTimer=null),console.log("学习监控已停止")}setCourseId(e){this.currentCourseId=e}async captureAndUpload(){try{if("none"===await this.getNetworkType())return void console.log("网络未连接,跳过截图上传");const e=await this.captureScreenshot();if(!e)return void console.log("截图失败");this.uploadQueue.push({filePath:e,courseId:this.currentCourseId,timestamp:Date.now()}),this.processUploadQueue()}catch(e){console.error("截图上传失败:",e)}}captureScreenshot(){return new Promise((e,t)=>{this.captureScreenshotH5(e,t)})}captureScreenshotApp(e,t){t(new Error("App环境不可用"))}captureScreenshotH5(e,t){try{const t=document.createElement("canvas"),s=t.getContext("2d");t.width=window.innerWidth,t.height=window.innerHeight,s.fillStyle="#fff",s.fillRect(0,0,t.width,t.height),s.fillStyle="#000",s.font="16px Arial",s.fillText("学习监控截图",20,40),s.fillText((new Date).toLocaleString(),20,60),s.fillText("H5环境截图功能有限",20,80),t.toBlob(t=>{const s=URL.createObjectURL(t);e(s)},"image/png",.8)}catch(s){console.error("H5截图失败:",s),t(s)}}getNetworkType(){return new Promise(t=>{e({success:e=>{t(e.networkType)},fail:()=>{t("unknown")}})})}async processUploadQueue(){if(!this.isUploading&&0!==this.uploadQueue.length){for(this.isUploading=!0;this.uploadQueue.length>0;){const t=this.uploadQueue.shift();try{await this.uploadScreenshot(t.filePath,t.courseId),console.log("截图上传成功")}catch(e){console.error("截图上传失败:",e),void 0===t.retryCount&&(t.retryCount=0),t.retryCount<3&&(t.retryCount++,this.uploadQueue.push(t))}}this.isUploading=!1}}async uploadScreenshot(e,s=null){const o={};return s&&(o.courseId=s),await t.upload("/study/monitor/screenshot",e,o,{name:"file"})}async manualCapture(){try{const e=await this.captureScreenshot();e&&(await this.uploadScreenshot(e,this.currentCourseId),s({title:"截图上传成功",icon:"success"}))}catch(e){s({title:"截图失败",icon:"none"}),console.error("手动截图失败:",e)}}};const L=new class{constructor(){this.queue=[],this.isUploading=!1,this.retryCount=0,this.maxRetryCount=3,this.uploadInterval=5e3,this.uploadTimer=null,this.storageKey="learning_progress_queue",this.isOnline=!0,this.initNetworkListener(),this.loadFromStorage()}initNetworkListener(){o(e=>{const t=!this.isOnline;this.isOnline=e.isConnected,t&&this.isOnline?(console.log("网络已恢复,开始上传队列"),this.processQueue()):this.isOnline||console.log("网络已断开,暂停上传")}),e({success:e=>{this.isOnline="none"!==e.networkType}})}addProgress(e){const t={id:Date.now()+Math.random(),courseId:e.courseId,duration:e.duration||0,videoPosition:e.videoPosition||0,videoTotalDuration:e.videoTotalDuration||0,timestamp:Date.now()},s=this.queue.findIndex(e=>e.courseId===t.courseId&&!e.uploaded);if(s>=0){const e=this.queue[s];e.duration=(e.duration||0)+(t.duration||0),e.videoPosition=t.videoPosition,e.videoTotalDuration=t.videoTotalDuration,e.timestamp=t.timestamp}else this.queue.push(t);this.saveToStorage(),this.isOnline&&this.processQueue()}async processQueue(){if(this.isUploading||!this.isOnline||0===this.queue.length)return;this.isUploading=!0;const e=this.queue.filter(e=>!e.uploaded);if(0===e.length)return void(this.isUploading=!1);const t=[];for(let o=0;o<e.length;o+=5)t.push(e.