channelSkeleton.ets 1.76 KB
/**
 * 频道骨架屏
 */

@Entry
@Component
export struct channelSkeleton {
  @State quantity: Array<number> = [1, 2, 3,]

  build() {
    Row() {
      Column() {

        ForEach(this.quantity, () => {
          Row() {
            Column() {
              textArea('60%', 12)
              textArea('60%', 12)
              textArea('40%', 12)
            }
            .RightStyle()
            
            Column() {
              textArea('35%', 78)
            }
            .margin({ right: 0 })
          }
          .height(110)
          .justifyContent(FlexAlign.SpaceBetween)
          .SkeletonStyle()
        })

        textArea('40%', 12)

        Column() {
          textArea('100%', 204)
        }
        .justifyContent(FlexAlign.SpaceBetween)
        .SkeletonStyle()

        ForEach([1, 2], () => {
          Row() {
            Column() {
              textArea('60%', 12)
              textArea('60%', 12)
              textArea('40%', 12)
            }
            .RightStyle()

            Column() {
              textArea('35%', 78)
            }
            .margin({ right: 0 })
          }
          .height(100)
          .justifyContent(FlexAlign.SpaceBetween)
          .SkeletonStyle()
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}

@Builder
function textArea(width: number | Resource | string = '100%', height: number | Resource | string = '100%') {
  Row()
    .width(width)
    .height(height)
    .backgroundColor('#FFF2F3F4')
    .margin({ top: 10 })
}

// 全局公共样式
@Styles
function SkeletonStyle() {
  .padding({ right: 18, left: 18 })
  .width('100%')
  // .margin({ top: 10 })
}

@Extend(Column)
function RightStyle() {
  .alignItems(HorizontalAlign.Start)
  .justifyContent(FlexAlign.SpaceAround)
  .height('100%')
}