EmptyComponent.ets 1.73 KB
import { CommonConstants } from 'wdConstant';
import { Logger } from 'wdKit';

const TAG = 'EmptyComponent';

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

  build() {
    this.noProgrammeData();
  }

  /**
   * 无数据,空白view组件
   */
  @Builder
  noProgrammeData() {
    Column() {
      // Image($r('app.media.icon_no_content'))
        // .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(): Resource | string {
    Logger.info(TAG, "buildNoDataTip");
    return $r('app.string.load_net_data_none')
  }
}