chenjun3_wd

直播回看 直播预约样式

  1 +import { CompDTO, ContentDTO } from 'wdBean';
  2 +
  3 +const TAG = 'Zh_Grid_Layout-02';
  4 +const FULL_PARENT: string = '100%';
  5 +let listSize: number = 2;
  6 +
  7 +/**
  8 + * 双图卡
  9 + * 枚举值Zh_Grid_Layout-02
  10 + * Zh_Grid_Layout-02
  11 + *
  12 + */
  13 +@Preview
  14 +@Component
  15 +export struct ZhGridLayout02 {
  16 + @State compDTO: CompDTO = {} as CompDTO
  17 +
  18 + aboutToAppear() {
  19 + if (this.compDTO.operDataList) {
  20 + listSize = this.compDTO.operDataList.length > 5 ? 2 : this.compDTO.operDataList.length;
  21 + }
  22 + }
  23 +
  24 + build() {
  25 + GridRow({
  26 + columns: { sm: listSize, md: 2 },
  27 + breakpoints: { value: ['320vp', '520vp', '840vp'] }
  28 + }) {
  29 + ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
  30 + GridCol() {
  31 + this.buildItemCard(this.compDTO.operDataList[index]);
  32 + }
  33 + })
  34 + }
  35 + }
  36 +
  37 + /**
  38 + * 组件项
  39 + *
  40 + * @param programmeBean item 组件项, 上面icon,下面标题
  41 + */
  42 + @Builder
  43 + buildItemCard(item: ContentDTO) {
  44 + Column() {
  45 + Image(item.coverUrl)
  46 + .width(44)
  47 + .aspectRatio(1 / 1)
  48 + .margin(16)
  49 + Text(item.newsTitle)
  50 + .fontSize(13)
  51 + .maxLines(1)
  52 + .textOverflow({ overflow: TextOverflow.Ellipsis })
  53 + }
  54 + .width('100%')
  55 + }
  56 +}
  57 +
  58 +
  1 +// 视频直播直播预约
  2 +import { LiveVideoTypeComponent } from './LiveVideoTypeComponent'
  3 +import { LiveHorizontalCardForOneComponent } from './LiveHorizontalCardForOneComponent'
  4 +import { CompDTO, ContentDTO } from 'wdBean'
  5 +import { CommonConstants } from 'wdConstant'
  6 +import { StringUtils } from 'wdKit/Index'
  7 +
  8 +@Component
  9 +export struct LiveHorizontalReservationComponent {
  10 + @State compDTO: CompDTO = {} as CompDTO
  11 +
  12 + build() {
  13 + Column() {
  14 + Row() {
  15 + Row() {
  16 + Image($r("app.media.redLine"))
  17 + .width(3)
  18 + .height(16)
  19 + .margin({ right: 4 })
  20 + Text(StringUtils.isNotEmpty(this?.compDTO?.objectTitle) ? this?.compDTO?.objectTitle : "直播预约")
  21 + .fontSize($r("app.float.font_size_17"))
  22 + .fontColor($r("app.color.color_222222"))
  23 + .fontWeight(600)
  24 + }
  25 +
  26 + if (this.compDTO.operDataList.length > 10) {
  27 + Row() {
  28 + Text("更多")
  29 + .fontSize($r("app.float.font_size_14"))
  30 + .fontColor($r("app.color.color_999999"))
  31 + .margin({ right: 1 })
  32 + Image($r("app.media.more"))
  33 + .width(14)
  34 + .height(14)
  35 + }
  36 + }
  37 + }.justifyContent(FlexAlign.SpaceBetween)
  38 + .padding({ left: 16, right: 16 })
  39 + .margin({ top: 8, bottom: 8 })
  40 + .width(CommonConstants.FULL_WIDTH)
  41 +
  42 + // 多个
  43 + if (this.compDTO.operDataList.length >= 2) {
  44 + List({ space: 12 }) {
  45 + ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
  46 + ListItem() {
  47 + Column() {
  48 + Stack({ alignContent: Alignment.BottomEnd }) {
  49 + Image(item.coverUrl)
  50 + .aspectRatio(16 / 9)
  51 + .width(this.compDTO.operDataList.length == 2 ? 210 : 150)
  52 + .borderRadius(4)
  53 + .objectFit(ImageFit.Cover)
  54 + if (item.objectType === '2' && item.liveInfo && item.liveInfo.liveState === 'running') {
  55 + LiveVideoTypeComponent({ nType: 0, name: '直播中' })
  56 + .padding({
  57 + bottom: 4,
  58 + right: 4
  59 + })
  60 + } else if (item.objectType === '1' && item.videoInfo) {
  61 + LiveVideoTypeComponent({ nType: 1, name: item.videoInfo.videoDuration + "" })
  62 + .padding({
  63 + bottom: 4,
  64 + right: 4
  65 + })
  66 + }
  67 + }
  68 +
  69 + Text(item.newsTitle)
  70 + .fontSize($r("app.float.font_size_14"))
  71 + .fontColor($r("app.color.color_212228"))
  72 + .fontWeight(400)
  73 + .maxLines(2)
  74 + .textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。
  75 + .textAlign(TextAlign.Start)
  76 + .margin({ top: 8 })
  77 + .width(this.compDTO.operDataList.length == 2 ? 210 : 150)
  78 + }
  79 + }
  80 + .padding({ left: (index == 0) ? 16 : 0, right: (index == this.compDTO.operDataList.length - 1) ? 16 : 0 })
  81 + .onClick(() => {
  82 + if (item.objectType != '0') {
  83 + console.log(item.objectId)
  84 + }
  85 + })
  86 + })
  87 + }.listDirection(Axis.Horizontal)
  88 + .width(CommonConstants.FULL_WIDTH)
  89 + .height(this.compDTO.operDataList.length == 2 ? 180 : 136)
  90 + } else if (this.compDTO.operDataList.length) {
  91 + // 一个
  92 + LiveHorizontalCardForOneComponent({ contentDTO: this.compDTO.operDataList[0] })
  93 + }
  94 + }
  95 + .width(CommonConstants.FULL_WIDTH)
  96 + .padding({
  97 + top: 14,
  98 + })
  99 + .backgroundColor($r("app.color.white"))
  100 + }
  101 +}