From c555de5fe558e778cd6415d42f2bca766bd8f983 Mon Sep 17 00:00:00 2001 From: zdg Date: Wed, 27 Nov 2024 14:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpptx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/AixPPTist/src/App.vue | 17 ++++++++++++----- src/renderer/src/utils/tool.js | 18 ++++++++++++------ src/renderer/src/views/model/index.vue | 13 +++++++------ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/renderer/src/AixPPTist/src/App.vue b/src/renderer/src/AixPPTist/src/App.vue index 2d58652..1a05300 100644 --- a/src/renderer/src/AixPPTist/src/App.vue +++ b/src/renderer/src/AixPPTist/src/App.vue @@ -26,6 +26,7 @@ import Mobile from './views/Mobile/index.vue' import msgUtils from '@/plugins/modal' // 消息工具 import * as API_entpcoursefile from '@/api/education/entpcoursefile' // 相关api import { PPTApi } from './api' +import { sessionStore } from '@/utils/store' // electron-store 状态管理 const loading = ref(true) const _isPC = isPC() @@ -68,11 +69,17 @@ interface Result { } // 获取参数 const initLoad: Function = () => { - const urlSearch = location.href.split('?')[1] - const query = Object.fromEntries(new URLSearchParams(urlSearch)) - const id: String = query.id - // 如果存在就获取pptx幻灯片内容 - if (!!id) return PPTApi.getSlideList(id) + // const urlSearch = location.href.split('?')[1] + // const query = Object.fromEntries(new URLSearchParams(urlSearch)) + // const id: String = query.id + // // 如果存在就获取pptx幻灯片内容 + // if (!!id) return PPTApi.getSlideList(id) + // 缓存当前资源信息 + const resource = sessionStore.get('curr.resource') + if (!!resource) { // 有ppt 资源数据缓存 + slidesStore.setTitle(resource.title) + return PPTApi.getSlideList(resource.id) + } return Promise.resolve() } diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 4afe082..a89be59 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -216,7 +216,11 @@ export const createWindow = async (type, data) => { win.maximize(); // win.setFullScreen(true) // 设置窗口为全屏 if (import.meta.env.VITE_SHOW_DEV_TOOLS === 'true') win.webContents.openDevTools() // 打开调试工具 - eventHandles(type, win) // 事件监听处理 + let events = {} // 事件处理函数对象 + Object.keys(data) + .filter(k => typeof data[k] === 'function') + .forEach(k => events[k] = data[k]) + eventHandles(type, win, events) // 事件监听处理 break } default: @@ -286,17 +290,20 @@ export function toolWindow(type, {url, isConsole, isWeb=true, option={}}) { * 窗口创建-事件处理 * @param {*} type 事件类型 * @param {*} win 窗口对象 + * @param {*} events 事件对象 */ -const eventHandles = (type, win) => { +const eventHandles = (type, win, events) => { const toolState = useToolState() // 获取store状态 const winAll = Remote.BrowserWindow.getAllWindows() const mainWin = winAll.find(o => o.type == 'main') // 主窗口对象 // 公共方法 - const publicMethods = ({onClosed}={}) => { + const publicMethods = ({onClosed, closed, close}={}) => { // 监听主窗口-关闭事件 mainWin.once('close', () => {winPdf=null;win.destroy();}) win.on('closed', () => { - if(onClosed) onClosed() // 自定义关闭事件 + if(!!onClosed) onClosed() // 自定义关闭事件 + if(!!closed) closed() // 自定义关闭事件 + if(!!close) close() // 自定义关闭事件 win = null wins_tool = null winChild=null @@ -385,8 +392,7 @@ const eventHandles = (type, win) => { win&&win.destroy() }); const on = { - onClosed: () => { - } + ...events } publicMethods(on) // 加载公共方法 break diff --git a/src/renderer/src/views/model/index.vue b/src/renderer/src/views/model/index.vue index e4dc056..9a1111d 100644 --- a/src/renderer/src/views/model/index.vue +++ b/src/renderer/src/views/model/index.vue @@ -255,13 +255,14 @@ const handleAll = async(type, row) =>{ break; } case 'open': { // 打开资源-pptist - // console.log(row) if (row.filetype != 'aptist') return msgUtils.msgWarning('暂不支持该类型文件!') - sessionStore.set('curr.resource', row) // 缓存当前资源信息 - const query = { id: row.id } - const queryUrl = new URLSearchParams(query).toString() - console.log('打开资源 ', queryUrl) - createWindow('open-win', { url: `/pptist?${queryUrl}` }) + // 缓存当前资源信息 + sessionStore.set('curr.resource', row) + createWindow('open-win', { + url: '/pptist', + // 窗口关闭时,清除缓存 + close: () => {sessionStore.set('curr.resource', null)} + }) } } }