From 1d808950b5cfa06740a061d159f0169a01d725a1 Mon Sep 17 00:00:00 2001 From: zdg Date: Mon, 2 Sep 2024 16:33:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/pdf/index.vue | 9 --------- src/renderer/src/views/classBegins/index.vue | 7 +++++-- src/renderer/src/views/tool/components/board.vue | 4 ++-- src/renderer/src/views/tool/sphere.vue | 7 ++++--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/components/pdf/index.vue b/src/renderer/src/components/pdf/index.vue index ae43c6e..64a8671 100644 --- a/src/renderer/src/components/pdf/index.vue +++ b/src/renderer/src/components/pdf/index.vue @@ -383,16 +383,7 @@ defineExpose({ savaDataStore }) watchEffect(() => { - setTimeout(() => { - console.log(toolState,'监听') - - }, 300) if(toolState.isPdfWin){ - // if(toolState.isToolWin){ - // ispointer.value=false - // }else{ - // ispointer.value=true - // } watchToolState() //监听工具栏 } }) diff --git a/src/renderer/src/views/classBegins/index.vue b/src/renderer/src/views/classBegins/index.vue index a1b4ec3..afd9920 100644 --- a/src/renderer/src/views/classBegins/index.vue +++ b/src/renderer/src/views/classBegins/index.vue @@ -104,9 +104,12 @@ const switchPageMode = () => { } } onMounted(async () => { + const isDev = process.env.NODE_ENV == 'development' toolState.isPdfWin=true //设置打开pdf窗口 - pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上 - // pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地 + if (isDev) + pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地 + else + pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上 textbookId.value = route.query.textbookId pdfObj.bookId=textbookId.value //初始化获取接口数据 diff --git a/src/renderer/src/views/tool/components/board.vue b/src/renderer/src/views/tool/components/board.vue index c6d4144..6aa1686 100644 --- a/src/renderer/src/views/tool/components/board.vue +++ b/src/renderer/src/views/tool/components/board.vue @@ -29,7 +29,7 @@ onMounted(async() => { const handleMode = (newVal, oldVal) => { if(toolStore.isPdfWin){ if(newVal=='clear'){ - emit('update:modelValue', oldVal) + setTimeout(() => emit('update:modelValue', oldVal), 10) } return } @@ -47,7 +47,7 @@ const handleMode = (newVal, oldVal) => { case 'clear': // 清空画布 if(oldVal){ FabricVue.history?.clean() - emit('update:modelValue', oldVal) + setTimeout(() => emit('update:modelValue', oldVal), 10) } break diff --git a/src/renderer/src/views/tool/sphere.vue b/src/renderer/src/views/tool/sphere.vue index f5c55ce..7b6030c 100644 --- a/src/renderer/src/views/tool/sphere.vue +++ b/src/renderer/src/views/tool/sphere.vue @@ -51,8 +51,9 @@ import imChat from './components/imChat.vue' // im-chat-子组件 import vDrag from './directive/drag' // 自定义指令-拖拽 import vIgnore from './directive/ignore' // 自定义指令-穿透 import { useToolState } from '@/store/modules/tool' // 数据状态-缓存 -import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' // 相关工具 +import { ipcMsgSend, ipcMain, sessionStore } from '@/utils/tool' // 相关工具 import MsgEnum from '@/plugins/imChat/msgEnum' // 消息头-相关定义(nuem) + const route = useRoute(); const tabActive = ref('select') // 工具栏当前选中项 const isFold = ref(false) // 折叠工具栏 @@ -82,7 +83,8 @@ const btnList = [ // 工具栏按钮列表 // === 页面加载完毕 === onMounted(async() => { if (!electron) return // 浏览器端 - getClassInfo() // 获取课堂详情 ex3 + // console.log(sessionStore) + // getClassInfo() // 获取课堂详情 ex3 setTimeout(() => { resetStatus() // 开启重置状态-监听 }, 200); @@ -104,7 +106,6 @@ const getClassInfo = async () => { const tabChange = (val) => { const bool = !toolStore.isPdfWin && !toolStore.showBoardAll if(bool) toolStore.showBoardAll = true - // ipcMsgSend('tool-sphere:close') toolStore.model = val // 存储当前tab } // logo 点击-事件 折叠|展开 -- 2.44.0.windows.1 From b4c2751e8cc87fa94da3f8f8d4ef787f9563c9fa Mon Sep 17 00:00:00 2001 From: zdg Date: Mon, 2 Sep 2024 18:35:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=94=BE=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/views/tool/sphere.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/views/tool/sphere.vue b/src/renderer/src/views/tool/sphere.vue index 7b6030c..739f20f 100644 --- a/src/renderer/src/views/tool/sphere.vue +++ b/src/renderer/src/views/tool/sphere.vue @@ -84,7 +84,7 @@ const btnList = [ // 工具栏按钮列表 onMounted(async() => { if (!electron) return // 浏览器端 // console.log(sessionStore) - // getClassInfo() // 获取课堂详情 ex3 + getClassInfo() // 获取课堂详情 ex3 setTimeout(() => { resetStatus() // 开启重置状态-监听 }, 200); -- 2.44.0.windows.1 From ea9af1440e419c67676d57797640a292cb492b4f Mon Sep 17 00:00:00 2001 From: zdg Date: Mon, 2 Sep 2024 22:22:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=EF=BC=9A=E7=BB=93=E5=90=88=20pinia=20+=20electron-sto?= =?UTF-8?q?re=20=E5=85=B3=E9=97=AD=E5=BC=80=E5=8F=91=20=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A5=E5=BF=97=EF=BC=8C=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E6=9C=89=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.js | 2 +- src/renderer/src/plugins/shareStore.js | 45 +++++++++++++++++++----- src/renderer/src/store/modules/tool.js | 9 +++-- src/renderer/src/utils/tool.js | 12 +++---- src/renderer/src/views/prepare/index.vue | 6 ++-- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 3f475be..30ef34e 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -13,7 +13,7 @@ import remote from '@electron/remote/main' // 第二步: 初始化remote remote.initialize() // 日志配置-初始化(日志直接绑定到console上) -Logger.initialize() +if(!is.dev) Logger.initialize() // 持久化数据-初始化 Store.initialize() diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index fee2151..7fc1392 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -3,13 +3,14 @@ */ const isNode = typeof require !== 'undefined' // 是否支持node函数 const { ipcRenderer } = isNode?require('electron'):{} // app使用 +import { sessionStore } from '@/utils/tool' // const Remote = isNode?require('@electron/remote'):{} // 远程模块 export function shareStorePlugin({store}) { store.$subscribe((mutation, state) => { // 自动同步 // mutation 变量包含了变化前后的状态 // mutation.events: key newValue target oldValue oldTarget // state 是变化后的状态 - // console.log('store.$subscribe', mutation) + // console.log('store.$subscribe', mutation, state, store) // 在存储变化的时候执行 // const storeName = store.$id const storeName = mutation.storeId @@ -19,13 +20,15 @@ export function shareStorePlugin({store}) { const { storeId: storeName, payload, events, type } = mutation // direct // if (!Object.keys(payload).length) return if (type != 'direct' || !events || Array.isArray(events) || !events.key) return - stateSync(storeName, events.key, events.newValue) // 需要同步 + stateSync(storeName, events.key, events.newValue, state) // 需要同步 } }) + // 暴露方法-手动同步 store.stateSync = (storeName, key, value) => { - if (!storeName && !!key && !!value) stateSync(storeName, key, value) - else stateSyncAll(store) + const state = store.$state + if (!storeName && !!key && !!value) stateSync(storeName, key, value, state) + else stateSyncAll(store, state) } // 暴露方法-发送当前状态-新窗口 store.stateSyncInit = wid => stateSyncInit(wid, store) @@ -34,14 +37,16 @@ export function shareStorePlugin({store}) { } // 同步数据-发送给主线程-单独 -function stateSync(storeName, key, value) { +function stateSync(storeName, key, value, state) { // console.log('state-change', storeName, key, value) try { - let jsonStr = '' - if (typeof key === 'string') jsonStr = JSON.stringify({[key]:value}) - else if (typeof value === 'object') jsonStr = JSON.stringify(key) + const { data, keystr } = filterByKey(state, key, value) + const jsonStr = JSON.stringify(data) // 从新组装-json数据 + // 更新本地数据-session + sessionStore.set(keystr, value) // 通知主线程更新 ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) + // console.log('======',keystr, data ) } catch (error) { console.log('state-change-error', error) } @@ -95,3 +100,27 @@ const circularSafeStringify = (obj) => { }); } +// 过滤对象 +const filterByKey = (obj, key, value) => { + let res = { data:{}, keystr:'' } + for (let k in obj) { + if (obj.hasOwnProperty(k)) { + const isEqual = JSON.stringify(obj[k]) === JSON.stringify(value) // 值是否相同 + if (k === key && isEqual) { + // 如果匹配,则添加到新对象中 + res.data[k] = obj[k]; + res.keystr = k; + } else { + if (obj[k] !== null && typeof obj[k] === 'object') { + // 如果是对象,则递归处理 + const {data, keystr} = filterByKey(obj[k], key, value) + res.data[k] = data + res.keystr = keystr ? `${k}.${keystr}`: key + } + } + } + } + return res; +} +// 对象克隆 +const objClone = (obj) => JSON.parse(JSON.stringify(obj)) diff --git a/src/renderer/src/store/modules/tool.js b/src/renderer/src/store/modules/tool.js index ac4e440..e2af372 100644 --- a/src/renderer/src/store/modules/tool.js +++ b/src/renderer/src/store/modules/tool.js @@ -2,6 +2,10 @@ * 工具类-窗口-状态管理 */ import { defineStore } from 'pinia' +import { sessionStore } from '@/utils/tool' + +// 默认数据 +const defData = sessionStore.store || {} export const useToolState = defineStore('tool', { state: () => ({ @@ -10,9 +14,10 @@ export const useToolState = defineStore('tool', { isPdfWin: false, // pdf窗口是否打开 isToolWin: false, // 工具窗口是否打开 curSubjectNode: { - data: {}, // 当前教材节点 (包含当前教材 单元) + data: {}, // 当前教材节点 (包含当前教材 单元) querySearch: {} // 查询资源所需参数 - } + }, + ...defData // 默认数据-覆盖上面的配置(不要删除, 会导致新窗口-获取状态失败) }), actions: { } diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 1abade6..8520394 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -11,13 +11,13 @@ const path = isNode?require('path'):{} const Remote = isNode?require('@electron/remote'):{} const { ipcRenderer } = isNode?require('electron'):window.electron || {} const API = isNode?window.api:{} // preload-api -import { useToolState } from '@/store/modules/tool' // 获取store状态 +// import { useToolState } from '@/store/modules/tool' // 获取store状态 const Store = isNode?require('electron-store'):null // 持久化存储 // 常用变量 const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':'' const isDev = isNode?process.env.NODE_ENV !== 'production':'' -const toolState = useToolState() // 获取store状态 +// const toolState = useToolState() // 获取store状态 // 暴露Remote中的属性 export const ipcMain = Remote?.ipcMain || {} @@ -137,7 +137,7 @@ export const createWindow = async (type, data) => { winPdf.restore(); } else{ winPdf.focus(); - toolState.isPdfWin=true + // toolState.isPdfWin=true } return @@ -204,9 +204,9 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) { mainWin.once('closed', () => { win.destroy()}) // 内部监听器 win.webContents.on('did-finish-load', () => { - setTimeout(() => { - toolState.stateSyncInit(win.id) // 同步状态 - }, 200); + // setTimeout(() => { + // toolState.stateSyncInit(win.id) // 同步状态 + // }, 200); }) // 内部监听器-是否打印 if (!!isConsole) { diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index 9b2992d..e23c39d 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -144,12 +144,13 @@ import { parseCataByNode, creatPPT, asyncLocalFile } from '@/utils/talkFile' import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue' import SetHomework from '@/components/set-homework/index.vue' import outLink from '@/utils/linkConfig' -import { createWindow } from '@/utils/tool' +import { createWindow, sessionStore } from '@/utils/tool' import { cloneDeep } from 'lodash' import { delClasswork } from '@/api/teaching/classwork' import { getSelfReserv, startClass } from '@/api/classManage' import { useGetHomework } from '@/hooks/useGetHomework' const toolStore = useToolState() + const fs = require('fs') const { ipcRenderer } = window.electron || {} @@ -423,7 +424,8 @@ export default { this.uploadData.levelThirdId = cata[2] this.uploadData.textbookId = data.textBook.curBookId toolStore.curSubjectNode.data = data - toolStore.curSubjectNode.querySearch = this.uploadData + // 不要同时修改共享数据,这样只会触发一次 + this.$nextTick(() =>{ toolStore.curSubjectNode.querySearch = this.uploadData }) this.initHomeWork() await this.asyncAllFile() }, -- 2.44.0.windows.1