PlayerRightView.ets 14.9 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
import { ContentDetailDTO, InteractDataDTO, Params, } from 'wdBean/Index';
import {
  batchLikeAndCollectResult,
  ContentDetailRequest,
  contentListParams,
  postExecuteCollectRecordParams,
  postExecuteLikeParams,
  postInteractAccentionOperateParams
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';

import { SPHelper, ToastUtils, NumberFormatterUtils } from 'wdKit';
import { WDPlayerController } from 'wdPlayer/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { DisplayDirection, SpConstants } from 'wdConstant/Index'
import { WDShare } from "wdShare"
import { publishCommentModel } from 'wdComponent/Index';
import { ParamType, TrackConstants, TrackingButton, TrackingContent } from 'wdTracking/Index';

interface ILikeStyleResp {
  url: Resource;
  name: string;
}

const TAG = 'PlayerRightView';


//视频点播页右侧操作栏:点赞/收藏/评论/分享 竖着排列
@Component
export struct PlayerRightView {
  private playerController?: WDPlayerController;
  @Consume interactData: InteractDataDTO
  @Consume contentDetailData: ContentDetailDTO
  @Consume newsStatusOfUser: batchLikeAndCollectResult
  @Consume followStatus: string
  @Consume isOpenDetail: boolean
  @Consume isDragging: boolean
  @Consume showComment?: boolean
  @Consume showCommentList: boolean
  @Consume displayDirection: DisplayDirection
  @Consume publishCommentModel: publishCommentModel
  @State likesStyle: number | string = 1 // 赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空
  @State openLikes: boolean = false // 是否可以点赞  1:可以 0:不可以
  pageParam: ParamType = {}
  @Consume pageName: string
  @Consume pageId: string
  followUserId: string = ''
  followUserName: string = ''

  aboutToAppear() {
    // 内容用 点赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空
    this.likesStyle = this.contentDetailData.likesStyle
    this.openLikes = this.contentDetailData.openLikes == 1 ? true : false
    // console.log(TAG, 'this.likesStyle', this.likesStyle)
    // console.log(TAG, 'this.openLikes', this.openLikes)
    this.contentTrackingDict()
  }
  contentTrackingDict(){
    this.pageParam = {
      'contentType': `${this.contentDetailData.newsType}`,
      'contentId': `${this.contentDetailData.newsId}`,
      'contentName': `${this.contentDetailData.newsTitle || ''}`,
    }
    this.followUserId = this.contentDetailData?.rmhInfo?.rmhId || ''
    this.followUserName = this.contentDetailData?.rmhInfo?.rmhName || ''
  }
  /**
   * 点赞、取消点赞
   */
  async toggleLikeStatus() {
    // 未登录,跳转登录
    const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
    if (!user_id) {
      this.playerController?.pause()
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }
    const params: postExecuteLikeParams = {
      status: this.newsStatusOfUser?.likeStatus == '1' ? 0 : 1,
      contentId: this.contentDetailData?.newsId + '',
      contentType: this.contentDetailData?.newsType + '',
      userName: this.contentDetailData?.userInfo?.userName || '' + '',
      contentRelId: this.contentDetailData?.reLInfo?.relId || '' + '',
      title: this.contentDetailData?.newsTitle || '' + '',
      channelId: this.contentDetailData?.reLInfo?.channelId || '' + '',
      relType: this.contentDetailData?.reLInfo?.relType || '' + '',
      userHeaderUrl: this.contentDetailData?.userInfo?.headPhotoUrl || '' + '',
    }
    console.log(TAG, '点赞params', JSON.stringify(params))
    ContentDetailRequest.postExecuteLike(params).then(res => {
      console.log(TAG, '点赞this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser))
      if (this.newsStatusOfUser) {
        this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus == '1' ? '0' : '1'
        if (this.newsStatusOfUser.likeStatus == '1') {
          this.interactData.likeNum = Number(this.interactData.likeNum || 0) + 1
          TrackingContent.like(true,this.pageId,this.pageName,this.pageParam)
          console.log(TAG, '点赞')
        } else {
          this.interactData.likeNum = Math.max(0, Number(this.interactData.likeNum || 0) - 1)
          TrackingContent.like(false,this.pageId,this.pageName,this.pageParam)
          console.log(TAG, '取消点赞')
        }
        console.log(TAG, '点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactData?.likeNum)
        // this.queryContentInteractCount()
      }

    })
  }

  /**
   * 收藏、取消收藏
   */
  async toggleCollectStatus() {
    // 未登录,跳转登录
    const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
    if (!user_id) {
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }
    const params: postExecuteCollectRecordParams = {
      status: this.newsStatusOfUser?.collectStatus === 1 ? '0' : '1',
      contentList: [{
        contentId: this.contentDetailData?.newsId + '',
        contentType: this.contentDetailData?.newsType + '',
        relType: this.contentDetailData?.reLInfo?.relType || '' + '',
        contentRelId: this.contentDetailData?.reLInfo?.relId || '' + '',
      }],

    }
    ContentDetailRequest.postExecuteCollectRecord(params).then(res => {
      if (this.newsStatusOfUser) {
        this.newsStatusOfUser.collectStatus = this.newsStatusOfUser?.collectStatus === 1 ? 0 : 1
        // this.queryContentInteractCount()
        if (this.newsStatusOfUser.collectStatus === 1) {
          this.interactData.collectNum = Number(this.interactData.collectNum || 0) + 1
          TrackingContent.collect(true,this.pageId,this.pageName,this.pageParam)
          console.log(TAG, '收藏')
        } else {
          this.interactData.collectNum = Math.max(0, Number(this.interactData.collectNum || 0) - 1)
          TrackingContent.collect(false,this.pageId,this.pageName,this.pageParam)
          console.log(TAG, '取消收藏')
        }
        console.log(TAG, '收藏、取消收藏==', this.newsStatusOfUser?.collectStatus, this.interactData?.collectNum)
      }
    })

  }

  /**
   * 查询点赞、收藏数量
   */
  queryContentInteractCount() {
    const params: contentListParams = {
      contentList: [{
        contentId: this.contentDetailData?.newsId + '',
        contentType: this.contentDetailData?.newsType,
      }]
    }
    ContentDetailRequest.getContentInteract(params).then(res => {
      if (res.data && this.interactData) {
        this.interactData.likeNum = res.data[0]?.likeNum || 0
        this.interactData.collectNum = res.data[0]?.collectNum || 0
        this.interactData.commentNum = res.data[0]?.commentNum || 0
      }
      console.log('获取互动点赞等数据===', JSON.stringify(res))
    })
  }

  getHeadUrl() {
    return this.contentDetailData?.rmhInfo?.rmhHeadUrl || this.contentDetailData?.userInfo?.userHeadUrl
  }

  /**
   * 关注号主
   */
  async handleAccention() {
    // 未登录,跳转登录
    const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
    if (!user_id) {
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }

    const params2: postInteractAccentionOperateParams = {
      attentionUserType: this.contentDetailData?.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
      attentionUserId: this.contentDetailData?.rmhInfo?.userId || '', // 被关注用户号主id
      attentionCreatorId: this.contentDetailData?.rmhInfo?.rmhId || '', // 被关注用户号主id
      // userType: 1,
      // userId: '1',
      status: 1,
    }
    ContentDetailRequest.postInteractAccentionOperate(params2).then(res => {
      console.log(TAG, '关注号主==', JSON.stringify(res.data))
      if (this.followStatus == '1') {
        this.followStatus = '0'
      } else {
        this.followStatus = '1'
        ContentDetailRequest.postPointLevelOperate({ operateType: 6 }).then((res) => {
          if (res.data?.showToast) {
            ToastUtils.showToast(res.data.ruleName + '+' + res.data.rulePoint + '积分', 1000);
          }
        })
        console.log(TAG, '关注号主')
        TrackingContent.follow(true,this.followUserId,this.followUserName,this.pageId,this.pageName,this.pageParam)
      }
    })
  }

  build() {
    Column() {
      this.userBuilderView()
      if (this.contentDetailData?.openLikes == 1) {
        this.likeBuilderView()
      }
      this.collectBuilderView()
      if (this.contentDetailData?.openComment == 1) {
        this.commentBuilderView()
      }
      if(this.contentDetailData?.shareInfo?.shareOpen == 1) {
        this.shareBuilderView()
      }
    }
    // .backgroundColor(Color.Blue)
    // .height('100%')
    .width(58)
    .position({ x: '100%', y: '100%' })
    .markAnchor({ x: '100%', y: '100%' })
    .padding({ bottom: 7, right: 10 })
    .visibility(this.isOpenDetail || this.isDragging || this.displayDirection === DisplayDirection.VIDEO_HORIZONTAL ?
    Visibility.None : Visibility.Visible)

  }

  /**
   * 用户关注、号主页
   */
  @Builder
  userBuilderView() {
    Stack() {
      Image(this.getHeadUrl())
        .width('100%')
        .borderRadius(24)
        .aspectRatio(1)
        .border({ width: 1, color: Color.White, style: BorderStyle.Solid })
        .onClick(() => {
          // 跳转到号主页
          if (this.contentDetailData.rmhInfo?.cnMainControl === 1) {
            const params: Params = {
              creatorId: this.contentDetailData.rmhInfo.rmhId,
              pageID: ''
            }
            WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
          } else {
            ToastUtils.showToast("暂时无法查看该创作者主页", 2000);
          }
        })

      Image($r('app.media.ic_add'))
        .width(24)
        .borderRadius(12)
        .position({ x: '50%', y: '100%' })
        .markAnchor({ x: '50%', y: '50%' })
        .visibility(this.followStatus == '1' ? Visibility.None : Visibility.Visible)
        .onClick(() => {
          // TODO:关注动画
          this.handleAccention()
        })


    }
    .height(48)
    .width('100%')
    .margin({ bottom: 30 })
    .visibility(this.getHeadUrl() ? Visibility.Visible : Visibility.None)
  }

  /**
   * 将点赞样式转换为icon
   */
  transLikeStyle(): ILikeStyleResp {
    if (this.likesStyle === 1) {
      return {
        url: this.newsStatusOfUser.likeStatus == '1' ? $r(`app.media.ic_like_check`) : $r(`app.media.ic_like_uncheck`),
        name: '赞'
      }
    } else if (this.likesStyle === 2) {
      return {
        url: this.newsStatusOfUser.likeStatus == '1' ? $r(`app.media.ic_thub_check`) : $r(`app.media.ic_thub_uncheck`),
        name: '祈祷'
      }
    } else if (this.likesStyle === 3) {
      return {
        url: this.newsStatusOfUser.likeStatus == '1' ? $r(`app.media.ic_candle_check`) :
        $r(`app.media.ic_candle_uncheck`),
        name: '默哀'
      }
    }
    return {
      url: $r(`app.media.icon_like_ckeck`), name: '点赞'
    }
  }

  transNum2String(name: 'likeNum' | 'collectNum' | 'commentNum') {
    console.log(TAG, 'transNum2String', this.interactData.likeNum, this.interactData.collectNum,
      this.interactData.commentNum)
    if (name === 'likeNum') {
      return this.interactData.likeNum != 0 ?
      NumberFormatterUtils.formatNumberWithWan(this.interactData.likeNum || '') : ''
    } else if (name === 'collectNum') {
      return this.interactData.collectNum != 0 ?
      NumberFormatterUtils.formatNumberWithWan(this.interactData.collectNum || '') : ''
    } else {
      return this.interactData.commentNum != 0 ?
      NumberFormatterUtils.formatNumberWithWan(this.interactData.commentNum || '') : ''
    }
  }

  /**
   * 点赞、默哀、祈福
   */
  @Builder
  likeBuilderView() {
    Column() {
      Image(this.transLikeStyle().url)
        .width(32)
        .aspectRatio(1)

      Text(this.transNum2String('likeNum') || this.transLikeStyle().name)
        .width('100%')
        .fontWeight(500)
        .textAlign(TextAlign.Center)
        .fontSize(13)
        .fontColor('#FFFFFF')
        .maxLines(1)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .margin({ top: 2 })
    }
    .margin({ bottom: 20 })
    .visibility(this.likesStyle == 4 || this.likesStyle == 'empty' || !this.openLikes ? Visibility.None : Visibility.Visible)
    .onClick(() => {
      // TODO:点赞动画
      this.toggleLikeStatus()
    })
  }

  /**
   * 收藏、取消收藏、收藏文件夹
   */
  @Builder
  collectBuilderView() {
    Column() {
      Image(this.newsStatusOfUser.collectStatus == 1 ? $r(`app.media.ic_collect_check`) :
      $r(`app.media.ic_collect_uncheck`))
        .width(32)
        .aspectRatio(1)

      Text(this.transNum2String('collectNum') || '收藏')
        .width('100%')
        .fontWeight(500)
        .textAlign(TextAlign.Center)
        .fontSize(13)
        .fontColor('#FFFFFF')
        .maxLines(1)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .margin({ top: 2 })

    }
    .margin({ bottom: 20 })
    .onClick(() => {
      this.toggleCollectStatus()
    })
  }

  /**
   * 评论
   */
  @Builder
  commentBuilderView() {
    Column() {
      Image($r(`app.media.ic_comment`))
        .width(32)
        .aspectRatio(1)

      Text(this.interactData.commentNum > 0 ? this.transNum2String('commentNum') : '抢首评')
        .width('100%')
        .fontWeight(500)
        .textAlign(TextAlign.Center)
        .fontSize(13)
        .fontColor('#FFFFFF')
        .maxLines(1)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .margin({ top: 2 })
    }
    .margin({ bottom: 20 })
    .onClick((event: ClickEvent) => {
      this.publishCommentModel.targetId = String(this.contentDetailData?.newsId || '')
      this.publishCommentModel.targetRelId = String(this.contentDetailData?.reLInfo?.relId || '')
      this.publishCommentModel.targetTitle = this.contentDetailData?.newsTitle
      this.publishCommentModel.targetRelType = String(this.contentDetailData?.reLInfo?.relType || '')
      this.publishCommentModel.targetRelObjectId = String(this.contentDetailData?.reLInfo?.relObjectId || '')
      this.publishCommentModel.keyArticle = String(this.contentDetailData?.keyArticle || '')
      this.publishCommentModel.targetType = String(this.contentDetailData?.newsType || '')
      this.publishCommentModel.visitorComment = String(this.contentDetailData?.visitorComment || '')
      this.publishCommentModel.commentContent = ''

      // ToastUtils.showToast('评论为公共方法,待开发', 1000);
      this.showCommentList = true
    })
  }

  /**
   * 分享
   */
  @Builder
  shareBuilderView() {
    Column() {
      Image($r(`app.media.ic_share`))
        .width(32)
        .aspectRatio(1)

      Text('分享')
        .width('100%')
        .fontWeight(500)
        .textAlign(TextAlign.Center)
        .fontSize(13)
        .fontColor('#FFFFFF')
        .maxLines(1)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .margin({ top: 2 })
    }
    .margin({ bottom: 20 })
    .onClick((event: ClickEvent) => {
      this.share()
    })
  }

  share() {

    WDShare.shareContent(this.contentDetailData)
  }
}