From b8ea091bb5f13e5eb8f57c7c6cd5c9203b981ca3 Mon Sep 17 00:00:00 2001 From: zhangxuelin <959231531@qq.com> Date: Tue, 20 Aug 2024 10:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=B0=8F=E5=8C=96pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/pdf/index.vue | 22 +++++++++--- src/renderer/src/utils/tool.js | 32 ++++++++++++----- src/renderer/src/views/classBegins/index.vue | 38 +++++++++++++++++--- src/renderer/src/views/prepare/index.vue | 2 +- 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/src/renderer/src/components/pdf/index.vue b/src/renderer/src/components/pdf/index.vue index e588373..ae43c6e 100644 --- a/src/renderer/src/components/pdf/index.vue +++ b/src/renderer/src/components/pdf/index.vue @@ -100,12 +100,17 @@ const renderPage = async (canvasobj) => { }) } // 保存数据 -const savaDataStore = () => { +const savaDataStore = (type) => { if(!toolState.isToolWin){ toolState.isPdfWin=false toolState.showBoardAll=true //恢复默认值 - ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 - ipcRenderer.send('open-PDF:minimize') + if(type=='rest'){ + ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 + ipcRenderer.send('open-PDF:close') + }else{ + ipcRenderer.invoke('open-PDF:minimize') + } + return } imgarr.value.forEach((a) => { @@ -139,8 +144,15 @@ const savaDataStore = () => { Promise.all(promises).then(res=>{ toolState.isPdfWin=false toolState.showBoardAll=true //恢复默认值 - ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 - ipcRenderer.send('open-PDF:minimize') + // ipcRenderer.send('open-PDF:minimize') + if(type=='rest'){ + ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 + ipcRenderer.send('open-PDF:close') + }else{ + ipcRenderer.send('open-PDF:minimize') + } + // ipcRenderer.send('open-PDF:close') + }) } const updatePage = (canvasobj) => { diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index ff4bfdc..3e7a934 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -115,6 +115,16 @@ export const createWindow = async (type, data) => { return wins_tool } case 'open-PDF': { //课本展示-pdf + if(winPdf){ //判断是否已经打开 + if (winPdf.isMinimized()){ + winPdf.restore(); + } else{ + winPdf.focus(); + toolState.isPdfWin=true + } + + return + } const option = data.option||{} const defOption = { frame: false, // 要创建无边框窗口 @@ -123,12 +133,6 @@ export const createWindow = async (type, data) => { } data.isConsole = true // 是否开启控制台 data.option = {...defOption, ...option} - if(winPdf){ //判断是否已经打开 - // if (winPdf.isMinimized()) winPdf.restore(); - winPdf.focus(); - // toolState.isPdfWin=true - return - } const win = await toolWindow(data) win.type = type // 唯一标识 win.show() @@ -240,12 +244,22 @@ const eventHandles = (type, win) => { break} case 'open-PDF': { // 最小化窗口 minimize() - Remote.ipcMain.once('open-PDF:minimize', () => { + Remote.ipcMain.handle('open-PDF:minimize', () => { + // winPdf=null + // win&&win.destroy() + win&&win.minimize(); //缩小功能 + }) + // 关闭窗口 + Remote.ipcMain.once('open-PDF:close', () => { winPdf=null win&&win.destroy() - // win&&win.minimize(); //缩小功能 }) - publicMethods() // 加载公共方法 + const on = { + onClosed: () => { + Remote.ipcMain.removeHandler('open-PDF:minimize') + } + } + publicMethods(on) // 加载公共方法 break} default: break diff --git a/src/renderer/src/views/classBegins/index.vue b/src/renderer/src/views/classBegins/index.vue index a0f8d07..1e3bf0e 100644 --- a/src/renderer/src/views/classBegins/index.vue +++ b/src/renderer/src/views/classBegins/index.vue @@ -26,7 +26,10 @@ 下一页 + +
最小化 + 关闭
@@ -72,9 +75,10 @@ const navtopage = (type) => { pdfCanvaslist.value.initPdf('rest') } // 关闭窗口 -const minimize = async () => { - await pdfCanvaslist.value.savaDataStore() +const minimize = async (type='minimize') => { + await pdfCanvaslist.value.savaDataStore(type) } + const handleUpdate = (data) => { numPagesTotal.value = data if (numPagesTotal.value == 1) { @@ -101,8 +105,8 @@ const switchPageMode = () => { } onMounted(async () => { toolState.isPdfWin=true //设置打开pdf窗口 - pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上 - // pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地 + // pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上 + pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地 textbookId.value = route.query.textbookId pdfObj.bookId=textbookId.value //初始化获取接口数据 @@ -138,7 +142,8 @@ const getUniqueArrayByLastOccurrence=(array)=> { flex-wrap: wrap; .pdf-btn { position: absolute; - right: 0; + // right: 0; + left: 0; bottom: 0; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5); border-radius: 5px 0 0 0; @@ -163,5 +168,28 @@ const getUniqueArrayByLastOccurrence=(array)=> { } } } + .pdf-btn-right{ + position: absolute; + right: 0; + bottom: 0; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5); + border-radius: 5px 0 0 0; + button { + margin-left: 0; + border: none; + font-size: 16px; + // padding: 4px 7px; + border-radius: 0; + width: 80px; + height: 70px; + :deep(> span) { + display: block !important; + } + .iconfont { + font-size: 26px; + margin-bottom: 10px; + } + } + } } diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index 04b11d4..9c5c7df 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -493,7 +493,7 @@ export default { // 打开PDF-课件 async navtoPdf() { - if (toolStore.isPdfWin) return this.$message.error('您当前已打开课本,请勿重复操作') + // if (toolStore.isPdfWin) return this.$message.error('您当前已打开课本,请勿重复操作') let path = await this.getBookPathFromServer() createWindow('open-PDF', { url: '/classBegins/index?textbookId=' + this.uploadData.textbookId + '&path=' + path