DynamicDetailComponent.ets 17.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
import { AccountManagerUtils, Logger, DateTimeUtils  } from 'wdKit';
import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
import { ContentDetailDTO,batchLikeAndCollectResult,batchLikeAndCollectParams,postBatchAttentionStatusParams,
  PhotoListBean,
  ContentDTO,
  RmhInfoDTO, } from 'wdBean';
import media from '@ohos.multimedia.media';
import { OperRowListView } from './view/OperRowListView';
import { WDPlayerController } from 'wdPlayer/Index';
import { ContentConstants } from '../constants/ContentConstants';
import { ProcessUtils } from 'wdRouter';
import { StringUtils } from 'wdKit/src/main/ets/utils/StringUtils';
import display from '@ohos.display';
import { BusinessError } from '@ohos.base';
import { CommonConstants } from 'wdConstant/Index';
import { CardMediaInfo } from '../components/cardCommon/CardMediaInfo'
const TAG = 'DynamicDetailComponent'
@Preview
@Component
export struct DynamicDetailComponent {
  //入参
  private relId: string = ''
  private contentId: string = ''
  private relType: string = ''
  //出参 fixme 模拟数据用json转换
  @State contentDetailData: ContentDetailDTO = {
    publishTime: "2023年03月14日 08:16",
    rmhInfo:{rmhHeadUrl:"",rmhName:"人民号名称",rmhDesc:"人民号描述单行展示"},
    newsContent:"优先展示这个内容",
    newsSummary:"其次展示这个内容",
    newsTitle:"上面两个都没有再展示这个内容",
    newsType:15
  } as ContentDetailDTO
  //变量
  /**
   * 默认未关注 点击去关注
   */
  private  followStatus: String = '0';
  @State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态

  //跳转
  private mJumpInfo: ContentDTO = {} as ContentDTO;

  // 获取当前所有的display对象
  promise: Promise<Array<display.Display>> = display.getAllDisplays()

  // 屏幕宽度(单位px)
  @State screenWidth: number = 0;

  async aboutToAppear() {
    await this.getContentDetailData()
  }
  onPageHide() {

  }

