From eb3778dde2113acb8d835d6054464c426c08db0b Mon Sep 17 00:00:00 2001 From: zdg Date: Tue, 3 Sep 2024 13:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug-=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/plugins/shareStore.js | 14 +++++++------ src/renderer/src/utils/store.js | 25 ++++++++++++++++++++++++ src/renderer/src/utils/tool.js | 18 +++++++---------- src/renderer/src/views/prepare/index.vue | 3 ++- src/renderer/src/views/tool/sphere.vue | 6 +++--- 5 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 src/renderer/src/utils/store.js diff --git a/src/renderer/src/plugins/shareStore.js b/src/renderer/src/plugins/shareStore.js index 7fc1392..f8c939f 100644 --- a/src/renderer/src/plugins/shareStore.js +++ b/src/renderer/src/plugins/shareStore.js @@ -3,7 +3,7 @@ */ const isNode = typeof require !== 'undefined' // 是否支持node函数 const { ipcRenderer } = isNode?require('electron'):{} // app使用 -import { sessionStore } from '@/utils/tool' +import { sessionStore } from '@/utils/store' // const Remote = isNode?require('@electron/remote'):{} // 远程模块 export function shareStorePlugin({store}) { store.$subscribe((mutation, state) => { // 自动同步 @@ -46,7 +46,7 @@ function stateSync(storeName, key, value, state) { sessionStore.set(keystr, value) // 通知主线程更新 ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) - // console.log('======',keystr, data ) + // console.log('======',keystr, jsonStr ) } catch (error) { console.log('state-change-error', error) } @@ -105,17 +105,19 @@ 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) // 值是否相同 + 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') { + 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 + if(!!keystr) { + res.data[k] = data + res.keystr = `${k}.${keystr}` + } } } } diff --git a/src/renderer/src/utils/store.js b/src/renderer/src/utils/store.js new file mode 100644 index 0000000..aef349c --- /dev/null +++ b/src/renderer/src/utils/store.js @@ -0,0 +1,25 @@ +/** + * @description : 存储对象-本地存储 封装工具(渲染器) + * @author : zdg + * @date : 2024-09-03 + */ +const isNode = typeof require !== 'undefined' // 是否支持node函数 +const Store = isNode?require('electron-store'):null // 持久化存储 + +// 暴露sessionStore存储对象 +export const sessionStore = Store ? new Store({ + name: 'session-store', // 存储文件名 + fileExtension: 'ini', // 文件后缀名 + encryptionKey: 'BvPLmgCC4DSIG0KkTec5' // 数据加密-防止用户直接改配置 +}) : {} + +// 暴露localStore存储对象 +export const localStore = Store ? new Store({ + name: 'local-store', // 存储文件名 + fileExtension: 'ini', // 文件后缀名 + encryptionKey: '6CyoHQmUaPmLzvVsh' // 数据加密-防止用户直接改配置 +}) : {} + +export default { + sessionStore, localStore +} \ No newline at end of file diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js index 8520394..21be23c 100644 --- a/src/renderer/src/utils/tool.js +++ b/src/renderer/src/utils/tool.js @@ -12,7 +12,8 @@ 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状态 -const Store = isNode?require('electron-store'):null // 持久化存储 +// const Store = isNode?require('electron-store'):null // 持久化存储 +import store from './store' // 常用变量 const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':'' @@ -23,18 +24,13 @@ const isDev = isNode?process.env.NODE_ENV !== 'production':'' export const ipcMain = Remote?.ipcMain || {} // 暴露sessionStore存储对象 -export const sessionStore = Store ? new Store({ - name: 'session-store', // 存储文件名 - fileExtension: 'ini', // 文件后缀名 - encryptionKey: 'BvPLmgCC4DSIG0KkTec5' // 数据加密-防止用户直接改配置 -}) : {} +export const sessionStore = store.sessionStore // 暴露localStore存储对象 -export const localStore = Store ? new Store({ - name: 'local-store', // 存储文件名 - fileExtension: 'ini', // 文件后缀名 - encryptionKey: '6CyoHQmUaPmLzvVsh' // 数据加密-防止用户直接改配置 -}) : {} +export const localStore = store.localStore + +// 暴露Store存储对象 +export const Store = store /** * 获取静态资源,开发和生产环境 diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index e23c39d..7b2c3bc 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -122,6 +122,7 @@ :book-id="uploadData.textbookId" @add-success="initReserv" > +