Compare commits

..

2 Commits

5 changed files with 21 additions and 6 deletions

View File

@ -5,7 +5,7 @@
</template> </template>
<script setup> <script setup>
import { ref, watch, defineProps, onMounted, defineEmits } from 'vue'; import { ref, watch, onMounted, defineEmits } from 'vue';
const placeholder = ref('') const placeholder = ref('')
const props = defineProps({ const props = defineProps({

View File

@ -19,7 +19,7 @@ export function shareStorePlugin({store}) {
// 同步数据-发送给主线程 // 同步数据-发送给主线程
function stateSync(store) { function stateSync(store) {
const storeName = store.$id const storeName = store.$id
const jsonStr = JSON.stringify(store.$state) const jsonStr = circularSafeStringify(store.$state)
console.log('state-change', jsonStr, storeName) console.log('state-change', jsonStr, storeName)
// 通知主线程更新 // 通知主线程更新
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
@ -30,7 +30,7 @@ function stateChange(store) {
ipcRenderer?.on('pinia-state-set', (e, sName, jsonStr) => { ipcRenderer?.on('pinia-state-set', (e, sName, jsonStr) => {
if (sName == storeName) { // 更新对应数据 if (sName == storeName) { // 更新对应数据
// console.log('state-set', jsonStr, sName) // console.log('state-set', jsonStr, sName)
const curJson = JSON.stringify(store.$state) // 当前数据 const curJson = circularSafeStringify(store.$state) // 当前数据
const isUp = curJson != jsonStr // 不同的时候才写入,不然会导致触发数据变化监听,导致死循环 const isUp = curJson != jsonStr // 不同的时候才写入,不然会导致触发数据变化监听,导致死循环
if (!isUp) return if (!isUp) return
const stateJson = JSON.parse(jsonStr) // 新数据 const stateJson = JSON.parse(jsonStr) // 新数据
@ -41,3 +41,18 @@ function stateChange(store) {
} }
}) })
} }
//解决JSON.stringify嵌套循环产生的bug
const circularSafeStringify = (obj) => {
const cache = new Set();
return JSON.stringify(obj, (key, value) => {
if (typeof value === "object" && value !== null) {
if (cache.has(value)) {
// 当前对象已经存在于缓存中,说明存在循环引用,返回占位符或其他处理方式
return "[Circular Reference]";
}
cache.add(value);
}
return value;
});
}

View File

@ -108,7 +108,7 @@
<script setup> <script setup>
import {listClassmain, listClassuser, addClassgroup, listClassgroup, delClassgroup,getClassgroup,updateClassgroup} from '@/api/classManage/index' import {listClassmain, listClassuser, addClassgroup, listClassgroup, delClassgroup,getClassgroup,updateClassgroup} from '@/api/classManage/index'
import {ref, onMounted, reactive, defineProps, watch} from 'vue' import {ref, onMounted, reactive, watch} from 'vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";

View File

@ -22,7 +22,7 @@
import {ElMessage, ElMessageBox} from "element-plus"; import {ElMessage, ElMessageBox} from "element-plus";
import { getClassmain,listClassuser,leaveClass} from '@/api/classManage/index' import { getClassmain,listClassuser,leaveClass} from '@/api/classManage/index'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import {reactive,onMounted,defineProps,nextTick,watch} from 'vue' import {reactive,onMounted,nextTick,watch} from 'vue'
import delClassDemo from '@/store/modules/delClass' import delClassDemo from '@/store/modules/delClass'
const props = defineProps({ const props = defineProps({
classId: { classId: {

View File

@ -112,7 +112,7 @@
<script setup> <script setup>
import {addStudentmain, listClassuser,updateStudentmain,getClassmain,getStudentmain,leaveClass,removeStudentDataAll,addStudentmainByNameArray} from '@/api/classManage/index' import {addStudentmain, listClassuser,updateStudentmain,getClassmain,getStudentmain,leaveClass,removeStudentDataAll,addStudentmainByNameArray} from '@/api/classManage/index'
import {ref, onMounted, reactive, nextTick, defineProps, watch} from 'vue' import {ref, onMounted, reactive, nextTick, watch} from 'vue'
import {ElMessage,ElMessageBox} from "element-plus"; import {ElMessage,ElMessageBox} from "element-plus";
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import * as XLSX from 'xlsx' import * as XLSX from 'xlsx'