修复bug

This commit is contained in:
zdg 2024-10-09 09:28:52 +08:00
parent 5e247006c5
commit 3038223a7f
2 changed files with 29 additions and 25 deletions

View File

@ -10,6 +10,8 @@ import _ from 'lodash'
// import { diff } from 'jsondiffpatch'
// const Remote = isNode?require('@electron/remote'):{} // 远程模块
const exArrs = ['subject'] // 不需要同步key-排除
export function shareStorePlugin({store}) {
store.$subscribe((mutation, state) => { // 自动同步
// mutation 变量包含了变化前后的状态
@ -54,6 +56,7 @@ function stateSync(storeName, key, value, state) {
// 同步数据-发送给主线程-单独($subscribe-监听使用)
function stateSyncWatch(storeName, newState) {
const oldState = sessionStore.store // 旧数据
exArrs.forEach(k => Object.keys(oldState).includes(k) && (delete oldState[k]))
const diffData = findDifferences(oldState, newState)
if(!_.keys(diffData).length) return // 没有变化就终止执行
// 数据处理: 找出差异
@ -62,27 +65,23 @@ function stateSyncWatch(storeName, newState) {
let pinaValue = {} // store pina状态管理需要的数据格式
// 数据转换处理
for(const key in diffData) {
const value = diffData[key] || null
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)
// 合并数据 loadsh _.merge() 函数
_.merge(pinaValue, newValue)
}
// 数据处理: electron-store
const [key, value] = _.toPairs(pinaValue)[0] // 对象转换为数组 {a:1} toPairs [['a',1]]
const piniaArr = _.toPairs(pinaValue) // 对象转换为数组 {a:1} toPairs [['a',1]]
const setData = (key, value) => {
// 无数据就终止执行
if (!key || !value) return
if (!key) return
// 更新本地数据-session
// 直接获取当前最新值(整体更新)上面获取到value是差异值并不能知道删除还是新增
const newValAll = _.get(newState, key)
const oldValAll = sessionStore.get(key)
// 没变化也终止执行
if (_.isEqual(oldValAll, newValAll)) return
// 更新本地数据-session
sessionStore.set(key, newValAll)
@ -91,6 +90,11 @@ function stateSyncWatch(storeName, newState) {
// 通知主线程更新
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
// console.log('======',key, value, jsonStr )
}
// 数据处理: electron-store
for(let [key, value] of piniaArr) {
setData(key, value)
}
} catch (error) {
console.log('state-change-error', error)
}

View File

@ -220,13 +220,13 @@ const sideChange = async o => {
await imChatRef.value?.imChatObj?.imChat?.sendMsgClosed() //
// const elMsg = ElMessage.warning({duration:0,message:'...'})
const elMsg = ElLoading.service({lock: true, text: '正在下课...', background: 'rgba(0, 0, 0, 0.7)'})
// 2
setTimeout(async() => {
// toolStore.isToolWin = false
toolStore.resetDef() //
await classManageApi.endClass(route.query.reservId)
// 2
setTimeout(async() => {
await imChatRef.value?.deleteGroup() //
await imChatRef.value?.logout() // 退im
await classManageApi.endClass(route.query.reservId)
elMsg.close()
ipcMsgSend('tool-sphere:close') //
}, 500);