  build() {
    Row() {
      Column(){
        //logo、日期
        Row() {
          Image($r('app.media.ic_article_rmh'))
            .width($r('app.float.margin_80'))
            .height($r('app.float.margin_28'))
            .margin({ left: $r('app.float.margin_16') })
          Blank()
          Text(this.contentDetailData.publishTime)
            .fontColor($r('app.color.color_B0B0B0'))
            .fontSize($r('app.float.font_size_12'))
            .lineHeight($r('app.float.margin_28'))
            .margin({ right: $r('app.float.margin_16') })
        }
        .height($r('app.float.margin_48'))
        .width('100%')
        //分割线
        Image($r('app.media.ic_news_detail_division'))
            .width('100%')
            .height($r('app.float.margin_7'))
            .margin({left: $r('app.float.margin_16'), right: $r('app.float.margin_16')} )
        //号主信息
        Row() {
          //头像
          Stack() {
            Image(this.contentDetailData.rmhInfo?.rmhHeadUrl)
              .alt(this.contentDetailData.rmhInfo?.userType=='1'?$r('app.media.default_head'):$r('app.media.icon_default_head_mater'))
              .width($r('app.float.margin_32'))
              .height($r('app.float.margin_32'))
              .objectFit(ImageFit.Cover)
              .borderRadius($r('app.float.margin_16'))
            Image($r('app.media.icon_border_test'))
              .width($r('app.float.margin_48'))
              .height($r('app.float.margin_48'))
              .objectFit(ImageFit.Cover)
              .borderRadius($r('app.float.margin_24'))
          }
          .width($r('app.float.margin_48'))
          .height($r('app.float.margin_48'))
          .alignContent(Alignment.Center)
          Column(){
            //昵称
            Text(this.contentDetailData.rmhInfo?.rmhName)
              .fontSize($r('app.float.font_size_14'))
              .fontColor($r('app.color.color_222222'))
              .fontWeight(FontWeight.Medium)
              .margin({ left: $r('app.float.margin_5') })
              .alignSelf(ItemAlign.Start)
            //简介
            Text(this.contentDetailData.rmhInfo?.rmhDesc)
              .fontSize($r('app.float.font_size_14'))
              .fontColor($r('app.color.color_B0B0B0'))
              .fontWeight(FontWeight.Medium)
              .maxLines(1)
              .margin({ left: $r('app.float.margin_5') })
              .alignSelf(ItemAlign.Start)
          }
          .width('63%')
          .margin({right: $r('app.float.margin_6')})
          if (this.followStatus == '0') {
            Text('关注')
              .width($r('app.float.margin_54'))
              .height($r('app.float.margin_24'))
              .textAlign(TextAlign.Center)
              .fontSize($r('app.float.font_size_12'))
              .borderRadius($r('app.float.vp_3'))
              .backgroundColor($r('app.color.color_ED2800'))
              .fontColor($r('app.color.color_fff'))
              .onClick(() => {
                // this.handleAccention(this.item, 1)
              })
          } else {
            Text('已关注')
              .width($r('app.float.margin_54'))
              .height($r('app.float.margin_24'))
              .borderWidth(1)
              .textAlign(TextAlign.Center)
              .fontSize($r('app.float.font_size_12'))
              .borderRadius($r('app.float.vp_3'))
              .borderColor($r('app.color.color_CCCCCC'))
              .fontColor($r('app.color.color_CCCCCC'))
              .onClick(() => {
                // this.handleAccention(this.item, 0)
              })
          }
        }
        .width('100%')
        .margin({ left: $r('app.float.margin_16')})
        //内容
        Text(StringUtils.isEmpty(this.contentDetailData.newsContent)
          ?StringUtils.isEmpty(this.contentDetailData.newsSummary)
            ?this.contentDetailData.newsTitle
            :this.contentDetailData.newsSummary
          :this.contentDetailData.newsContent)
          .fontColor($r('app.color.color_222222'))
          .fontSize($r('app.float.font_size_18'))
          .lineHeight($r('app.float.margin_25'))
          .margin({ top: $r('app.float.margin_6')
          ,left: $r('app.float.margin_16')
          ,right: $r('app.float.margin_16') })
          .alignSelf(ItemAlign.Start)
        if(this.contentDetailData.newsType+"" == ContentConstants.TYPE_FOURTEEN){
          //附件内容:图片/视频
          if(this.contentDetailData.photoList!= null && this.contentDetailData.photoList.length>0){
            // 图片-从无图到9图展示
            GridRow({
              gutter: { x: 2, y: 2 }
            }) {
              ForEach(this.contentDetailData.photoList, (item: PhotoListBean, index: number) => {
                if (this.contentDetailData.photoList.length === 1) {
                  if (this.getPicType(item) !== 3) {
                    GridCol({
                      span: this.getPicType(item) === 1 ? 12 : 8
                    }){
                      Stack({
                        alignContent: Alignment.BottomEnd
                      }) {
                        if (this.getPicType(item) === 1) {
                          Image(item.picPath)
                            .width('100%')
                            .height(172)
                            .autoResize(true)
                            .borderRadius(this.caclImageRadius(index))
                        } else if (this.getPicType(item) === 2) {
                          Image(item.picPath)
                            .width('100%')
                            .height(305)
                            .autoResize(true)
                            .borderRadius(this.caclImageRadius(index))
                        }
                        Flex({ direction: FlexDirection.Row }) {
                          Image($r('app.media.icon_long_pic'))
                            .width(14)
                            .height(14)
                            .margin({right: 4})
                          Text('长图')
                            .fontSize(12)
                            .fontWeight(400)
                            .fontColor(0xffffff)
                            .fontFamily('PingFang SC')
                        }
                        .width(48)
                        .padding({bottom: 9})

                      }
                    }
                    .onClick((event: ClickEvent) => {
                      ProcessUtils.gotoMultiPictureListPage(this.contentDetailData.photoList)
                    })
                  } else {
                    GridCol({
                      span: { xs: 8 }
                    }) {
                      Image(item.picPath)
                        .width('100%')
                        .borderRadius(this.caclImageRadius(index))
                        .autoResize(true)
                        .opacity(!item.width && !item.height ? 0 : 1)
                        .onComplete(callback => {
                          item.width = callback?.width || 0;
                          item.height = callback?.height || 0;
                        })
                    }
                  }
                } else if (this.contentDetailData.photoList.length === 4) {
                  GridCol({
                    span: { xs: 4 }
                  }) {
                    Image(item.picPath)
                      .aspectRatio(1)
                      .borderRadius(this.caclImageRadius(index))
                  }
                } else {
                  GridCol({
                    span: { sm: 4, lg: 3 }
                  }) {
                    Image(item.picPath)
                      .aspectRatio(1)
                      .borderRadius(this.caclImageRadius(index))
                  }
                }
              })
            }
            .margin({ left: $r('app.float.margin_16'),right: $r('app.float.margin_16'),top: $r('app.float.margin_8')})
          }
        }else{
          if(this.contentDetailData.videoInfo!= null && this.contentDetailData.videoInfo.length>0){
            GridRow() {
              if (this.contentDetailData.videoInfo[0].videoLandScape === 1) {
                // 横屏
                GridCol({
                  span: { xs: 12 }
                }) {
                  Stack() {
                    Image(this.contentDetailData.fullColumnImgUrls!= null && this.contentDetailData.fullColumnImgUrls.length>0&&!StringUtils.isEmpty(this.contentDetailData.fullColumnImgUrls[0].url)?
                            this.contentDetailData.fullColumnImgUrls[0].url:
                    this.contentDetailData.videoInfo[0].firstFrameImageUri)
                      .width(CommonConstants.FULL_WIDTH)
                      .aspectRatio(16 / 9)
                      .borderRadius($r('app.float.image_border_radius'))
                    CardMediaInfo({ contentDTO: this.mJumpInfo })
                  }
                  .align(Alignment.BottomEnd)
                }
              } else {
                // 竖图显示,宽度占50%,高度自适应
                GridCol({
                  span: { xs: 6 }
                }) {
                  Stack() {
                    Image(this.contentDetailData.fullColumnImgUrls!= null && this.contentDetailData.fullColumnImgUrls.length>0&&!StringUtils.isEmpty(this.contentDetailData.fullColumnImgUrls[0].url)?
                    this.contentDetailData.fullColumnImgUrls[0].url:
                    this.contentDetailData.videoInfo[0].firstFrameImageUri)
                      .width(CommonConstants.FULL_WIDTH)
                      .borderRadius($r('app.float.image_border_radius'))
                    CardMediaInfo({ contentDTO: this.mJumpInfo })
                  }
                  .align(Alignment.BottomEnd)
                }
              }
            }
            .margin({ left: $r('app.float.margin_16'),right: $r('app.float.margin_16'),top: $r('app.float.margin_8')})
            .onClick((event: ClickEvent) => {
              this.mJumpInfo.objectType = ContentConstants.TYPE_VOD;
              ProcessUtils.processPage(this.mJumpInfo)
            })
          }
        }
        //特别声明
        Text("特别声明:本文为人民日报新媒体平台“人民号”作者上传并发布,仅代表作者观点。人民日报仅提供信息发布平台。")
          .fontColor($r('app.color.color_CCCCCC'))
          .fontSize($r('app.float.font_size_12'))
          .lineHeight($r('app.float.margin_16'))
          .margin({ top: $r('app.float.margin_16')
          ,left: $r('app.float.margin_16')
          ,right: $r('app.float.margin_16') })
        //微信/朋友圈/微博
        Row(){
          Image($r('app.media.xxhdpi_pic_wechat'))
            .width($r('app.float.margin_116'))
            .height($r('app.float.margin_36'))
            .objectFit(ImageFit.Cover)
          Image($r('app.media.xxhdpi_pic_pyq'))
            .width($r('app.float.margin_116'))
            .height($r('app.float.margin_36'))
            .margin({ left: $r('app.float.margin_4_negative')})
            .objectFit(ImageFit.Cover)
          Image($r('app.media.xxhdpi_pic_wb'))
            .width($r('app.float.margin_116'))
            .height($r('app.float.margin_36'))
            .margin({ left: $r('app.float.margin_4_negative')})
            .objectFit(ImageFit.Cover)
        }
        .margin({ top: $r('app.float.margin_24')})
        //点赞
        Row(){
          Image($r('app.media.icon_like_selected_redheart'))
            .width($r('app.float.margin_24'))
            .height($r('app.float.margin_24'))
            .objectFit(ImageFit.Cover)
          Text("2.6万")
            .fontColor($r('app.color.color_999999'))
            .fontSize($r('app.float.font_size_16'))
            .lineHeight($r('app.float.margin_20'))
            .margin({ left: $r('app.float.margin_2')})
        }
        //评论组件/底部组件

      }
      .alignSelf(ItemAlign.Start)
    }
    .backgroundColor('#FFFFFFFF')
    .width('100%')
    .height('100%')
  }
  /**
   * 请求(动态)详情页数据
   * */
  private async getContentDetailData() {
    try {
      let data = await MultiPictureDetailViewModel.getDetailData(this.relId, this.contentId, this.relType)
      this.contentDetailData = data[0];
      console.log('动态详情',JSON.stringify(this.contentDetailData))
    } catch (exception) {
    console.log('请求失败',JSON.stringify(exception))
    }
    this.getBatchAttentionStatus()
    this.getInteractDataStatus()
    this.makeJumpInfo()
  }

