refactor(websocket): 优化websocket消息处理及状态检查逻辑
移除调试日志输出并优化微信账号状态检查逻辑 添加深拷贝工具函数并应用于客服列表处理 将状态检查改为间隔10秒的轮询方式
This commit is contained in:
@@ -113,3 +113,45 @@ export function getSafeAreaHeight() {
|
||||
// 3. 默认值
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 深拷贝函数,支持对象、数组、Date、RegExp等类型
|
||||
* @param obj 要拷贝的对象
|
||||
* @returns 深拷贝后的对象
|
||||
*/
|
||||
export function deepCopy<T>(obj: T): T {
|
||||
// 处理 null 和 undefined
|
||||
if (obj === null || obj === undefined) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// 处理基本数据类型
|
||||
if (typeof obj !== "object") {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// 处理 Date 对象
|
||||
if (obj instanceof Date) {
|
||||
return new Date(obj.getTime()) as T;
|
||||
}
|
||||
|
||||
// 处理 RegExp 对象
|
||||
if (obj instanceof RegExp) {
|
||||
return new RegExp(obj.source, obj.flags) as T;
|
||||
}
|
||||
|
||||
// 处理 Array
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => deepCopy(item)) as T;
|
||||
}
|
||||
|
||||
// 处理普通对象
|
||||
const clonedObj = {} as T;
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
clonedObj[key] = deepCopy(obj[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return clonedObj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user