From 3038223a7f69b1581c43b4759c088908f557a186 Mon Sep 17 00:00:00 2001 From: zdg Date: Wed, 9 Oct 2024 09:28:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/plugins/shareStore.js | 48 ++++++++++++++------------ src/renderer/src/views/tool/sphere.vue | 6 ++-- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index ba893d2..3b3c819 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -10,6 +10,8 @@ import _ from 'lodash' // import { diff } from 'jsondiffpatch' // const Remote = isNode?require('@electron/remote'):{} // 远程模块 +const exArrs = ['subject'] // 不需要同步key-排除 + export function shareStorePlugin({store}) { store.$subscribe((mutation, state) => { // 自动同步 // mutation 变量包含了变化前后的状态 @@ -54,6 +56,7 @@ function stateSync(storeName, key, value, state) { // 同步数据-发送给主线程-单独($subscribe-监听使用) function stateSyncWatch(storeName, newState) { const oldState = sessionStore.store // 旧数据 + exArrs.forEach(k => Object.keys(oldState).includes(k) && (delete oldState[k])) const diffData = findDifferences(oldState, newState) if(!_.keys(diffData).length) return // 没有变化就终止执行 // 数据处理: 找出差异 @@ -62,35 +65,36 @@ function stateSyncWatch(storeName, newState) { let pinaValue = {} // store pina状态管理需要的数据格式 // 数据转换处理 for(const key in diffData) { - const value = diffData[key] || null + const value = diffData[key] const newValue = {} // 重新组装pinia需要的数据 {a:{b:1}} 这种 const keyArr = key.split('.') || [] keyArr.reduce((o,c,i)=>{o[c] = i === keyArr.length-1 ? value : {};return o[c]}, newValue) // 合并数据 loadsh _.merge() 函数 _.merge(pinaValue, newValue) } - + const piniaArr = _.toPairs(pinaValue) // 对象转换为数组 {a:1} toPairs [['a',1]] + const setData = (key, value) => { + // 无数据就终止执行 + if (!key) return + // 更新本地数据-session + // 直接获取当前最新值(整体更新),上面获取到value是差异值,并不能知道删除还是新增 + const newValAll = _.get(newState, key) + const oldValAll = sessionStore.get(key) + // 没变化也终止执行 + if (_.isEqual(oldValAll, newValAll)) return + // 更新本地数据-session + sessionStore.set(key, newValAll) + + // 数据处理: pina-store + const jsonStr = JSON.stringify(pinaValue) // 从新组装-json数据 + // 通知主线程更新 + ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) + // console.log('======',key, value, jsonStr ) + } // 数据处理: electron-store - const [key, value] = _.toPairs(pinaValue)[0] // 对象转换为数组 {a:1} toPairs [['a',1]] - // 无数据就终止执行 - if (!key || !value) return - - // 更新本地数据-session - // 直接获取当前最新值(整体更新),上面获取到value是差异值,并不能知道删除还是新增 - const newValAll = _.get(newState, key) - const oldValAll = sessionStore.get(key) - - // 没变化也终止执行 - if (_.isEqual(oldValAll, newValAll)) return - - // 更新本地数据-session - sessionStore.set(key, newValAll) - - // 数据处理: pina-store - const jsonStr = JSON.stringify(pinaValue) // 从新组装-json数据 - // 通知主线程更新 - ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) - // console.log('======',key, value, jsonStr ) + for(let [key, value] of piniaArr) { + setData(key, value) + } } catch (error) { console.log('state-change-error', error) } diff --git a/src/renderer/src/views/tool/sphere.vue b/src/renderer/src/views/tool/sphere.vue index 27a9d92..bfed571 100644 --- a/src/renderer/src/views/tool/sphere.vue +++ b/src/renderer/src/views/tool/sphere.vue @@ -220,13 +220,13 @@ const sideChange = async o => { await imChatRef.value?.imChatObj?.imChat?.sendMsgClosed() // 发送下课消息 // const elMsg = ElMessage.warning({duration:0,message:'正在下课...'}) const elMsg = ElLoading.service({lock: true, text: '正在下课...', background: 'rgba(0, 0, 0, 0.7)'}) + // toolStore.isToolWin = false + toolStore.resetDef() // 重置状态 + await classManageApi.endClass(route.query.reservId) // 延迟2秒后关闭窗口,如果马上解散群,会导致群组不存在 setTimeout(async() => { - // toolStore.isToolWin = false - toolStore.resetDef() // 重置状态 await imChatRef.value?.deleteGroup() // 解散群 await imChatRef.value?.logout() // 退出im - await classManageApi.endClass(route.query.reservId) elMsg.close() ipcMsgSend('tool-sphere:close') // 关闭窗口 }, 500); -- 2.44.0.windows.1 From a7743ba249589cc8b1c6b21e2b428137498d4376 Mon Sep 17 00:00:00 2001 From: zdg Date: Wed, 9 Oct 2024 09:30:42 +0800 Subject: [PATCH 2/2] =?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/main/store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/store.js b/src/main/store.js index 5cc0f1c..a34bd90 100644 --- a/src/main/store.js +++ b/src/main/store.js @@ -13,6 +13,7 @@ const defaultData = { showBoardAll: false, // 全屏画板-是否显示 isPdfWin: false, // pdf窗口是否打开 isToolWin: false, // 工具窗口是否打开 + isTaskWin: false, // 批改窗口是否打开 curSubjectNode: { querySearch: {} // 查询资源所需参数 }, -- 2.44.0.windows.1