聊天记录功能-初步

This commit is contained in:
2025-08-13 16:53:27 +08:00
parent a859fe51d1
commit ef02eedac6
9 changed files with 6223 additions and 497 deletions
+33 -31
View File
@@ -8,37 +8,39 @@
* 为不支持 structuredClone 的环境提供兼容实现
*/
export function initPolyfills(): void {
// structuredClone polyfill
if (typeof (globalThis as any).structuredClone === 'undefined') {
(globalThis as any).structuredClone = function(obj: any): any {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (obj instanceof Date) {
return new Date(obj.getTime());
}
if (Array.isArray(obj)) {
return obj.map((item: any) => (globalThis as any).structuredClone(item));
}
if (typeof obj === 'object') {
const cloned: any = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
cloned[key] = (globalThis as any).structuredClone(obj[key]);
}
}
return cloned;
}
return obj;
};
console.log('[Polyfill] structuredClone polyfill loaded');
}
// structuredClone polyfill
if (typeof (globalThis as any).structuredClone === "undefined") {
(globalThis as any).structuredClone = function (obj: any): any {
if (obj === null || typeof obj !== "object") {
return obj;
}
if (obj instanceof Date) {
return new Date(obj.getTime());
}
if (Array.isArray(obj)) {
return obj.map((item: any) =>
(globalThis as any).structuredClone(item)
);
}
if (typeof obj === "object") {
const cloned: any = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
cloned[key] = (globalThis as any).structuredClone(obj[key]);
}
}
return cloned;
}
return obj;
};
//console.log('[Polyfill] structuredClone polyfill loaded');
}
}
// 自动初始化
initPolyfills();
initPolyfills();