PageViewModel.ets 1.47 KB
import { BottomNavBean, GroupDTO, NavigationBody } from 'wdBean';
import { Logger, ResourcesUtils } from 'wdKit';
import { ResponseDTO } from 'wdNetwork';

const TAG = 'PageViewModel';

/**
 * 处理返回后的数据
 */
export class PageViewModel {
  /**
   * get Nav Data from Resource .
   *
   * @return BottomNavBean[] Nav Data List
   */
  static getBottomNavData(context: Context): BottomNavBean[] {
    Logger.info(TAG, `getBottomNavData start`);
    let compRes: ResponseDTO<NavigationBody> | null = ResourcesUtils.getResourcesJsonSync<ResponseDTO<NavigationBody>>(context, 'bottom_nav.json');
    if (!compRes || !compRes.data || !compRes.data.bottomNavList) {
      Logger.info(TAG, `getBottomNavData compRes bottomNavList is empty`);
      return []
    }
    Logger.info(TAG, `getBottomNavData getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
    return compRes.data.bottomNavList
  }

  /**
   * Get Group data.
   *
   * @return {GroupDTO} compRes.data
   */
  static getGroupDTO(context: Context): GroupDTO {
    let compRes: ResponseDTO<GroupDTO> | null = ResourcesUtils.getResourcesJsonSync<ResponseDTO<GroupDTO>>(context, 'comp_list.json');
    if (!compRes || !compRes.data) {
      Logger.info(TAG, `getCompList compRes is empty`);
      return {} as GroupDTO
    }
    Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`);
    return compRes.data
  }
}

let pageViewModel = new PageViewModel();

export default pageViewModel as PageViewModel;