From 4e2512ed777488d583f33a470b747d056d35b5d2 Mon Sep 17 00:00:00 2001 From: zdg Date: Wed, 7 Aug 2024 15:14:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/pdf/index copy.vue | 3 -- src/renderer/src/components/pdf/index.vue | 20 +++++---- src/renderer/src/plugins/shareStore.js | 5 ++- src/renderer/src/utils/tool.js | 22 ++++++++- src/renderer/src/views/classBegins/index.vue | 2 +- src/renderer/src/views/classManage/aside.vue | 2 +- .../src/views/tool/components/board.vue | 4 +- src/renderer/src/views/tool/sphere.vue | 45 ++++++++----------- 8 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/renderer/src/components/pdf/index copy.vue b/src/renderer/src/components/pdf/index copy.vue index ed14d19..48d93e3 100644 --- a/src/renderer/src/components/pdf/index copy.vue +++ b/src/renderer/src/components/pdf/index copy.vue @@ -13,10 +13,7 @@ import { onMounted, watch, reactive, - defineProps, - defineExpose, nextTick, - defineEmits } from 'vue' import { fabric } from 'fabric' import { ElMessage } from 'element-plus' diff --git a/src/renderer/src/components/pdf/index.vue b/src/renderer/src/components/pdf/index.vue index 056474c..652d57d 100644 --- a/src/renderer/src/components/pdf/index.vue +++ b/src/renderer/src/components/pdf/index.vue @@ -26,7 +26,7 @@ import { defineProps, defineExpose, nextTick, - defineEmits,watchEffect + watchEffect } from 'vue' // import { fabric } from 'fabric' import { ElMessage } from 'element-plus' @@ -272,8 +272,12 @@ onMounted(async () => { // 监听2个canvas事件 // handleevent(fabriccanvas.value, imgarr) // handleevent(fabriccanvas1.value, imgarr, 'two') + setToolStatus() // 加载完后-(设置-底部工具栏-状态) }) - +// zdg: 设置-底部工具栏-状态 +const setToolStatus = () => { + toolState.showBoardAll = false +} defineExpose({ initPdf, @@ -282,12 +286,12 @@ defineExpose({ watchEffect(() => { console.log(toolState.showBoardAll,'监听') - if( toolState.showBoardAll){ - console.log('xczxcxzsdf') - setTimeout(() => { - toolState.showBoardAll=false - }, 200); - } + // if( toolState.showBoardAll){ + // setTimeout(() => { + // console.log('pdf 关闭:') + // toolState.showBoardAll=false + // }, 200); + // } // if(toolState.model=='select'){ // toolState.showBoardAll=false // } diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index dab8505..1a43c74 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -1,8 +1,8 @@ /** * 共享数据状态-多窗口 */ -// const { ipcRenderer } = require('electron') // app使用 -const { ipcRenderer } = window.electron || {} +const isNode = typeof require !== 'undefined' // 是否支持node函数 +const { ipcRenderer } = isNode?require('electron'):{} // app使用 export function shareStorePlugin({store}) { store.$subscribe(() => { // 自动同步 // 在存储变化的时候执行 @@ -20,6 +20,7 @@ export function shareStorePlugin({store}) { function stateSync(store) { const storeName = store.$id const jsonStr = JSON.stringify(store.$state) + // console.log('state-change', jsonStr, storeName) // 通知主线程更新 ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) } diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 6802ad6..ca7b212 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -15,6 +15,8 @@ const { ipcRenderer } = isNode?require('electron'):window.electron || {} const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':'' const isDev = isNode?process.env.NODE_ENV !== 'production':'' +// 暴露Remote中的属性 +export const ipcMain = Remote?.ipcMain || {} /** * 获取静态资源,开发和生产环境 * @param {*} url @@ -56,6 +58,17 @@ export function ipcMsgSend(key, data, type) { return ipcRenderer?.invoke(key, data) } } +/** + * @description 封装ipcRenderer事件监听 + * @param {*} fn on once handle invoke + * @param {*} key + * @param {Function} cb 回调函数 + * @returns + */ +export function ipcHandle(fn,key, cb) { + return ipcRenderer[fn](key, cb) + // return ipcRenderer?.[fn]?.(key, cb) +} /** * 创建-窗口 调用该方法 * @param {*} type 类型 @@ -96,6 +109,7 @@ export const createWindow = async (type, data) => { resizable: true, // 禁止窗口大小缩放 alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前 } + data.isConsole = true // 是否开启控制台 data.option = {...defOption, ...option} const win = await toolWindow(data) win.type = type // 唯一标识 @@ -152,7 +166,7 @@ export function toolWindow({url, isConsole, option={}}) { // 内部监听器-是否打印 if (!!isConsole) { win.webContents.on('console-message', (e,leve,m,lin,s) => { - console.log(m) + console.log(`[${win.type}]`,m) }) } }) @@ -186,7 +200,11 @@ const eventHandles = (type, win) => { // 放大监听-测试 Remote.ipcMain.once('maximize-window', () => {win&&win.destroy()}) const on = { - onClosed: () => {Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore)} + onClosed: () => { + Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore) + Remote.ipcMain.removeHandler('tool-sphere:reset') + // Remote.ipcMain.removeAllListeners() // 移除所有监听事件 + } } publicMethods(on) // 加载公共方法 break} diff --git a/src/renderer/src/views/classBegins/index.vue b/src/renderer/src/views/classBegins/index.vue index 80990c9..adbce55 100644 --- a/src/renderer/src/views/classBegins/index.vue +++ b/src/renderer/src/views/classBegins/index.vue @@ -76,7 +76,7 @@ const minimize = () => { toolState.isPdfWin=false toolState.showBoardAll=true //恢复默认值 console.log(toolState.showBoardAll,"关闭") - // ipcRenderer.send('tool-sphere:reset') //重置tool状态 + ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 ipcRenderer.send('open-PDF:minimize') } const handleUpdate = (data) => { diff --git a/src/renderer/src/views/classManage/aside.vue b/src/renderer/src/views/classManage/aside.vue index 120991c..941134f 100644 --- a/src/renderer/src/views/classManage/aside.vue +++ b/src/renderer/src/views/classManage/aside.vue @@ -19,7 +19,7 @@