diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index a83cbd1..9ba4abc 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -222,9 +222,11 @@ export const createWindow = async (type, data) => { if (import.meta.env.VITE_SHOW_DEV_TOOLS === 'true') win.webContents.openDevTools() // 打开调试工具 let events = {} // 事件处理函数对象 Object.keys(data) - .filter(k => typeof data[k] === 'function') + .filter(k => typeof data[k] === 'function' && k!=='success') .forEach(k => events[k] = data[k]) eventHandles(type, win, events) // 事件监听处理 + // 创建成功后触发回调 + data.success && data.success(win) return win } default: @@ -306,9 +308,9 @@ const eventHandles = (type, win, events) => { // 监听主窗口-关闭事件 mainWin.once('close', () => {winPdf=null;win.destroy();}) win.on('closed', () => { - if(!!onClosed) onClosed() // 自定义关闭事件 - if(!!closed) closed() // 自定义关闭事件 - if(!!close) close() // 自定义关闭事件 + if(!!onClosed) onClosed(win) // 自定义关闭事件 + if(!!closed) closed(win) // 自定义关闭事件 + if(!!close) close(win) // 自定义关闭事件 win = null wins_tool = null winChild=null diff --git a/src/renderer/src/views/model/index.vue b/src/renderer/src/views/model/index.vue index 70bafe7..6ceca61 100644 --- a/src/renderer/src/views/model/index.vue +++ b/src/renderer/src/views/model/index.vue @@ -288,14 +288,17 @@ const createAIPPT = () => { }) }) } - +const isPgDialogClose = ref(false) // 弹窗-进度条-是否关闭 const pgDialog = ref({ // 弹窗-进度条 visible: false, title: 'PPT解析中...', width: 300, - showClose: false, + showClose: true, draggable: true, - beforeClose: done => {}, // 阻止-弹窗事件 + beforeClose: done => { // 弹窗关闭前回调 + isPgDialogClose.value = true + done() + }, pg: { // 进度条-参数 percentage: 0, // 百分比 color: [ @@ -316,20 +319,26 @@ const openFilePicker = () =>{ const handleFileChange = ()=> { const file = event.target.files[0]; + fileInput.value.value = '' if (file) { - console.log(file); createAIPPTByFile(file) } } // ppt文件转PPT线上数据 const createAIPPTByFile = async (file)=> { + isPgDialogClose.value = false // 默认没有关闭 pgDialog.value.visible = true pgDialog.value.pg.percentage = 0 + const closePgDialog = () => { + pgDialog.value.pg.percentage = 0 + pgDialog.value.visible = false + } pptMedia = {} // 清空媒体数据 const resPptJson = await PPTXFileToJson(file).catch(() => { ElMessageBox.alert('PPT文件转换失败!请点击素材右侧...下载文件后打开另存为PPTX文件格式再进行导入!') pgDialog.value.visible = false }) + if(isPgDialogClose.value) return closePgDialog() // 弹窗关闭了,终止进行 const { def, slides, ...content } = resPptJson // 生成缩略图 const thumbnails = await slidesToImg(slides, content.width) @@ -337,13 +346,13 @@ const createAIPPTByFile = async (file)=> { let completed = 0 const total = slides.length for( let o of slides ) { + if(isPgDialogClose.value) return closePgDialog() // 弹窗关闭了,终止进行 completed++ await toRousrceUrl(o) // 设置进度条 pgDialog.value.pg.percentage = Math.floor(completed / total * 100) } - pgDialog.value.pg.percentage = 0 - pgDialog.value.visible = false + closePgDialog() // 关闭进度条弹窗 listEntpcourse({ evalid: currentNode.value.id, edituserid: userStore.userId, @@ -564,13 +573,38 @@ const changeClass = async (type, row, other) => { switch(type) { case 'click': { // 点击-打开课件-aippt if (row.fileFlag === 'aippt' && !!row.fileId) { + const id = Number(row.fileId) + const openFileIds = sessionStore.get('curr.openFileIds')||[] // 已打开课件列表id + const isHasOpen = openFileIds.includes(id) // 是否已打开 + if (isHasOpen) return ElMessage.warning('该课件已打开!') const res = await getEntpcoursefile(row.fileId) if (res && res.code === 200) { + openFileIds.push(id) // 课堂资源缓存-允许打开多个 + sessionStore.set('curr.openFileIds', openFileIds) // 更新窗口课件列表id sessionStore.set('curr.resource', res.data) // 缓存当前资源信息 sessionStore.set('curr.smarttalk', row) // 缓存当前文件smarttalk createWindow('open-win', { url: '/pptist', // 窗口关闭时,清除缓存 - close: () => { + success: (win) => { // 窗口打开成功 + const map = sessionStore.get('curr.winMap') || {} + map[win.id] = id // 将当前窗口id和课件id进行关联 + sessionStore.set('curr.winMap', map) + }, + close: (win) => { + const openFileIds = sessionStore.get('curr.openFileIds')||[] // 已打开课件列表id + const map = sessionStore.get('curr.winMap') || {} + const resourceId = map[win.id] // 当前窗口关联的课件id + if (resourceId){ + const ind = openFileIds.findIndex(id => id == resourceId) // 是否存在打开的课件 + if (ind >= 0) { // 存在打开的课件 + openFileIds.splice(ind, 1) // 删除关联课件 + if (openFileIds.length) sessionStore.set('curr.openFileIds', openFileIds) // 更新窗口课件列表 + else sessionStore.delete('curr.openFileIds') // 清除缓存 + delete map[win.id] // 删除 当前窗口课件关联 + if(Object.keys(map).length) sessionStore.set('curr.winMap', map) // 更新窗口课件关联 + else sessionStore.delete('curr.winMap') // 清除缓存 + } + } sessionStore.delete('curr.resource') // 清除缓存 sessionStore.delete('curr.smarttalk') // 清除缓存 getSmarttalkPage({ diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index 8a9d5c6..444a4bb 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -274,13 +274,17 @@ export default { treelogRef:null, // 获取当前章节对应的课程信息 Entpcourse entp: null, + isPgDialogClose: false, // 关闭进度条弹窗 pgDialog: { // 弹窗-进度条 visible: false, title: 'PPT解析中...', width: 300, - showClose: false, + showClose: true, draggable: true, - beforeClose: done => {}, // 阻止-弹窗事件 + beforeClose: done => { // 弹窗关闭前回调 + this.isPgDialogClose = true + done() + }, pg: { // 进度条-参数 percentage: 0, // 百分比 color: [ @@ -453,6 +457,9 @@ export default { } case 'click': { // 点击-打开课件-aippt if (row.fileFlag === 'aippt' && !!row.fileId) { + const openFileIds = sessionStore.get('curr.openFileIds')||[] // 已打开课件列表id + const isHasOpen = openFileIds.includes(Number(row.fileId)) // 是否已打开 + if (isHasOpen) return ElMessage.warning('该课件已打开!') sessionStore.delete('curr.classcourse') // 清除上课相关信息 const res = await getEntpcoursefile(row.fileId) if (res && res.code === 200) { @@ -496,12 +503,37 @@ export default { * @param {object} currData 当前数据 type: edit/class 备课信息 | 课堂信息 */ openPublicScreen(type, resource, currData) { + const openFileIds = sessionStore.get('curr.openFileIds')||[] + const isNoOpen = !openFileIds.includes(Number(resource.id)) // 是否不存在 + if (isNoOpen) { + openFileIds.push(resource.id) // 课堂资源缓存-允许打开多个 + sessionStore.set('curr.openFileIds', openFileIds) // 更新窗口课件列表id + } 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: () => { + success: (win) => { // 窗口打开成功 + const map = sessionStore.get('curr.winMap') || {} + map[win.id] = resource.id // 将当前窗口id和课件id进行关联 + sessionStore.set('curr.winMap', map) + }, + close: (win) => { + const openFileIds = sessionStore.get('curr.openFileIds')||[] // 课件列表 + const map = sessionStore.get('curr.winMap') || {} + const resourceId = map[win.id] // 当前窗口关联的课件id + if (resourceId){ + const ind = openFileIds.findIndex(id => id == resourceId) // 是否存在打开的课件 + if (ind >= 0) { // 存在打开的课件 + openFileIds.splice(ind, 1) // 删除关联课件 + if (openFileIds.length) sessionStore.set('curr.openFileIds', openFileIds) // 更新窗口课件列表 + else sessionStore.delete('curr.openFileIds') // 清除缓存 + delete map[win.id] // 删除 当前窗口课件关联 + if(Object.keys(map).length) sessionStore.set('curr.winMap', map) // 更新窗口课件关联 + else sessionStore.delete('curr.winMap') // 清除缓存 + } + } sessionStore.delete('curr.resource') // 清除缓存 if (type=='edit') { sessionStore.delete('curr.smarttalk') // 清除缓存 @@ -584,6 +616,7 @@ export default { }, handleFileChange(){ const file = event.target.files[0]; + this.$refs.fileInput.value = '' if (file) { console.log(file); console.log('文件名:', file.name); @@ -659,14 +692,20 @@ export default { } }, async createAIPPTByFile(file,fileShowName) { + this.isPgDialogClose = false // 默认不关闭 this.pgDialog.visible = true this.pgDialog.pg.percentage = 0 + const closePgDialog = () => { + this.pgDialog.pg.percentage = 0 + this.pgDialog.visible = false + } this.pptMedia = {} // 清空媒体数据 const resPptJson = await PPTXFileToJson(file).catch(() => { ElMessageBox.alert('PPT文件转换失败!请点击素材右侧...下载文件后打开另存为PPTX文件格式再进行导入!') this.pgDialog.visible = false }) if (!resPptJson) return + if(this.isPgDialogClose) return closePgDialog() // 弹窗关闭了,终止进行 const { def, slides, ...content } = resPptJson // 生成缩略图 const thumbnails = await slidesToImg(slides, content.width) @@ -674,13 +713,13 @@ export default { let completed = 0 const total = slides.length for( let o of slides ) { + if(this.isPgDialogClose) return closePgDialog() // 弹窗关闭了,终止进行 completed++ await this.toRousrceUrl(o) // 设置进度条 this.pgDialog.pg.percentage = Math.floor(completed / total * 100) } - this.pgDialog.pg.percentage = 0 - this.pgDialog.visible = false + closePgDialog() // 关闭进度条弹窗 listEntpcourse({ evalid: this.currentNode.id, edituserid: this.userStore.userId,