初始化

This commit is contained in:
砂糖
2025-11-08 10:38:36 +08:00
commit 3beeec7296
1626 changed files with 198488 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
// 自定义序列化方法解决JSON.stringify方法忽略函数属性的问题
export function customSerialize(obj) {
// 将对象属性和函数转换为字符串形式
const serializedObj = JSON.stringify(obj, function (key, value) {
if (typeof value === "function") {
return value.toString(); // 将函数转换为字符串
}
return value; // 保持其他属性不变
});
return serializedObj;
}
// 自定义反序列化方法
export function customDeserialize(serializedObj) {
const parsedObject = JSON.parse(serializedObj, function (key, value) {
if (typeof value === "string" && value.indexOf("function") === 0) {
// 将字符串还原为函数
return new Function("return " + value)();
}
return value; // 保持其他属性不变
});
return parsedObject;
}