LiveEmptyComponent.ets 2.82 KB
import { CommonConstants } from 'wdConstant';
import { Logger } from 'wdKit';

const TAG = 'LiveEmptyComponent';

/**
 * WDViewDefaultType 缺省页
 */
export const enum WDViewDefaultType {
  /// 1.默认
  WDViewDefaultType_Default,
  /// 16.直播结束
  WDViewDefaultType_NoLiveEnd,
  /// 17.直播暂停
  WDViewDefaultType_NoLiveSuspend,

}

/**
 * 空数据/无数据
 */
@Preview
@Component
export struct LiveEmptyComponent {
  // private emptySize: SizeOptions = {};
  @State emptyWidth: string | number = CommonConstants.FULL_PARENT;
  @State emptyHeight: string | number = CommonConstants.FULL_PARENT;
  @State emptyType: number = WDViewDefaultType.WDViewDefaultType_Default
  /**
   * The empty image width percentage setting.
   */
  readonly EMPTY_IMAGE_WIDTH: string = '15%';
  /**
   * The empty image height percentage setting.
   */
  readonly EMPTY_IMAGE_HEIGHT: string = '15%';
  /**
   * The empty data text component margin top.
   */
  readonly EMPTY_TIP_TEXT_MARGIN_TOP: string = '10';
  /**
   * The empty data text opacity.
   */
  readonly TEXT_OPACITY: number = 0.4;

  build() {
    this.noProgrammeData();
  }

  /**
   * 无数据,空白view组件
   */
  @Builder
  noProgrammeData() {
    Column() {
      Image(this.buildNoDataTipImage())
        .width('this.EMPTY_IMAGE_WIDTH')
        .height(this.EMPTY_IMAGE_HEIGHT)
        .objectFit(ImageFit.Contain)
      // .border({ width: 1, color: Color.Red, radius: 6 })

      Text(this.buildNoDataTip())
        .fontSize($r('app.float.normal_text_size'))
        .fontColor('#000000')
        .fontWeight(FontWeight.Normal)
        .opacity(this.TEXT_OPACITY)
        .margin({ top: this.EMPTY_TIP_TEXT_MARGIN_TOP })
        .onClick((event: ClickEvent) => {
          Logger.info(TAG, `noProgrammeData onClick event?.source: ${event.source}`);
        })
    }
    .justifyContent(FlexAlign.Center)
    .width(this.emptyWidth)
    .height(this.emptyHeight)
  }

  buildNoDataTip(): string {
    Logger.info(TAG, "buildNoDataTip");
    let contentString: string = '暂无内容'
    if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoLiveEnd) {
      contentString = '直播已结束' // 前方拥堵,请耐心等待
    } else if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoLiveSuspend) {
      contentString = '主播暂时离开,马上回来' // 前方拥堵,请耐心等待
    }
    return contentString
  }

  buildNoDataTipImage(): Resource | string {
    Logger.info(TAG, "buildNoDataTip");
    let imageString: Resource | string = $r('app.media.icon_no_content')
    if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoLiveEnd) {
      imageString = $r('app.media.icon_no_end')
    } else if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoLiveSuspend) {
      imageString = $r('app.media.icon_no_liver')
    }
    return imageString
  }
}