PeopleShipMainViewModel.ets 4.09 KB
import { Logger } from 'wdKit';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import HashMap from '@ohos.util.HashMap';
import {
  RmhRecommendDTO,
  PeopleShipContentListDTO,
  AttentionBatchDTO
} from 'wdBean';

const TAG = 'PeopleShipMainViewModel'

export class PeopleShipMainViewModel {

  /*人民号号主推荐*/
  static fetchPeopleRemRecommendData() {
    let url = HttpUrlUtils.getRmhRecommendUrl()
    let bean: Record<string, string> = {};
    return WDHttp.post<ResponseDTO<RmhRecommendDTO[]>>(url, bean)
  }

  static async getPeopleRemRecommendInfo(): Promise<RmhRecommendDTO[]> {
    return new Promise<RmhRecommendDTO[]>((success, error) => {
      Logger.debug(TAG, `getMorningEveningCompInfo pageInfo start`);
      PeopleShipMainViewModel.fetchPeopleRemRecommendData()
        .then((resDTO: ResponseDTO<RmhRecommendDTO[]>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getPeopleRemRecommendInfo then navResDTO is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getPeopleRemRecommendInfo then code:${resDTO.code}, message:${resDTO.message}`);
            error('resDTO Response Code is failure');
            return
          }
          Logger.debug(TAG, "getPeopleRemRecommendInfo then,navResDTO.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getPeopleRemRecommendInfo catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }

  /*关注号主发布内容接口*/
  static fetchAttentionContentListData(pageNum: number, pageSize: number, time: string) {
    let url = HttpUrlUtils.getAttentionContentListUrl()
    let params: Record<string, Object> = {};
    params['pageNum'] = pageNum
    params['pageSize'] = pageSize
    params['time'] = time
    return WDHttp.post<ResponseDTO<PeopleShipContentListDTO>>(url, params)
  }

  static async getAttentionContentListInfo(pageNum:number, pageSize: number, time: string): Promise<PeopleShipContentListDTO> {
    return new Promise<PeopleShipContentListDTO>((success, error) => {
      Logger.debug(TAG, `getAttentionContentListInfo pageInfo start`);
      PeopleShipMainViewModel.fetchAttentionContentListData(pageNum, pageSize, time)
        .then((resDTO: ResponseDTO<PeopleShipContentListDTO>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getAttentionContentListInfo then navResDTO is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getAttentionContentListInfo then code:${resDTO.code}, message:${resDTO.message}`);
            error('resDTO Response Code is failure');
            return
          }
          Logger.debug(TAG, "getAttentionContentListInfo then,navResDTO.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getAttentionContentListInfo catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }

  /*一键关注接口*/
  static fetchAttentionBatchData(params: AttentionBatchDTO) {
    let url = HttpUrlUtils.getAttentionBatchUrl()
    return WDHttp.post<ResponseDTO>(url, params)
  }

  static async getAttentionBatchInfo(params: AttentionBatchDTO): Promise<ResponseDTO> {
    return new Promise<ResponseDTO>((success, error) => {
      Logger.debug(TAG, `getAttentionBatchInfo pageInfo start`);
      PeopleShipMainViewModel.fetchAttentionBatchData(params)
        .then((resDTO: ResponseDTO) => {
          if (!resDTO || resDTO.code != 0) {
            error(resDTO.message)
            return
          }
          Logger.debug(TAG, "getAttentionBatchInfo then,navResDTO.timestamp:" + resDTO.timestamp);
          success(resDTO);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getAttentionBatchInfo catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }


}