聊天记录功能-初步
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user