From 45abab7a4179ef8e3bbbb4069ea574856770ebf6 Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 19 Dec 2024 11:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=B1=8F=E4=B8=8A=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/AixPPTist/src/api/chat.ts | 7 ++ .../src/AixPPTist/src/api/classcourse.ts | 9 ++- .../src/views/Screen/hooks/useExecPlay.ts | 14 ++-- .../views/prepare/container/class-start.vue | 18 +++-- src/renderer/src/views/prepare/index.vue | 68 +++++++++++++------ 5 files changed, 83 insertions(+), 33 deletions(-) diff --git a/src/renderer/src/AixPPTist/src/api/chat.ts b/src/renderer/src/AixPPTist/src/api/chat.ts index 6cf016e..8557f27 100644 --- a/src/renderer/src/AixPPTist/src/api/chat.ts +++ b/src/renderer/src/AixPPTist/src/api/chat.ts @@ -8,8 +8,15 @@ import * as API_classcourse from '@/api/teaching/classcourse' // 后端api export default () => { const classcourse = sessionStore.get('curr.classcourse') // 课堂信息 + const courseId = classcourse?.id // 课堂id const timgroupid = classcourse?.timgroupid // 群组id if (!ChatWs.ws) ChatWs.init() + // 开课消息 + const startCourse = async() => { + // await API_classcourse.updateClasscourse({ id: classcourse.id, status: 'open' }) + ChatWs.sendMsg('open', {id: courseId}) + return Promise.resolve() + } // 下课消息 const exitCourse = async() => { if(!timgroupid) throw new Error('未获取到群组ID') diff --git a/src/renderer/src/AixPPTist/src/api/classcourse.ts b/src/renderer/src/AixPPTist/src/api/classcourse.ts index 21e7296..e93fb0f 100644 --- a/src/renderer/src/AixPPTist/src/api/classcourse.ts +++ b/src/renderer/src/AixPPTist/src/api/classcourse.ts @@ -14,6 +14,7 @@ const slidesStore = useStore.useSlidesStore() // 幻灯片-状态管理 const screenStore = useStore.useScreenStore() // 全屏-状态管理 const classcourseStore = useStore.useClasscourseStore() // 课堂信息-状态管理 const classcourse = sessionStore.get('curr.classcourse') // 课堂信息 +const isPublic = sessionStore.get('curr.isPublic') // 是否公屏开课 export class Classcourse { msgObj:ElMessageBox = null // 提示消息对象 @@ -36,8 +37,14 @@ export class Classcourse { // 如果课堂信息有值,则连接socket if (isCourse) { // 连接socket - if (!ChatWs.ws) ChatWs.init() ChatWs.id = classcourse.timgroupid // 群组id + if (!ChatWs.ws) { + ChatWs.init().then(_ => { + console.log('socket-加载成功') + isPublic && ChatWs.sendMsg('open', {id: classcourse.id}) + isPublic && console.log('socket-开课消息-已发送') + }) + } this.classcourse = classcourse // 课堂信息 this.id = classcourse.id // 课堂id // 如果课堂信息有paging,则更新当前页码 diff --git a/src/renderer/src/AixPPTist/src/views/Screen/hooks/useExecPlay.ts b/src/renderer/src/AixPPTist/src/views/Screen/hooks/useExecPlay.ts index 860e37a..3838c08 100644 --- a/src/renderer/src/AixPPTist/src/views/Screen/hooks/useExecPlay.ts +++ b/src/renderer/src/AixPPTist/src/views/Screen/hooks/useExecPlay.ts @@ -6,6 +6,8 @@ import { KEYS } from '../../../configs/hotkey' import { ANIMATION_CLASS_PREFIX } from '../../../configs/animation' import message from '../../../utils/message' import emitter from '@/utils/mitt'; +import ChatWs from '@/plugins/socket' // 聊天socket +import { MsgEnum } from '../../../api/types' // 消息枚举 export default () => { const slidesStore = useSlidesStore() @@ -178,8 +180,7 @@ export default () => { // 鼠标滚动翻页 const mousewheelListener = (e: WheelEvent) => { // console.log('mousewheel', e) - // 课堂信息存在时,不允许翻页 - if (!!classcourseStore.classcourse) e.preventDefault() + e.preventDefault() // 阻止默认事件 mousewheelListenerThrottle(e) } const mousewheelListenerThrottle = throttle(function(e: WheelEvent) { @@ -212,10 +213,15 @@ export default () => { // 向上翻页/向下翻页 const turning = (e, type) => { e.preventDefault() // 阻止默认事件 - // 课堂信息存在时,不允许翻页 - if (!!classcourseStore.classcourse) return if (type === 'prev') execPrev() else if (type === 'next') execNext() + // 发送sokcet消息 + const isSend = classcourseStore.classcourse && !!ChatWs.ws && ChatWs.ws.readyState === 1 + console.log('isSend', isSend, ChatWs.ws.readyState) + if (isSend) { // 有课堂信息,发送,没有就是编辑状态 + // const head = MsgEnum.HEADS.MSG_slideFlapping + // ChatWs.sendMsg(head, {type}) + } } // 快捷键翻页 const keydownListener = (e: KeyboardEvent) => { diff --git a/src/renderer/src/views/prepare/container/class-start.vue b/src/renderer/src/views/prepare/container/class-start.vue index c9c518b..774facc 100644 --- a/src/renderer/src/views/prepare/container/class-start.vue +++ b/src/renderer/src/views/prepare/container/class-start.vue @@ -62,6 +62,7 @@
开始新的课堂,需要点击先创建课堂,才能显示手机二维码
开始新的课堂,需要点击先创建课堂
创建课堂 + 公屏上课 @@ -146,7 +147,7 @@ const open = async (id, classObj) => { await getAptInfo(id) // 获取班级列表 getClassList() - console.log('classObj', classObj) + // console.log('classObj', classObj) // 继续上课 if (!!classObj) { dt.ctCourse = classObj @@ -245,8 +246,8 @@ const getClasscourseList = async type => { } } } -// 创建课程 -const createClasscourse = async () => { +// 创建课程 isPublic 公屏上课 +const createClasscourse = async (isPublic = false) => { const { classid } = classForm.form if (!classid) { ElMessage.warning('请选择班级') @@ -255,8 +256,8 @@ const createClasscourse = async () => { dt.loading = true const { entpcourseid, evalid, id, coursetitle } = myClassActive.value // 课件对象 const curDate = commUtil.getDateNow('yyyy-MM-dd') - const params = { - id: 0, coursetype: '', courseverid: 0, coursedesc: '', status: '', + const params = { // 公屏上课直接 status = open + id: 0, coursetype: '', courseverid: 0, coursedesc: '', status: isPublic?'open':'', teacherid: userStore.id, entpcoursefileid: id, classid, entpcourseid, evalid, coursetitle, plandate: curDate, opendate: curDate @@ -274,7 +275,7 @@ const createClasscourse = async () => { setTimeout(async() => { msgEl.close() const res = await Http_Classcourse.getClasscourse(teacherForm.form.classcourseid) - openPublicScreen(res.data) + openPublicScreen(res.data, isPublic) }, 2000); }, 1000); } @@ -355,7 +356,7 @@ const getQrUrl = async() => { } // 打开公屏 -const openPublicScreen = (classcourse) => { +const openPublicScreen = (classcourse, isPublic) => { console.log('打开公屏', classcourse) if (!dt.ctCourse) { // 新开课需要发送消息-继续上课不需要直接打开 // 发送app端待开课消息 @@ -366,11 +367,14 @@ const openPublicScreen = (classcourse) => { const resource = toRaw(myClassActive.value) sessionStore.set('curr.resource', resource) // 缓存当前资源信息 sessionStore.set('curr.classcourse', classcourse) // 缓存当前当前上课 + // 公屏开课 + sessionStore.set('curr.isPublic', isPublic) // 缓存是否公屏开课 createWindow('open-win', { url: '/pptist', // 窗口关闭时,清除缓存 close: () => { sessionStore.set('curr.resource', null) // 清除缓存 sessionStore.set('curr.classcourse', null) // 清除缓存 + sessionStore.set('curr.isPublic', null) // 清除缓存 } }) visible.value = false // 关闭弹窗 diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index c593d06..3ab235a 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -367,7 +367,8 @@ export default { this.$refs.calssRef.open(item.fileId, classObj) } if(item.fileFlag === 'aippt') { - this.$refs.calssRef.open(item.fileId, classObj) + if (!!classObj) this.changeClass('continue', classObj) // 继续上课 + else this.$refs.calssRef.open(item.fileId, classObj) // 新开课 } }, // 继续上课-apt @@ -375,7 +376,18 @@ export default { switch(type) { case 'continue': { // 继续上课 const aptFileId = row.entpcoursefileid - this.$refs.calssRef.open(aptFileId, row) + const res = await getEntpcoursefile(aptFileId) + if (res.code == 200) { + const resource = res.data + if (resource.filetype != 'aippt') this.$refs.calssRef.open(aptFileId, row) + else { + const msgEl = ElMessage.warning({message:'正在打开公屏,请稍后...',duration: 0}) + setTimeout(()=>{ + msgEl.close() + this.openPublicScreen('class', resource, row) // 打开公屏-窗口 + }, 2000) + } + } else ElMessage.error(res.msg||'获取课件信息失败') break } case 'close': { // 关闭上课 @@ -428,16 +440,7 @@ export default { if (row.fileFlag === 'aippt' && !!row.fileId) { const res = await getEntpcoursefile(row.fileId) if (res && res.code === 200) { - sessionStore.set('curr.resource', res.data) // 缓存当前资源信息 - sessionStore.set('curr.smarttalk', row) // 缓存当前文件smarttalk - createWindow('open-win', { - url: '/pptist', // 窗口关闭时,清除缓存 - close: () => { - sessionStore.set('curr.resource', null) // 清除缓存 - sessionStore.set('curr.smarttalk', null) // 清除缓存 - this.asyncAllFile() // 刷新资源列表 - } - }) + this.openPublicScreen('edit', res.data, row) // 打开公屏-窗口 } else { ElMessage.warning(res.msg||'文件获取异常!') } @@ -462,21 +465,44 @@ export default { msgEl.close() // 关闭提示 const resource = res?.data||{} const classcourse = row - sessionStore.set('curr.resource', resource) // 缓存当前资源信息 - sessionStore.set('curr.classcourse', classcourse) // 缓存当前当前上课 - createWindow('open-win', { - url: '/pptist', // 窗口关闭时,清除缓存 - close: () => { - sessionStore.set('curr.resource', null) // 清除缓存 - sessionStore.set('curr.classcourse', null) // 清除缓存 - } - }) + this.openPublicScreen('class',resource, classcourse) // 打开公屏-窗口 + // sessionStore.set('curr.resource', resource) // 缓存当前资源信息 + // sessionStore.set('curr.classcourse', classcourse) // 缓存当前当前上课 + // createWindow('open-win', { + // url: '/pptist', // 窗口关闭时,清除缓存 + // close: () => { + // sessionStore.set('curr.resource', null) // 清除缓存 + // sessionStore.set('curr.classcourse', null) // 清除缓存 + // } + // }) break } default: break } }, + /** + * description 打开公屏 + * @param {string} type 类型 edit 打开 class 上课 + * @param {object} resource 资源信息 + * @param {object} currData 当前数据 type: edit/class 备课信息 | 课堂信息 + */ + openPublicScreen(type, resource, currData) { + sessionStore.set('curr.resource', resource) // 缓存当前资源信息 + if (type=='edit') sessionStore.set('curr.smarttalk', currData) // 缓存当前文件smarttalk + else sessionStore.set('curr.classcourse', currData) // 缓存当前当前上课 + createWindow('open-win', { + url: '/pptist', // 窗口关闭时,清除缓存 + close: () => { + sessionStore.set('curr.resource', null) // 清除缓存 + if (type=='edit') { + sessionStore.set('curr.smarttalk', null) // 清除缓存 + this.asyncAllFile() // 刷新资源列表 + } else sessionStore.set('curr.classcourse', null) // 清除缓存 + } + }) + }, + closeChange() { // 上课弹窗被关闭-触发 // console.log('关闭上课弹窗') // this.activeClass = null