/* * @Author: LinLong * @LastEditors: LinLong * @Description: 上课进度上传 */ import { ref, onMounted, onUnmounted } from 'vue' import { getItem, setItem } from '@/hooks' import { uselearningProgress } from '@/stores' import { updatedLearningProgress } from '@/apiList/learningProgress' const learningProgressStore = uselearningProgress() //学习进度仓库 const currentProgressFile = ref(null) //当前学习进度文件 const heartbeatTime = 30 * 1000 //30秒 let timer = null //时间函数 export function useClassProgress(onBeforeRouteLeave) { //从仓库获取用户点击的课程->项目->任务->文件 learningProgressStore.$subscribe((mutation, state) => { const { currentProgress } = state // console.log('%c--currentProgress-->', 'background:#18C36E;color:#3F4040;', currentProgress) currentProgressFile.value = { classId: currentProgress.classId, courseId: currentProgress.courseId, courseId_text: currentProgress.courseId_text, projectId: currentProgress.pid == 0 ? currentProgress.id : currentProgress.pid, // projectId: currentProgress.id, taskId: currentProgress.pid == 0 ? null : currentProgress.id, pid_text: currentProgress.pid_text, name: currentProgress.name, file: currentProgress.url, userId: getItem('userInfo').id, } // console.log('%c-----state 学习进度------->', 'background:#18C36E;color:#3F4040;', currentProgress) }) //生命周期页面挂载完毕 onMounted(() => { //接收iframe 异步框架消息 window.addEventListener('message', (e) => { if (e.origin.includes('8013')) { const data = e.data setItem('postMessage', data) // console.log('%c-----监听postMessage子级------->', 'background:#18C36E;color:#3F4040;', JSON.parse(data)) } }) //浏览器tab标签切换或最小化事件设置暂停提交 上课记录 document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'hidden') { timer ? clearTimeout(timer) : (timer = null) //清除定时器 } else if (document.visibilityState === 'visible') { timer ? clearTimeout(timer) : (timer = null) //先清除一次定时器 sendMessage() //继续发送学习进度 } }) //发送统计信息至后端 sendMessage() function sendMessage() { console.log('%c---对方水电费水电费水电费->', 'background:#18C36E;color:#3F4040;') timer ? clearTimeout(timer) : (timer = false) //先清除一次定时器 timer = setTimeout(() => { const sendData = { ...getItem('postMessage'), ...currentProgressFile.value, } // console.log('%c------准备发送的信息sendData------>', 'background:#18C36E;color:#3F4040;', sendData) updatedLearningProgress(sendData).then((res) => { if (res.success) sendMessage() }) }, heartbeatTime) //heartbeatTime } }) //生命周期页面销毁之前 onUnmounted(() => { clearTimeout(timer) // //路由离开 // onBeforeRouteLeave(() => { // clearTimeout(timer) // }) }) }
时间: 2023-06-03 14:06:42 浏览: 176
amems:航空维修工程管理系统
null是一个常见的编程术语,表示空值或空对象。在程序中,null通常表示变量或对象不存在或没有被初始化。在Java等语言中,null也可以作为一种特殊的引用类型,与其他引用类型不同的是,它不能指向任何实际的对象。
阅读全文