douaojie

Merge remote-tracking branch 'origin/main'

... ... @@ -47,6 +47,10 @@ export class HttpUrlUtils {
*/
static readonly INTERACT_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/content/interactData";
/**
* 查询各类型内容动态数据接口V2:其他场景的均调用V2---api缓存1-2s
*/
static readonly INTERACT_V2_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/v2/content/interactData";
/**
* 查询视频频道推荐楼层
*/
static readonly DISPLAY_REC_COMPINFO: string = "/api/rmrb-bff-display-zh/display/zh/c/rec/compInfo";
... ...
import { AccountManagerUtils, Logger, DateTimeUtils, SPHelper } from 'wdKit';
import { AccountManagerUtils, Logger, DateTimeUtils, SPHelper, NumberFormatterUtils } from 'wdKit';
import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
import { ContentDetailDTO,postBatchAttentionStatusParams,
PhotoListBean,
ContentDTO,
RmhInfoDTO, } from 'wdBean';
batchLikeAndCollectResult,
RmhInfoDTO,
InteractDataDTO, } from 'wdBean';
import media from '@ohos.multimedia.media';
import { OperRowListView } from './view/OperRowListView';
import { WDPlayerController } from 'wdPlayer/Index';
import {
batchLikeAndCollectParams,
batchLikeAndCollectResult,
ContentDetailRequest,
contentListParams,
postExecuteCollectRecordParams,
... ... @@ -32,25 +33,23 @@ export struct DynamicDetailComponent {
private relId: string = ''
private contentId: string = ''
private relType: string = ''
//出参 fixme 模拟数据用json转换
//出参
@State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
//变量
//UI
scroller: Scroller = new Scroller();
//点赞 收藏 评论 数量
@State interactDataDTO: InteractDataDTO = {} as InteractDataDTO
/**
* 默认未关注 点击去关注
* 关注状态:默认未关注 点击去关注
*/
@State followStatus: String = '0';
@State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
@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()
}
... ... @@ -327,17 +326,28 @@ export struct DynamicDetailComponent {
.margin({ top: $r('app.float.margin_24')})
//点赞
Row(){
Image($r('app.media.icon_like_selected_redheart'))
Image(this.newsStatusOfUser?.likeStatus == '1'?
$r('app.media.icon_like_selected_redheart')
:$r('app.media.icon_like_unselect_grey_redheart'))
.width($r('app.float.margin_24'))
.height($r('app.float.margin_24'))
.objectFit(ImageFit.Cover)
Text("2.6万")
Text(NumberFormatterUtils.formatNumberWithWan(this.interactDataDTO?.likeNum))
.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')})
}
.width($r('app.float.margin_154'))
.height($r('app.float.margin_40'))
.margin({top:$r('app.float.margin_16')})
.borderWidth($r('app.float.margin_1'))
.borderColor($r('app.color.color_EDEDED'))
.borderRadius($r('app.float.margin_20'))
.onClick((event: ClickEvent) => {
//点赞操作
this.toggleLikeStatus()
})
Blank().layoutWeight(1)
//fixme 评论组件
}
... ... @@ -405,27 +415,30 @@ export struct DynamicDetailComponent {
this.getBatchAttentionStatus()
this.getInteractDataStatus()
this.makeJumpInfo()
this.interactDataV2()
}
// 查询当前登录用户点赞状态
private async interactDataV2() {
this.interactDataDTO = await MultiPictureDetailViewModel.interactDataV2(
this.contentDetailData?.newsId+'',this.contentDetailData?.newsType+'',this.contentDetailData.reLInfo == null ?'':this.contentDetailData.reLInfo?.relId,this.contentDetailData.rmhPlatform)
}
// 已登录->查询用户对作品点赞、收藏状态
private async getInteractDataStatus() {
//未登录
if(!AccountManagerUtils.isLoginSync() || this.contentDetailData?.openLikes != 1){
return
}
try {
const params: batchLikeAndCollectParams = {
contentList: [
{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
contentId: this.contentDetailData[0]?.newsId + '',
contentType: this.contentDetailData[0]?.newsType + '',
}
]
}
console.error(TAG, JSON.stringify(this.contentDetailData))
let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
// this.newsStatusOfUser = data[0];
this.newsStatusOfUser = data[0];
Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
} catch (exception) {
console.error(TAG, JSON.stringify(exception))
... ... @@ -524,6 +537,37 @@ export struct DynamicDetailComponent {
}
})
}
/**
* 点赞、取消点赞
*/
async toggleLikeStatus() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params: postExecuteLikeParams = {
status: this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1',
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
}
ContentDetailRequest.postExecuteLike(params).then(res => {
if (this.newsStatusOfUser) {
this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1'
if (this.newsStatusOfUser.likeStatus === '1') {
this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) + 1
} else {
this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) - 1
}
console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactDataDTO?.likeNum)
// this.queryContentInteractCount()
}
})
}
}
interface radiusType {
... ...
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { DateTimeUtils, Logger } from 'wdKit';
import { DateTimeUtils, Logger, StringUtils } from 'wdKit';
import {
batchLikeAndCollectResult,
CompInfoBean,
... ... @@ -128,6 +128,19 @@ export class PageRepository {
return url;
}
static getInteractDataV2Url(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number) {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_V2_DATA_PATH;
url = url + "?contentId=" + contentId
+ "&contentType=" + contentType
if(!StringUtils.isEmpty(contentRelId)){
url = url + "&contentRelId=" + contentRelId;
}
url = url + "&rmhPlatform=" + rmhPlatform;
url = url + "&detail=" + '1';
Logger.info(TAG, "getInteractDataV2Url url = " + url)
return url;
}
static getInteractDataUrl() {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH;
Logger.info(TAG, "getInteractDataUrl url = " + url)
... ... @@ -253,6 +266,12 @@ export class PageRepository {
return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url, headers)
};
static fetchInteractDataV2(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number) {
let url = PageRepository.getInteractDataV2Url(contentId, contentType, contentRelId,rmhPlatform)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<InteractDataDTO>>(url, headers)
};
static fetchInteractData(param: object) {
let url = PageRepository.getInteractDataUrl()
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
... ...
... ... @@ -5,7 +5,8 @@ import { ContentDetailDTO,
batchLikeAndCollectResult,
postBatchAttentionStatusParams,
postBatchAttentionStatusResult,
postInteractBrowsOperateParams
postInteractBrowsOperateParams,
InteractDataDTO
} from 'wdBean';
import { PageRepository } from '../repository/PageRepository';
... ... @@ -106,4 +107,28 @@ export class MultiPictureDetailViewModel {
})
}
//查询点赞数量
static async interactDataV2(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number): Promise<InteractDataDTO> {
return new Promise<InteractDataDTO>((success, error) => {
Logger.info(TAG, `interactDataV2 start`);
PageRepository.fetchInteractDataV2(contentId, contentType, contentRelId,rmhPlatform).then((resDTO: ResponseDTO<InteractDataDTO>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'interactDataV2 is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `interactDataV2 then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.info(TAG, "interactDataV2 then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
}).catch((err: Error) => {
Logger.error(TAG, `interactDataV2 catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
}
... ...
... ... @@ -117,6 +117,10 @@
"value": "28vp"
},
{
"name": "margin_40",
"value": "40vp"
},
{
"name": "margin_48",
"value": "48vp"
},
... ... @@ -129,6 +133,10 @@
"value": "60vp"
},
{
"name": "margin_154",
"value": "154vp"
},
{
"name": "single_row_03_img_height",
"value": "88vp"
},
... ... @@ -185,6 +193,10 @@
"value": "24vp"
},
{
"name": "margin_1",
"value": "1vp"
},
{
"name": "margin_6",
"value": "6vp"
},
... ...