BaseViewModel.ets 777 Bytes
import { Logger } from 'wdKit';
import { ResponseDTO } from 'wdNetwork';

/**
 * 处理返回后的数据
 */
export abstract class BaseViewModel {
  abstract getLogTag(): string;

  public isRespondsInvalid(resDTO: ResponseDTO<object>, tag?: string): boolean {
    if (resDTO == null) {
      Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO is empty`);
      return true;
    }
    // code = 0, success
    if (resDTO.code != 0) {
      Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}code error, code:${resDTO.code}, message:${resDTO.message}`);
      return true;
    }
    if (!resDTO.data) {
      Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO.data is null`);
      return true;
    }
    return false;
  }
}