export function deepEqual(a: any, b: any, excludeKeys: string[] = ['mediaState']) { // 严格相等检查 if (a === b) return true; // 非对象类型检查 if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false; // 构造函数检查 if (a.constructor !== b.constructor) return false; // 特殊对象处理 if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime(); if (a instanceof RegExp && b instanceof RegExp) return a.toString() === b.toString(); // 获取并过滤属性键(核心修改点) const filterKeys = (obj: any) => Reflect.ownKeys(obj).filter(k => typeof k === 'string' ? !excludeKeys.includes(k) : false); const keysA = filterKeys(a); const keysB = filterKeys(b); // 属性数量检查 if (keysA.length !== keysB.length) return false; // 分类型处理属性名 const processKeys = (keys: (string | symbol)[]) => ({ strings: keys.filter(k => typeof k === 'string').sort(), symbols: keys.filter(k => typeof k === 'symbol'), }); const { strings: strA, symbols: symA } = processKeys(keysA); const { strings: strB, symbols: symB } = processKeys(keysB); // 字符串键顺序敏感比较 if (!arrayEqual(strA, strB)) return false; // Symbol键存在性检查 if (symA.length !== symB.length) return false; const symSet = new Set(symB); if (!symA.every(k => symSet.has(k))) return false; // 合并所有需比较的键 const allKeys = [...strA, ...symA]; // 递归比较属性值(传递排除键) for (const key of allKeys) { if (!deepEqual(a[key], b[key], excludeKeys)) return false; } return true; } // 辅助函数:比较数组是否严格相等 function arrayEqual(arr1: any[], arr2: any[]) { if (arr1.length !== arr2.length) return false; for (let i = 0; i < arr1.length; i++) { if (arr1[i] !== arr2[i]) return false; } return true; } export async function delay(time: number): Promise { return new Promise(resolve => setTimeout(resolve, time)); }