DailyPaperTopicModel.ets 2.61 KB
import { PageInfoBean } from 'wdBean/Index';
import { Logger } from 'wdKit/Index';
import { ResponseDTO } from 'wdNetwork/Index';
import { PageRepository } from '../repository/PageRepository';

const TAG = "SearcherAboutDataModel"

class DailyPaperTopicModel {
  private static instance: DailyPaperTopicModel;

  /**
   * 单例模式
   * @returns
   */
  public static getInstance(): DailyPaperTopicModel {
    if (!DailyPaperTopicModel.instance) {
      DailyPaperTopicModel.instance = new DailyPaperTopicModel();
    }
    return DailyPaperTopicModel.instance;
  }

  /**
   * 首页 搜索提示滚动内容
   */
  // getSearchHintData(context: Context): Promise<string[]> {
  //   return new Promise<string[]>((success, error) => {
  //     Logger.info(TAG, `getSearchHintData start`);
  //     this.fetchSearchHintData().then((navResDTO: ResponseDTO<string[]>) => {
  //       // if (!navResDTO || navResDTO.code != 0) {
  //       //   success(this.getSearchHintDataLocal(context))
  //       //   return
  //       // }
  //       Logger.info(TAG, "getSearchHintData then,SearchHintDataResDTO.timeStamp:" + navResDTO.timestamp);
  //       let navigationBean = navResDTO.data as string[]
  //       success(navigationBean);
  //     }).catch((err: Error) => {
  //       Logger.error(TAG, `fetchSearchHintData catch, error.name : ${err.name},  error.message:${err.message}`);
  //       success(this.getSearchHintDataLocal(context))
  //     })
  //   })
  // }
  public async getDailyPaperTopic(): Promise<PageInfoBean> {
    return new Promise<PageInfoBean>((success, error) => {
      Logger.info(TAG, `getDailyPaperTopic pageInfo start`);
      PageRepository.fetchDailyPaperTopic()
        .then((resDTO: ResponseDTO<PageInfoBean>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getDailyPaperTopic then navResDTO is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getDailyPaperTopic then code:${resDTO.code}, message:${resDTO.message}`);
            error('resDTO Response Code is failure');
            return
          }
          // let navResStr = JSON.stringify(navResDTO);
          Logger.info(TAG, "getDailyPaperTopic then,navResDTO.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getDailyPaperTopic catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }
}

const dailyPaperTopicModel = DailyPaperTopicModel.getInstance()

export default dailyPaperTopicModel as DailyPaperTopicModel