CardMediaInfo.ets 3.16 KB
import { ContentDTO } from 'wdBean/Index'
import { DateTimeUtils } from 'wdKit/Index'

/**
 * 这里是样式卡中,右下角显示的音视频信息
 * 目前已知:
 * 音频: 音频图标+时长
 * 视频:点播图标+时长;直播图标+'直播中'
 */
@Component
export struct CardMediaInfo {
  @State contentDTO: ContentDTO = {} as ContentDTO // 如果有duraion,代表点播,显示时长;如果不传或者传0,显示直播中
  // objectType 0:不跳转 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,
  // 14动态图文,15动态视频16问政;100人民号,101标签

  build() {
    Row() {
      if(this.contentDTO.objectType === '1') {
        // 显示点播
        Row(){
          Image($r('app.media.videoTypeIcon'))
            .width(22)
            .height(18)
            .borderRadius($r('app.float.button_border_radius'))
          Text(DateTimeUtils.getFormattedDuration(this.contentDTO.videoInfo.videoDuration * 1000))
            .fontColor($r('app.color.color_fff'))
            .fontSize($r('app.float.font_size_12'))
            .width(40)
            .height(18)
            .textAlign(TextAlign.Center)
            .margin({ left: -3 })
        }
        .backgroundColor('#4d000000')
        .borderRadius($r('app.float.button_border_radius'))
      } else if(this.contentDTO.objectType === '2') {
        // 显示直播信息
        Row(){
          Image($r('app.media.icon_live'))
            .width(22)
            .height(18)
            .borderRadius($r('app.float.button_border_radius'))
          Text('直播中')
            .fontColor($r('app.color.color_fff'))
            .fontSize($r('app.float.font_size_12'))
            .width(40)
            .height(18)
            .textAlign(TextAlign.Center)
            .margin({ left: -3 })
        }
        .backgroundColor('#4d000000')
        .borderRadius($r('app.float.button_border_radius'))
      } else if(this.contentDTO.objectType === '9') {
        // 显示组图;图片数量
        Row(){
          Image($r('app.media.album_card_shape'))
            .width(22)
            .height(18)
            .borderRadius($r('app.float.button_border_radius'))
          Text(this.contentDTO.photoNum)
            .fontColor($r('app.color.color_fff'))
            .fontSize($r('app.float.font_size_12'))
            .width(20)
            .height(18)
            .textAlign(TextAlign.Center)
            .margin({ left: -3 })
        }
        .backgroundColor('#4d000000')
        .borderRadius($r('app.float.button_border_radius'))
      } else if(this.contentDTO.objectType === '13') {
        // 显示音频信息
        Row(){
          Image($r('app.media.broadcast_listen'))
            .height(14)
            .borderRadius($r('app.float.button_border_radius'))
          Text(DateTimeUtils.getFormattedDuration(this.contentDTO.voiceInfo.voiceDuration * 1000))
            .fontColor($r('app.color.color_fff'))
            .fontSize($r('app.float.font_size_12'))
            .width(40)
            .height(18)
            .textAlign(TextAlign.Center)
            .margin({ left: -3 })
        }
      }
    }
    .margin(6)
  }
}