From 95e9fc528a2e85379a3df1169cfb734143a5c1cc Mon Sep 17 00:00:00 2001 From: lyc Date: Mon, 5 Aug 2024 17:03:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=95=99=E6=9D=90=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/choose-textbook/index.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/choose-textbook/index.vue b/src/renderer/src/components/choose-textbook/index.vue index 2a45170..ae8d243 100644 --- a/src/renderer/src/components/choose-textbook/index.vue +++ b/src/renderer/src/components/choose-textbook/index.vue @@ -30,7 +30,10 @@
- + +
+ +
{{ item.itemtitle }}
@@ -398,6 +401,9 @@ onMounted(() => { .textbook-img { width: 55px; height: 70px; + display: flex; + align-items: center; + justify-content: center; } } From 8d558c47f540260de0b7403ba4fdf810deb3f4cd Mon Sep 17 00:00:00 2001 From: zdg Date: Mon, 5 Aug 2024 17:10:57 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=A4=9A=E7=AA=97=E5=8F=A3=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.js | 31 ++++++++++++----- src/renderer/src/plugins/shareStore.js | 41 +++++++++++++++++++++++ src/renderer/src/store/index.js | 2 ++ src/renderer/src/store/modules/tool.js | 25 ++++++++++++++ src/renderer/src/views/resource/index.vue | 18 ++++------ src/renderer/src/views/tool/sphere.vue | 15 ++++++--- 6 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 src/renderer/src/plugins/shareStore.js create mode 100644 src/renderer/src/store/modules/tool.js diff --git a/src/main/index.js b/src/main/index.js index 673da1f..1fb5bdd 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -202,14 +202,8 @@ app.on('ready', () => { ipcMain.on('openWindow', (e, data) => { createLinkWin(data) }) - // 新窗口创建-监听 - ipcMain.on('new-window', (e, data) => { - const { id, type } = data - const win = BrowserWindow.fromId(id) - win.type = type // 绑定独立标识 - remote.enable(win.webContents) // 开启远程服务 - }) - + // zdg: 消息监听 + handleAll() // 打开-登录窗口 createLoginWindow() @@ -226,3 +220,24 @@ app.on('window-all-closed', () => { app.quit() } }) + +// 监听全局事件 +function handleAll() { + // 新窗口创建-监听 + ipcMain.on('new-window', (e, data) => { + const { id, type } = data + const win = BrowserWindow.fromId(id) + win.type = type // 绑定独立标识 + remote.enable(win.webContents) // 开启远程服务 + }) + // 用于监听-状态管理变化-同步所有窗口 + ipcMain.handle('pinia-state-change', (e, storeName, jsonStr) => { + for(const curWin of BrowserWindow.getAllWindows()){ + const id = curWin.webContents.id + const bool = id !== e.sender.id && !curWin.isDestroyed() + if (bool) { // 除了消息发送窗口和销毁的窗口 其他都发送 + curWin.webContents.send('pinia-state-set', storeName, jsonStr) + } + } + }) +} \ No newline at end of file diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js new file mode 100644 index 0000000..746332e --- /dev/null +++ b/src/renderer/src/plugins/shareStore.js @@ -0,0 +1,41 @@ +/** + * 共享数据状态-多窗口 + */ +const { ipcRenderer } = require('electron') // app使用 +export function shareStorePlugin({store}) { + store.$subscribe(() => { // 自动同步 + // 在存储变化的时候执行 + const storeName = store.$id + // 用于多窗口共享(需要共享的状态名称) + const names = ['tool'] + if (names.includes(storeName)) stateSync(store) // 需要同步 + }) + // 暴露方法-手动同步 + store.stateSync = () => stateSync(store) + // 监听主线程消息-同步数据 + stateChange(store) +} +// 同步数据-发送给主线程 +function stateSync(store) { + const storeName = store.$id + const jsonStr = JSON.stringify(store.$state) + // 通知主线程更新 + ipcRenderer.invoke('pinia-state-change', storeName, jsonStr) +} +// 同步数据-接收主线程消息 +function stateChange(store) { + const storeName = store.$id + ipcRenderer.on('pinia-state-set', (e, sName, jsonStr) => { + if (sName == storeName) { // 更新对应数据 + console.log('state-set', jsonStr, sName) + const curJson = JSON.stringify(store.$state) // 当前数据 + const isUp = curJson != jsonStr // 不同的时候才写入,不然会导致触发数据变化监听,导致死循环 + if (!isUp) return + const stateJson = JSON.parse(jsonStr) // 新数据 + // 更新状态 + store.$patch(stateJson) + // 您可以通过将其 $state 属性设置为新对象来替换 Store 的整个状态 + // store.$state = stateJson + } + }) +} \ No newline at end of file diff --git a/src/renderer/src/store/index.js b/src/renderer/src/store/index.js index 3871c81..3dfcd54 100644 --- a/src/renderer/src/store/index.js +++ b/src/renderer/src/store/index.js @@ -1,7 +1,9 @@ import { createPinia } from 'pinia' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' +import { shareStorePlugin } from '@/plugins/shareStore' const pinia = createPinia() //创建pinia实例 pinia.use(piniaPluginPersistedstate) //将插件添加到 pinia 实例上 +pinia.use(shareStorePlugin) // 多窗口数据状态共享 export const store = pinia \ No newline at end of file diff --git a/src/renderer/src/store/modules/tool.js b/src/renderer/src/store/modules/tool.js new file mode 100644 index 0000000..c6bd2d9 --- /dev/null +++ b/src/renderer/src/store/modules/tool.js @@ -0,0 +1,25 @@ +/** + * 工具类-窗口-状态管理 + */ +import { defineStore } from 'pinia' + +export const useToolState = defineStore('tool', { + state: () => ({ + // 窗口状态 + windowState: { + // 窗口是否最小化 + isMinimize: false, + // 窗口是否最大化 + isMaximize: false, + // 窗口是否关闭 + isClose: false, + test: '' + } + }), + actions: { + // 设置窗口状态 + setWindowState(payload) { + if(!!payload)this.windowState = payload + } + } +}) \ No newline at end of file diff --git a/src/renderer/src/views/resource/index.vue b/src/renderer/src/views/resource/index.vue index 4f66881..6438cbb 100644 --- a/src/renderer/src/views/resource/index.vue +++ b/src/renderer/src/views/resource/index.vue @@ -23,7 +23,6 @@ - \ No newline at end of file