diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index f8c939f..05e071f 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -68,6 +68,18 @@ function stateSyncInit(wid, store) { ipcRenderer.invoke('pinia-state-init', wid, storeName, curJson) } +// 监听session数据变化 +function sessionWatch(store) { + const unsubscribe = sessionStore.onDidAnyChange((newV, oldV) => { + if (newV !== oldV) { + console.log('session-change', newV, oldV) + // 通知主线程更新 + // ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) + } + }) + // unsubscribe() 取消监听 +} + // 同步数据-接收主线程消息 function stateChange(store) { const storeName = store.$id @@ -124,5 +136,10 @@ const filterByKey = (obj, key, value) => { } return res; } + +// 获取对象值 +const getObjValue = (obj, key) => { + +} // 对象克隆 const objClone = (obj) => JSON.parse(JSON.stringify(obj)) diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 21be23c..c42f2c8 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -11,14 +11,14 @@ 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 // 持久化存储 import store from './store' - // 常用变量 const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':'' const isDev = isNode?process.env.NODE_ENV !== 'production':'' -// const toolState = useToolState() // 获取store状态 + +const appPath = isNode?Remote.app.getAppPath():'' // 应用目录 // 暴露Remote中的属性 export const ipcMain = Remote?.ipcMain || {} @@ -110,6 +110,7 @@ export const createWindow = async (type, data) => { resizable: false, // 禁止窗口大小缩放 transparent: true, // 设置透明 alwaysOnTop: true, // 窗口是否总是显示在其他窗口之前 + type: 'toolbar', // 创建的窗口类型为工具栏窗口 // parent: mainWin, // 父窗口 // autoClose: true, // 关闭窗口后自动关闭 } @@ -141,8 +142,8 @@ export const createWindow = async (type, data) => { const option = data.option||{} const defOption = { frame: false, // 要创建无边框窗口 - resizable: true, // 禁止窗口大小缩放 - alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前 + resizable: true, // 禁止窗口大小缩放 + alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前 } data.isConsole = true // 是否开启控制台 data.option = {...defOption, ...option} @@ -179,8 +180,7 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) { return new Promise((resolve) => { const config = { width, height, - type: 'toolbar', // 创建的窗口类型为工具栏窗口 - // icon: path.join(__dirname, '../../resources/logo2.ico'), + icon: path.join(appPath, '/resources/logo2.ico'), webPreferences: { preload: path.join(API.preloadPath, '/index.js'), sandbox: false, @@ -221,6 +221,7 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) { * @param {*} win 窗口对象 */ const eventHandles = (type, win) => { + const toolState = useToolState() // 获取store状态 const winAll = Remote.BrowserWindow.getAllWindows() const mainWin = winAll.find(o => o.type == 'main') // 主窗口对象 // 公共方法 @@ -250,6 +251,9 @@ const eventHandles = (type, win) => { Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore) Remote.ipcMain.removeHandler('tool-sphere:reset') // Remote.ipcMain.removeAllListeners() // 移除所有监听事件 + // 设置状态(再次设置-防止未设置到) + if(toolState.isToolWin) toolState.isToolWin = false + // sessionStore.set('isToolWin', false) } } publicMethods(on) // 加载公共方法 @@ -269,6 +273,8 @@ const eventHandles = (type, win) => { const on = { onClosed: () => { Remote.ipcMain.removeHandler('open-PDF:minimize') + // 设置状态(再次设置-防止未设置到) + if(toolState.isPdfWin) toolState.isPdfWin = false } } publicMethods(on) // 加载公共方法 diff --git a/src/renderer/src/views/classManage/classReserv.vue b/src/renderer/src/views/classManage/classReserv.vue index dbabd76..3414291 100644 --- a/src/renderer/src/views/classManage/classReserv.vue +++ b/src/renderer/src/views/classManage/classReserv.vue @@ -31,6 +31,7 @@ import { getSelfReserv } from '@/api/classManage' import ReservItem from '@/views/classManage/reserv-item.vue' import Reserv from '@/views/prepare/container/reserv.vue' import { useToolState } from '@/store/modules/tool' +import { sessionStore } from '@/utils/tool' const reservDialog = ref(null) const tabOptions = ref(['进行中', '已结束']) const tabActive = ref('进行中') @@ -51,21 +52,27 @@ const doneDataList = computed(() => { return item.status === '已结束' }) }) +// 获取数据 +const getData = () => { + getSelfReserv().then((res) => { + const list = res.data || [] + list.sort((a,b) => { if(a.status=='上课中') return -1; else return 0 }) + dataList.value = list + }) +} const toolStore = useToolState() + watch( () => [dataList,toolStore.isToolWin], () => { + console.log('====',toolStore) setTimeout(()=>{ - getSelfReserv().then((res) => { - dataList.value = [...res.data] - }) + getData() // 加载数据 },300) } ) onMounted(() => { - getSelfReserv().then((res) => { - dataList.value = res.data - }) + getData() // 加载数据 }) diff --git a/src/renderer/src/views/classManage/reserv-item.vue b/src/renderer/src/views/classManage/reserv-item.vue index 76d2726..5032c49 100644 --- a/src/renderer/src/views/classManage/reserv-item.vue +++ b/src/renderer/src/views/classManage/reserv-item.vue @@ -20,14 +20,14 @@