
/** 过滤掉值为undefined和null的字段 */
export const filterUndefinedAndNull = (obj: any): any => {
  if (obj === null || obj === undefined) {
    return obj;
  }

  if (Array.isArray(obj)) {
    return obj.map(item => filterUndefinedAndNull(item));
  }

  if (typeof obj === 'object') {
    const filteredObj: any = {};
    for (const [key, value] of Object.entries(obj)) {
      if (value !== undefined && value !== null) {
        filteredObj[key] = filterUndefinedAndNull(value);
      }
    }
    return filteredObj;
  }

  return obj;
}