修复bug-数据共享
This commit is contained in:
parent
411ef757e2
commit
eb3778dde2
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
const isNode = typeof require !== 'undefined' // 是否支持node函数
|
const isNode = typeof require !== 'undefined' // 是否支持node函数
|
||||||
const { ipcRenderer } = isNode?require('electron'):{} // app使用
|
const { ipcRenderer } = isNode?require('electron'):{} // app使用
|
||||||
import { sessionStore } from '@/utils/tool'
|
import { sessionStore } from '@/utils/store'
|
||||||
// const Remote = isNode?require('@electron/remote'):{} // 远程模块
|
// const Remote = isNode?require('@electron/remote'):{} // 远程模块
|
||||||
export function shareStorePlugin({store}) {
|
export function shareStorePlugin({store}) {
|
||||||
store.$subscribe((mutation, state) => { // 自动同步
|
store.$subscribe((mutation, state) => { // 自动同步
|
||||||
|
@ -46,7 +46,7 @@ function stateSync(storeName, key, value, state) {
|
||||||
sessionStore.set(keystr, value)
|
sessionStore.set(keystr, value)
|
||||||
// 通知主线程更新
|
// 通知主线程更新
|
||||||
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
|
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
|
||||||
// console.log('======',keystr, data )
|
// console.log('======',keystr, jsonStr )
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('state-change-error', error)
|
console.log('state-change-error', error)
|
||||||
}
|
}
|
||||||
|
@ -105,17 +105,19 @@ const filterByKey = (obj, key, value) => {
|
||||||
let res = { data:{}, keystr:'' }
|
let res = { data:{}, keystr:'' }
|
||||||
for (let k in obj) {
|
for (let k in obj) {
|
||||||
if (obj.hasOwnProperty(k)) {
|
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) {
|
if (k === key && isEqual) {
|
||||||
// 如果匹配,则添加到新对象中
|
// 如果匹配,则添加到新对象中
|
||||||
res.data[k] = obj[k];
|
res.data[k] = obj[k];
|
||||||
res.keystr = k;
|
res.keystr = k;
|
||||||
} else {
|
} 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)
|
const {data, keystr} = filterByKey(obj[k], key, value)
|
||||||
res.data[k] = data
|
if(!!keystr) {
|
||||||
res.keystr = keystr ? `${k}.${keystr}`: key
|
res.data[k] = data
|
||||||
|
res.keystr = `${k}.${keystr}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -12,7 +12,8 @@ const Remote = isNode?require('@electron/remote'):{}
|
||||||
const { ipcRenderer } = isNode?require('electron'):window.electron || {}
|
const { ipcRenderer } = isNode?require('electron'):window.electron || {}
|
||||||
const API = isNode?window.api:{} // preload-api
|
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 // 持久化存储
|
// const Store = isNode?require('electron-store'):null // 持久化存储
|
||||||
|
import store from './store'
|
||||||
|
|
||||||
// 常用变量
|
// 常用变量
|
||||||
const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':''
|
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 || {}
|
export const ipcMain = Remote?.ipcMain || {}
|
||||||
|
|
||||||
// 暴露sessionStore存储对象
|
// 暴露sessionStore存储对象
|
||||||
export const sessionStore = Store ? new Store({
|
export const sessionStore = store.sessionStore
|
||||||
name: 'session-store', // 存储文件名
|
|
||||||
fileExtension: 'ini', // 文件后缀名
|
|
||||||
encryptionKey: 'BvPLmgCC4DSIG0KkTec5' // 数据加密-防止用户直接改配置
|
|
||||||
}) : {}
|
|
||||||
|
|
||||||
// 暴露localStore存储对象
|
// 暴露localStore存储对象
|
||||||
export const localStore = Store ? new Store({
|
export const localStore = store.localStore
|
||||||
name: 'local-store', // 存储文件名
|
|
||||||
fileExtension: 'ini', // 文件后缀名
|
// 暴露Store存储对象
|
||||||
encryptionKey: '6CyoHQmUaPmLzvVsh' // 数据加密-防止用户直接改配置
|
export const Store = store
|
||||||
}) : {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取静态资源,开发和生产环境
|
* 获取静态资源,开发和生产环境
|
||||||
|
|
|
@ -122,6 +122,7 @@
|
||||||
:book-id="uploadData.textbookId"
|
:book-id="uploadData.textbookId"
|
||||||
@add-success="initReserv"
|
@add-success="initReserv"
|
||||||
></reserv>
|
></reserv>
|
||||||
|
<!-- <button @click="ipcMsgSend('tool-sphere:close')">测试</button> -->
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { Check } from '@element-plus/icons-vue'
|
import { Check } from '@element-plus/icons-vue'
|
||||||
|
@ -144,7 +145,7 @@ import { parseCataByNode, creatPPT, asyncLocalFile } from '@/utils/talkFile'
|
||||||
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
|
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
|
||||||
import SetHomework from '@/components/set-homework/index.vue'
|
import SetHomework from '@/components/set-homework/index.vue'
|
||||||
import outLink from '@/utils/linkConfig'
|
import outLink from '@/utils/linkConfig'
|
||||||
import { createWindow, sessionStore } from '@/utils/tool'
|
import { createWindow, ipcMsgSend } from '@/utils/tool'
|
||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
import { delClasswork } from '@/api/teaching/classwork'
|
import { delClasswork } from '@/api/teaching/classwork'
|
||||||
import { getSelfReserv, startClass } from '@/api/classManage'
|
import { getSelfReserv, startClass } from '@/api/classManage'
|
||||||
|
|
|
@ -84,10 +84,10 @@ const btnList = [ // 工具栏按钮列表
|
||||||
onMounted(async() => {
|
onMounted(async() => {
|
||||||
if (!electron) return // 浏览器端
|
if (!electron) return // 浏览器端
|
||||||
// console.log(sessionStore)
|
// console.log(sessionStore)
|
||||||
|
// window.test = sessionStore
|
||||||
|
// window.test1 = toolStore
|
||||||
getClassInfo() // 获取课堂详情 ex3
|
getClassInfo() // 获取课堂详情 ex3
|
||||||
setTimeout(() => {
|
resetStatus() // 开启重置状态-监听
|
||||||
resetStatus() // 开启重置状态-监听
|
|
||||||
}, 200);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// ==== 方法 ===
|
// ==== 方法 ===
|
||||||
|
|
Loading…
Reference in New Issue