zhaojunkai

人民号-动态Tab下的内容分享优化

1 -import { ToastUtils } from 'wdKit';  
2 - 1 +import { SPHelper,Logger,ToastUtils } from 'wdKit';
  2 +import { ContentDetailDTO, Action, ContentDTO,batchLikeAndCollectResult } from 'wdBean';
  3 +import { ProcessUtils } from 'wdRouter';
  4 +import router from '@ohos.router';
  5 +import { batchLikeAndCollectParams } from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
  6 +import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
  7 +import { SpConstants } from 'wdConstant/Index';
  8 +import { WDShare } from 'wdShare/Index';
  9 +const TAG = 'CarderInteraction'
3 /** 10 /**
4 * 卡片 分享、评论、点赞公用组件 11 * 卡片 分享、评论、点赞公用组件
5 */ 12 */
6 @Component 13 @Component
7 export struct CarderInteraction { 14 export struct CarderInteraction {
  15 + @Prop contentDTO: ContentDTO
  16 + @State contentId: string = ''
  17 + @State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
  18 + @State newsStatusOfUser: batchLikeAndCollectResult = {} as batchLikeAndCollectResult// 点赞、收藏状态
8 build() { 19 build() {
9 Row(){ 20 Row(){
10 Row(){ 21 Row(){
@@ -18,7 +29,7 @@ export struct CarderInteraction { @@ -18,7 +29,7 @@ export struct CarderInteraction {
18 } 29 }
19 .justifyContent(FlexAlign.Center) 30 .justifyContent(FlexAlign.Center)
20 .onClick(()=>{ 31 .onClick(()=>{
21 - ToastUtils.showToast('分享为公共方法,待开发', 1000) 32 + this.getContentDetailData()
22 }) 33 })
23 Row(){ 34 Row(){
24 Image($r('app.media.CarderInteraction_comment')) 35 Image($r('app.media.CarderInteraction_comment'))
@@ -31,7 +42,7 @@ export struct CarderInteraction { @@ -31,7 +42,7 @@ export struct CarderInteraction {
31 } 42 }
32 .justifyContent(FlexAlign.Center) 43 .justifyContent(FlexAlign.Center)
33 .onClick(()=>{ 44 .onClick(()=>{
34 - ToastUtils.showToast('分享为公共方法,待开发', 1000) 45 + ProcessUtils.processPage(this.contentDTO)
35 }) 46 })
36 Row(){ 47 Row(){
37 Image($r('app.media.CarderInteraction_like')) 48 Image($r('app.media.CarderInteraction_like'))
@@ -44,7 +55,8 @@ export struct CarderInteraction { @@ -44,7 +55,8 @@ export struct CarderInteraction {
44 } 55 }
45 .justifyContent(FlexAlign.Center) 56 .justifyContent(FlexAlign.Center)
46 .onClick(()=>{ 57 .onClick(()=>{
47 - ToastUtils.showToast('分享为公共方法,待开发', 1000) 58 + ProcessUtils.processPage(this.contentDTO)
  59 + // ToastUtils.showToast('点赞为公共方法,待开发', 1000)
48 }) 60 })
49 } 61 }
50 .width('100%') 62 .width('100%')
@@ -56,4 +68,45 @@ export struct CarderInteraction { @@ -56,4 +68,45 @@ export struct CarderInteraction {
56 .justifyContent(FlexAlign.SpaceBetween) 68 .justifyContent(FlexAlign.SpaceBetween)
57 .alignItems(VerticalAlign.Center) 69 .alignItems(VerticalAlign.Center)
58 } 70 }
  71 + /**
  72 + * 请求(动态)详情页数据
  73 + * */
  74 + private async getContentDetailData() {
  75 + try {
  76 + let data = await MultiPictureDetailViewModel.getDetailData(this.contentDTO.relId, this.contentDTO.objectId, this.contentDTO.relType)
  77 + this.contentDetailData = data[0];
  78 + console.log('动态详情',JSON.stringify(this.contentDetailData))
  79 + WDShare.shareContent(this.contentDetailData)
  80 + } catch (exception) {
  81 + console.log('请求失败',JSON.stringify(exception))
  82 + }
  83 + this.getInteractDataStatus()
  84 + }
  85 + // 已登录->查询用户对作品点赞、收藏状态
  86 + private async getInteractDataStatus() {
  87 + // 未登录,跳转登录
  88 + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
  89 + if (!user_id) {
  90 + return
  91 + }
  92 + try {
  93 + const params: batchLikeAndCollectParams = {
  94 + contentList: [
  95 + {
  96 + contentId: this.contentDetailData?.newsId + '',
  97 + contentType: this.contentDetailData?.newsType + '',
  98 + }
  99 + ]
  100 + }
  101 + console.error(TAG, JSON.stringify(this.contentDetailData))
  102 + let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
  103 + console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
  104 + this.newsStatusOfUser = data[0];
  105 + Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
  106 + } catch (exception) {
  107 + console.error(TAG, JSON.stringify(exception))
  108 + }
  109 + }
  110 +
59 } 111 }
  112 +
@@ -37,7 +37,7 @@ export struct Card20Component { @@ -37,7 +37,7 @@ export struct Card20Component {
37 if (this.contentDTO.fullColumnImgUrls[0]) { 37 if (this.contentDTO.fullColumnImgUrls[0]) {
38 createImg({ contentDTO: this.contentDTO }) 38 createImg({ contentDTO: this.contentDTO })
39 } 39 }
40 - CarderInteraction() 40 + CarderInteraction({contentDTO: this.contentDTO})
41 //TODO 底部的:分享、评论、点赞 功能;需要引用一个公共组件 41 //TODO 底部的:分享、评论、点赞 功能;需要引用一个公共组件
42 } 42 }
43 .padding({ 43 .padding({