  // 查询当前登录用户点赞状态
  private async getInteractDataStatus() {
    //未登录
    if(!AccountManagerUtils.isLoginSync() || this.contentDetailData?.openLikes != 1){
      return
    }
    try {
      const params: batchLikeAndCollectParams = {
        contentList: [
          {
            contentId: this.contentDetailData?.newsId + '',
            contentType: this.contentDetailData?.newsType + '',
          }
        ]
      }
      console.error(TAG, JSON.stringify(this.contentDetailData))
      let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
      console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
      this.newsStatusOfUser = data[0];
      Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
    } catch (exception) {
      console.error(TAG, JSON.stringify(exception))
    }
  }

  /**
   * 查询当前登录用户是否关注作品号主
   * */
  private async getBatchAttentionStatus() {
    try {
      const params: postBatchAttentionStatusParams = {
        creatorIds: [{ creatorId: this.contentDetailData?.rmhInfo?.rmhId ?? '' }]
      }
      let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params)
      this.followStatus = data[0]?.status;
      Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`)
    } catch (exception) {

    }
  }

  //创建跳转信息
  makeJumpInfo(){
    this.mJumpInfo.pageId = 'dynamicDetailPage';
    // this.mJumpInfo.from = 'dynamicDetailPage';
    this.mJumpInfo.objectId = this.contentDetailData.newsId+"";
    this.mJumpInfo.relType = this.contentDetailData.reLInfo?.relType+"";
    this.mJumpInfo.relId = this.contentDetailData.reLInfo?.relId+"";
    // this.mJumpInfo.objectType = this.contentDetailData.newsType+"";
  }


  caclImageRadius(index: number) {
    let radius: radiusType = {
      topLeft: index === 0 ? $r('app.float.image_border_radius') : 0,
      topRight: 0,
      bottomLeft: 0,
      bottomRight: 0,
    }
    if (this.contentDetailData.photoList.length === 1) {
      radius.topRight = index === 0 ? $r('app.float.image_border_radius') : 0
      radius.bottomLeft = index === 0 ? $r('app.float.image_border_radius') : 0
      radius.bottomRight = index === 0 ? $r('app.float.image_border_radius') : 0
    } else if (this.contentDetailData.photoList.length === 5 && !this.contentDetailData.photoList[2].fullUrl) {
      radius.topRight = index === 1 ? $r('app.float.image_border_radius') : 0
      radius.bottomLeft = index === 3 ? $r('app.float.image_border_radius') : 0
      radius.bottomRight = index === 4 ? $r('app.float.image_border_radius') : 0
    } else {
      radius.topRight = index === 2 ? $r('app.float.image_border_radius') : 0
      radius.bottomLeft = index === 6 ? $r('app.float.image_border_radius') : 0
      radius.bottomRight = index === 8 ? $r('app.float.image_border_radius') : 0
    }
    return radius
  }

  getPicType(item: PhotoListBean){
    if (item.width && item.width) {
      if (item.width / item.height > 343/172) {
        return 1; //横长图
      } else if (item.height / item.width > 305/228) {
        return 2; //竖长图
      } else {
        return 3
      }
    } else {
      return 3; //普通图
    }
  }
}

interface radiusType {
  topLeft: number | Resource;
  topRight: number | Resource;
  bottomLeft: number | Resource;
  bottomRight: number | Resource;
}