From 3a83a31970aad79e33ab7083f3a6ae8c0e6fb6a7 Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 5 Sep 2024 01:02:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=8A=B6=E6=80=81-=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=9B=91=E5=90=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/plugins/shareStore.js | 68 ++++++++++++++++++++++-- src/renderer/src/store/modules/tool.js | 9 ++++ src/renderer/src/utils/tool.js | 1 + src/renderer/src/views/prepare/index.vue | 4 +- src/renderer/src/views/tool/sphere.vue | 3 +- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index 4f6c6e9..e291561 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -4,7 +4,9 @@ const isNode = typeof require !== 'undefined' // 是否支持node函数 const { ipcRenderer } = isNode?require('electron'):{} // app使用 import { sessionStore } from '@/utils/store' +// import { diff } from 'jsondiffpatch' // const Remote = isNode?require('@electron/remote'):{} // 远程模块 + export function shareStorePlugin({store}) { store.$subscribe((mutation, state) => { // 自动同步 // mutation 变量包含了变化前后的状态 @@ -19,8 +21,8 @@ export function shareStorePlugin({store}) { if (names.includes(storeName)) { 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, state) // 需要同步 + // if (type != 'direct' || !events || Array.isArray(events) || !events.key) return + stateSyncWatch(storeName, state) // 需要同步 } }) @@ -38,7 +40,7 @@ export function shareStorePlugin({store}) { // 同步数据-发送给主线程-单独 function stateSync(storeName, key, value, state) { - console.log('state-change', storeName, key, value) + // console.log('state-change', storeName, key, value) try { const { data, keystr } = filterByKey(state, key, value) const jsonStr = JSON.stringify(data) // 从新组装-json数据 @@ -51,6 +53,28 @@ function stateSync(storeName, key, value, state) { console.log('state-change-error', error) } } +// 同步数据-发送给主线程-单独($subscribe-监听使用) +function stateSyncWatch(storeName, newState) { + const oldState = sessionStore.store // 旧数据 + const diffData = findDifferences(oldState, newState) + // console.log('state-change-diffData', diffData) + try { + for(const key in diffData) { + 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) + const jsonStr = JSON.stringify(newValue) // 从新组装-json数据 + // // 更新本地数据-session + sessionStore.set(key, value) + // // 通知主线程更新 + ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) + // console.log('======',key, value, jsonStr ) + } + } catch (error) { + console.log('state-change-error', error) + } +} // 同步数据-发送给主线程-全量更新 function stateSyncAll(store) { @@ -141,5 +165,43 @@ const filterByKey = (obj, key, value) => { const getObjValue = (obj, key) => { } + +// 找出两个对象之间的差异 +const findDifferences = (obj1, obj2) => { + const differences = {}; + function compareObjects(o1, o2, path = '') { + for (const key in o1) { + if (o1.hasOwnProperty(key)) { + const newPath = path ? `${path}.${key}` : key; + if (o2.hasOwnProperty(key)) { + const v1 = toJsonStr(o1[key]) + const v2 = toJsonStr(o2[key]) + if (typeof o1[key] === 'object' && typeof o2[key] === 'object' && !Array.isArray(o1[key])) { + compareObjects(o1[key], o2[key], newPath); + } else if (v1 !== v2) { + differences[newPath] = o2[key]; + } + } else { + differences[newPath] = o2[key]; + } + } + } + + for (const key in o2) { + if (o2.hasOwnProperty(key) && !o1.hasOwnProperty(key)) { + const newPath = path ? `${path}.${key}` : key; + differences[newPath] = o2[key]; + } + } + } + + compareObjects(objClone(obj1), objClone(obj2)); + // 特殊处理 + + + return differences; +} // 对象克隆 const objClone = (obj) => JSON.parse(JSON.stringify(obj)) +// 转换为json +const toJsonStr = (obj) => JSON.stringify(obj) diff --git a/src/renderer/src/store/modules/tool.js b/src/renderer/src/store/modules/tool.js index e2af372..fdddb52 100644 --- a/src/renderer/src/store/modules/tool.js +++ b/src/renderer/src/store/modules/tool.js @@ -6,6 +6,8 @@ import { sessionStore } from '@/utils/tool' // 默认数据 const defData = sessionStore.store || {} +// 延时 +const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) export const useToolState = defineStore('tool', { state: () => ({ @@ -20,5 +22,12 @@ export const useToolState = defineStore('tool', { ...defData // 默认数据-覆盖上面的配置(不要删除, 会导致新窗口-获取状态失败) }), actions: { + async resetDef() { // 重置数据-下课 + this.model = 'select' // 悬浮球-当前模式 + await sleep(20) // 休眠20ms + this.showBoardAll = false // 全屏画板-是否显示 + await sleep(20) // 休眠20ms + this.isToolWin = false // 工具窗口是否打开 + } } }) diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index c42f2c8..39e26da 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -186,6 +186,7 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) { sandbox: false, nodeIntegration: true, // nodeApi调用 contextIsolation: false, // 沙箱取消 + devTools: true }, ...option } diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index 7f49460..0cb65bc 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -145,7 +145,7 @@ 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, ipcMsgSend } from '@/utils/tool' +import { createWindow, ipcMsgSend, sessionStore } from '@/utils/tool' import { cloneDeep } from 'lodash' import { delClasswork } from '@/api/teaching/classwork' import { getSelfReserv, startClass } from '@/api/classManage' @@ -220,6 +220,8 @@ export default { this.initReserv() }, mounted() { + window.test = sessionStore + window.test1 = toolStore this.$watch( () => toolStore.isToolWin, (newD, oldD) => { diff --git a/src/renderer/src/views/tool/sphere.vue b/src/renderer/src/views/tool/sphere.vue index 3d7277f..2af576d 100644 --- a/src/renderer/src/views/tool/sphere.vue +++ b/src/renderer/src/views/tool/sphere.vue @@ -219,7 +219,8 @@ const sideChange = async o => { // 延迟2秒后关闭窗口,如果马上解散群,会导致群组不存在 setTimeout(async() => { // elMsg.close() - toolStore.isToolWin = false + // toolStore.isToolWin = false + toolStore.resetDef() // 重置状态 await imChatRef.value?.deleteGroup() // 解散群 await imChatRef.value?.logout() // 退出im await classManageApi.endClass(route.query.reservId) From b794d55cd7761e5d67d84a742056fed04ede6055 Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 5 Sep 2024 01:05:29 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/pdf/index copy.vue | 4 ++-- src/renderer/src/utils/tool.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/components/pdf/index copy.vue b/src/renderer/src/components/pdf/index copy.vue index 45b499a..a1c3487 100644 --- a/src/renderer/src/components/pdf/index copy.vue +++ b/src/renderer/src/components/pdf/index copy.vue @@ -110,7 +110,7 @@ const savaDataStore = () => { if(!toolState.isToolWin){ toolState.isPdfWin=false toolState.showBoardAll=true //恢复默认值 - ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 + // ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 ipcRenderer.send('open-PDF:minimize') return } @@ -145,7 +145,7 @@ const savaDataStore = () => { Promise.all(promises).then(res=>{ toolState.isPdfWin=false toolState.showBoardAll=true //恢复默认值 - ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 + // ipcRenderer.invoke('tool-sphere:reset') //重置tool状态 ipcRenderer.send('open-PDF:minimize') }) } diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 7a0d03c..5d61452 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -251,7 +251,7 @@ const eventHandles = (type, win) => { const on = { onClosed: () => { Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore) - Remote.ipcMain.removeHandler('tool-sphere:reset') + // Remote.ipcMain.removeHandler('tool-sphere:reset') // Remote.ipcMain.removeAllListeners() // 移除所有监听事件 // 设置状态(再次设置-防止未设置到) if(toolState.isToolWin) toolState.isToolWin = false From 1c69d10263bf1de589a274227cdc55906cc94dd9 Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 5 Sep 2024 01:30:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D--=20bug=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=9C=A8=E6=A1=8C=E9=9D=A2=E5=92=8Cpdf=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/utils/tool.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 5d61452..e7fcf86 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -275,11 +275,13 @@ const eventHandles = (type, win) => { // 监听窗口的激活事件 win.on('focus', async () => { + console.log('激活窗口') toolState.isPdfWin=true await sleep(20) // 延时 toolState.showBoardAll=false //恢复默认值 - await sleep(50) // 延时 - + // await sleep(50) // 延时 + // 穿透开启 + if (toolState.isToolWin) ipcRenderer.invoke('tool-sphere:set:ignore', true) }); const on = { onClosed: () => { From f5f33eaa6329204858cbba1da4a508eeb4afc2ca Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 5 Sep 2024 16:18:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?im=E6=97=A5=E5=BF=97=E7=BA=A7=E5=88=AB=20De?= =?UTF-8?q?bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/plugins/imChat/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/plugins/imChat/index.js b/src/renderer/src/plugins/imChat/index.js index 3b42935..dda4bfa 100644 --- a/src/renderer/src/plugins/imChat/index.js +++ b/src/renderer/src/plugins/imChat/index.js @@ -13,6 +13,7 @@ import IMListeners from './imLiseners' // im消息-监听器 const API = window.api // TIM生成签名 // import * as GenerateUserSig from './userSig' // 引入签名生成器 +const isDev = process.env.NODE_ENV == 'development' // 环境 export class ImChat { timChat // imChat对象 SDKAppID // sdkID @@ -48,10 +49,11 @@ export class ImChat { } // 设置配置 async setConfig() { + const log_level = TYPES.TIMLogLevel.kTIMLog_Error await this.timChat.TIMSetConfig({ // TIMSetConfigParam json_config: { // JSONCongfig - set_config_log_level: TYPES.TIMLogLevel.kTIMLog_Test, - set_config_callback_log_level: TYPES.TIMLogLevel.kTIMLog_Error, + set_config_log_level: log_level, + set_config_callback_log_level: log_level, set_config_is_log_output_console: true, // set_config_user_config: { // 用户配置 // user_config_is_read_receipt: true, // true表示要收已读回执事件 From 5ecba3fb62809293250b6db21d953973dd3404a1 Mon Sep 17 00:00:00 2001 From: zdg Date: Thu, 5 Sep 2024 16:28:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=BE=A4=E6=B2=A1?= =?UTF-8?q?=E6=B8=85=E9=99=A4=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BE=A4?= 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 2af576d..4e65bd0 100644 --- a/src/renderer/src/views/tool/sphere.vue +++ b/src/renderer/src/views/tool/sphere.vue @@ -95,7 +95,7 @@ const getClassInfo = async () => { const { data } = await classManageApi.getClassInfo(classObj.id) classObj.data = data // 群id - let timGroupId = data?.ex3 || '@TGS#36AICW6O6' + let timGroupId = data?.ex3 || '' console.log('获取群ID:', timGroupId) const chat = await imChatRef.value?.initImChat(timGroupId) // 初始化im-chat if (!timGroupId) timGroupId = chat?.timGroupId