ZhSingleRow02.ets 5.02 KB
import { CompDTO, ContentDTO, Params } from 'wdBean';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { HttpUrlUtils } from 'wdNetwork/Index';
import { postInteractAccentionOperateParams } from 'wdBean';
import { PageRepository } from '../../repository/PageRepository';
import { CommonConstants } from 'wdConstant/Index';
import { ProcessUtils } from 'wdRouter';

/**
 * 小视频横划卡
 * Zh_Single_Row-02
 */
const TAG = 'Zh_Single_Row-02'

@Component
export struct ZhSingleRow02 {
  @State compDTO: CompDTO = {} as CompDTO

  build() {
    Column() {
      //顶部
      this.CompHeader(this.compDTO)
      Row(){
        // 列表内容
        List() {
          ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
            CreatorItem({
              item
            })
              .margin({right: index === this.compDTO.operDataList.length - 1 ? $r('app.float.card_comp_pagePadding_lf') : 0})
          })
        }
        .listDirection(Axis.Horizontal)
        .scrollBar(BarState.Off)
      }
      .width(CommonConstants.FULL_WIDTH)
      .height(208)
    }
    .padding({
      left: $r('app.float.card_comp_pagePadding_lf'),
      // right: $r('app.float.card_comp_pagePadding_lf'),
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
    .backgroundColor($r('app.color.white'))
    .margin({ bottom: 8 })
  }

  @Builder
  CompHeader(item: CompDTO) {
    Row() {
      Row() {
        Image($r("app.media.redLine"))
          .width(3)
          .height(16)
          .margin({ right: 4 })
        Text(item.objectTitle)
          .fontSize($r("app.float.font_size_17"))
          .fontColor($r("app.color.color_222222"))
          .fontWeight(600)
      }

      Row() {
        Text("更多")
          .fontSize($r("app.float.font_size_14"))
          .fontColor($r("app.color.color_999999"))
          .margin({ right: 1 })
        Image($r("app.media.more"))
          .width(14)
          .height(14)
          .onClick(() => {
            // TODO 跳转的页面,定义的入参可能不合理。推荐id: 41
            let params = {'index': "1"} as Record<string, string>
            WDRouterRule.jumpWithPage(WDRouterPage.followListPage, params)
          })
      }
      .padding({
        right: $r('app.float.card_comp_pagePadding_lf'),
      })
      .onClick(() => {
        if (this.compDTO?.objectType === '11') {
          ProcessUtils.jumpChannelTab(this.compDTO.objectId, this.compDTO.pageId as string)
        } else if (this.compDTO?.objectType === '5') {
          ProcessUtils._gotoSpecialTopic(this.compDTO.linkUrl)
        } else if (this.compDTO?.objectType === '6') {
          ProcessUtils._gotoDefaultWeb(this.compDTO.linkUrl)
        }
      })
    }
    .justifyContent(FlexAlign.SpaceBetween)
    .margin({ top: 8, bottom: 8 })
    .width('100%')
  }
}

@Extend(Text)
function textOverflowStyle(maxLine: number) {
  .maxLines(maxLine)
  .textOverflow({ overflow: TextOverflow.Ellipsis })
}

@Component
struct CreatorItem {
  @Prop item: ContentDTO
  @State rmhIsAttention: number = 0
  build() {
    ListItem() {
      Column() {
        Stack({ alignContent: Alignment.Bottom }) {
          Image(this.item.coverUrl)
            .width(156)
            .height(208)
          Row()
            .width(156)
            .height(80)
            .linearGradient({
              direction: GradientDirection.Bottom,
              colors: [['rgba(0, 0, 0, 0.0)', 0.0], ['rgba(0, 0, 0, 0.3)', 1.0]]
            })
          Text(this.item.newsTitle)
            .fontColor(0xffffff)
            .fontSize(14)
            .maxLines(2)
            .textOverflow({overflow: TextOverflow.Ellipsis})
            .width(140)
            .margin({bottom: 8})
        }
      }
      .width(156)
      .height(208)
      .margin({ right: 11 })
      .borderColor($r('app.color.color_EDEDED'))
      .borderRadius($r('app.float.image_border_radius'))
    }
    .onClick((event: ClickEvent) => {
      ProcessUtils.processPage(this.item)
    })
  }

  /**
   * 关注号主 TODO 这里后面需要抽离
   */
  handleAccention(item: ContentDTO, status: number) {
    this.rmhIsAttention = this.rmhIsAttention ? 0 : 1
    return
    // 未登录,跳转登录
    if (!HttpUrlUtils.getUserId()) {
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }

    const params: postInteractAccentionOperateParams = {
      attentionUserType: item.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
      attentionUserId: item.rmhInfo?.userId || '', // 被关注用户号主id
      attentionCreatorId: item.rmhInfo?.rmhId || '', // 被关注用户号主id
      // userType: 1,
      // userId: '1', // TODO 用户id需要从本地获取
      status: status,
    }
    PageRepository.postInteractAccentionOperate(params).then(res => {
      console.log(TAG, '关注号主==', JSON.stringify(res.data))
      if (status === 1) {
        this.rmhIsAttention = 0
      } else {
        this.rmhIsAttention = 1
      }
    })
  }
}