王士厅

多图(图集)详情页评论、点赞调接口中

... ... @@ -23,7 +23,18 @@ export { Pic } from './src/main/ets/bean/content/Pic'
export { InteractDataDTO } from './src/main/ets/bean/content/InteractDataDTO';
export { InteractDataStatusBean, PhotoListBean, InputMethodProperty } from './src/main/ets/bean/detail/MultiPictureDetailPageDTO';
export {
PhotoListBean,
InputMethodProperty,
batchLikeAndCollectParams,
postBatchAttentionStatusParams,
postInteractBrowsOperateParams,
postBatchAttentionStatusResult,
batchLikeAndCollectResult,
postExecuteLikeParams,
postExecuteCollectRecordParams,
contentListParams
} from './src/main/ets/bean/detail/MultiPictureDetailPageDTO';
export { InteractParam, ContentBean } from './src/main/ets/bean/content/InteractParam';
... ...
/*
* 多图(图集)详情
* */
// 批量查询内容当前用户点赞、收藏状态
export interface InteractDataStatusBean {
contentId: string;
contentType: number;
contentRelId: string;
relType: number;
likeStatus: number;
collectStatus: number;
}
// 【图文、图集稿件正文图片】图片信息数组
export interface PhotoListBean {
... ... @@ -97,4 +88,83 @@ export interface InputMethodProperty {
* @since 10
*/
extra?: object;
}
export interface IStatusContentList {
contentId: string;
// relType: string;
contentType: string;
// contentRelId: string;
}
export interface batchLikeAndCollectParams {
// userType: number;
// userId: string;
contentList: IStatusContentList[]
}
export interface postBatchAttentionStatusParamsItem {
creatorId: string;
}
export interface postBatchAttentionStatusParams {
creatorIds: postBatchAttentionStatusParamsItem[]
}
export interface postInteractBrowsOperateParamsContent {
browseTime: string;
contentId: string;
contentType: number;
}
export interface postInteractBrowsOperateParams {
delStatus: number;
contentList: postInteractBrowsOperateParamsContent[]
}
export interface postBatchAttentionStatusResult {
creatorId: string;
status: string;
userId: string;
}
export interface batchLikeAndCollectResult {
collectStatus: number;
contentType: string;
likeStatus: string;
relType: string;
contentId: string;
contentRelId: string;
}
export interface postExecuteLikeParams {
status: string;
contentId: string;
contentType: string;
relType?: string;
userName?: string;
title?: string;
contentRelId?: string;
userHeaderUrl?: string;
channelId?: string;
}
export interface postExecuteCollectRecordParamsItem {
contentId: string;
contentType: string;
relType?: string;
contentRelId?: string;
}
export interface postExecuteCollectRecordParams {
status: string;
contentList: postExecuteCollectRecordParamsItem[]
}
interface contentListItem {
contentId: string;
contentType: number;
}
export interface contentListParams {
contentList: contentListItem[];
}
\ No newline at end of file
... ...
import { Logger } from 'wdKit';
import { ContentDetailDTO, PhotoListBean } from 'wdBean';
import { ContentDetailDTO, PhotoListBean, postInteractBrowsOperateParams, postBatchAttentionStatusParams } from 'wdBean';
import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
import display from '@ohos.display';
import font from '@ohos.font';
import { OperRowListView } from './view/OperRowListView';
import { MultiPictureDetailItemComponent } from './MultiPictureDetailItemComponent';
import { DateTimeUtils } from 'wdKit/Index';
import { HttpUrlUtils } from 'wdNetwork/Index';
const TAG = 'MultiPictureDetailPageComponent';
... ... @@ -21,6 +23,7 @@ export struct MultiPictureDetailPageComponent {
@Provide @Watch('onCurrentPageNumUpdated') currentPageNum: string = '01'
private swiperController: SwiperController = new SwiperController()
@State swiperIndex: number = 0;
@Provide followStatus: string = '0' // 关注状态
//watch监听页码回调
onCurrentPageNumUpdated(): void {
... ... @@ -43,6 +46,10 @@ export struct MultiPictureDetailPageComponent {
familySrc: $rawfile('font/BebasNeue_Regular.otf')
})
this.getContentDetailData()
if (HttpUrlUtils.getUserId()) {
this.getInteractBrowsOperate()
this.getBatchAttentionStatus()
}
}
aboutToDisappear() {
... ... @@ -74,7 +81,9 @@ export struct MultiPictureDetailPageComponent {
this.swiperIndex = index
})
}
OperRowListView()
OperRowListView({
contentDetailData: this.contentDetailData?.[0],
})
.alignRules({
bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
middle: { anchor: "__container__", align: HorizontalAlign.Center }
... ... @@ -98,4 +107,37 @@ export struct MultiPictureDetailPageComponent {
}
}
// 记录浏览历史
private getInteractBrowsOperate() {
try {
const params: postInteractBrowsOperateParams = {
delStatus: 0,
contentList: [{
browseTime: DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN),
contentId: this.contentDetailData?.[0].newsId + '',
contentType: this.contentDetailData?.[0].newsType || 0,
}]
}
MultiPictureDetailViewModel.getInteractBrowsOperate(params).then(res => {
console.log('记录浏览历史==', JSON.stringify(res.data))
})
} catch (exception) {
}
}
// 已登录->批量查作品是否被号主关注
private async getBatchAttentionStatus() {
try {
const params: postBatchAttentionStatusParams = {
creatorIds: [{ creatorId: this.contentDetailData?.[0]?.rmhInfo?.rmhId ?? '' }]
}
let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params)
this.followStatus = data[0]?.status;
Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`)
} catch (exception) {
}
}
}
\ No newline at end of file
... ...
import { ToastUtils, Logger } from 'wdKit';
import { InputMethodProperty } from 'wdBean';
import {
InputMethodProperty,
batchLikeAndCollectResult,
batchLikeAndCollectParams,
ContentDetailDTO,
postExecuteLikeParams,
contentListParams,
InteractDataDTO,
postExecuteCollectRecordParams
} from 'wdBean';
import router from '@ohos.router';
import inputMethod from '@ohos.inputMethod';
import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel';
import { HttpUrlUtils } from 'wdNetwork/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { PageRepository } from '../../repository/PageRepository';
export interface OperationItem {
icon: Resource;
icon_check?: Resource;
text: string | Resource;
num?: number; // 个数
}
... ... @@ -14,19 +28,23 @@ const TAG = 'OperRowListView';
@Preview
@Component
export struct OperRowListView {
private contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
private interactData: InteractDataDTO | undefined = undefined
@State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
@State operationList: OperationItem[] = [
{
icon: $r('app.media.ic_comment'),
text: "评论",
num: 500,
},
{
icon: $r('app.media.ic_like_uncheck'),
icon_check: $r('app.media.ic_like_check'),
text: "点赞",
num: 6622
},
{
icon: $r('app.media.ic_collect_uncheck'),
icon_check: $r('app.media.ic_collect_check'),
text: "收藏",
},
{
... ... @@ -36,6 +54,10 @@ export struct OperRowListView {
]
aboutToAppear() {
if (HttpUrlUtils.getUserId()) {
this.getInteractDataStatus()
}
this.queryContentInteractCount()
}
build() {
... ... @@ -100,55 +122,166 @@ export struct OperRowListView {
@Builder
buildOperationItem(item: OperationItem, index: number) {
Column() {
RelativeContainer() {
Row() {
Image(item.icon)
.width(24)
.height(24)
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
if (item.text === '点赞') {
RelativeContainer() {
Row() {
Image(this.newsStatusOfUser?.likeStatus == '1' ? item.icon_check : item.icon)
.width(24)
.height(24)
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick(() => {
this.toggleLikeStatus()
})
}
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id(`e_row1_${index}`)
if(this.interactData?.likeNum) {
Row() {
Image($r('app.media.corner_mark'))
.width(25)
.height(12)
.interpolation(ImageInterpolation.High)
}
.alignRules({
top: { anchor: `e_row1_${index}`, align: VerticalAlign.Top },
left: { anchor: `e_row1_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row2_${index}`)
Row() {
Text(`${this.interactData?.likeNum}`)
.fontSize(8)
.textAlign(TextAlign.Center)
.fontColor(Color.White)
.lineHeight(12)
}
.alignRules({
top: { anchor: `e_row2_${index}`, align: VerticalAlign.Top },
middle: { anchor: `e_row2_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row3_${index}`)
}
}
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id(`e_row1_${index}`)
if(item.num) {
.id(`e_icon_${index}`)
} else if (item.text === '收藏') {
RelativeContainer() {
Row() {
Image($r('app.media.corner_mark'))
.width(25)
.height(12)
Image(this.newsStatusOfUser?.collectStatus == 1 ? item.icon_check : item.icon)
.width(24)
.height(24)
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick(() => {
this.toggleCollectStatus()
})
}
.alignRules({
top: { anchor: `e_row1_${index}`, align: VerticalAlign.Top },
left: { anchor: `e_row1_${index}`, align: HorizontalAlign.Center }
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id(`e_row2_${index}`)
.id(`e_row1_${index}`)
if(this.interactData?.collectNum) {
Row() {
Image($r('app.media.corner_mark'))
.width(25)
.height(12)
.interpolation(ImageInterpolation.High)
}
.alignRules({
top: { anchor: `e_row1_${index}`, align: VerticalAlign.Top },
left: { anchor: `e_row1_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row2_${index}`)
Row() {
Text(`${this.interactData?.collectNum}`)
.fontSize(8)
.textAlign(TextAlign.Center)
.fontColor(Color.White)
.lineHeight(12)
}
.alignRules({
top: { anchor: `e_row2_${index}`, align: VerticalAlign.Top },
middle: { anchor: `e_row2_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row3_${index}`)
}
}
.id(`e_icon_${index}`)
} else if (item.text === '评论') {
RelativeContainer() {
Row() {
Image(item.icon)
.width(24)
.height(24)
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick((event: ClickEvent) => {
ToastUtils.showToast('评论为公共方法,待开发', 1000);
})
}
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id(`e_row1_${index}`)
if(this.interactData?.commentNum) {
Row() {
Image($r('app.media.corner_mark'))
.width(25)
.height(12)
.interpolation(ImageInterpolation.High)
}
.alignRules({
top: { anchor: `e_row1_${index}`, align: VerticalAlign.Top },
left: { anchor: `e_row1_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row2_${index}`)
Row() {
Text(`${this.interactData?.commentNum}`)
.fontSize(8)
.textAlign(TextAlign.Center)
.fontColor(Color.White)
.lineHeight(12)
}
.alignRules({
top: { anchor: `e_row2_${index}`, align: VerticalAlign.Top },
middle: { anchor: `e_row2_${index}`, align: HorizontalAlign.Center }
})
.id(`e_row3_${index}`)
}
}
.id(`e_icon_${index}`)
} else {
RelativeContainer() {
Row() {
Text('99+')
.fontSize(8)
.textAlign(TextAlign.Center)
.fontColor(Color.White)
.lineHeight(12)
Image(item.icon)
.width(24)
.height(24)
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick((event: ClickEvent) => {
ToastUtils.showToast('分享为公共方法,待开发', 1000);
})
}
.alignRules({
top: { anchor: `e_row2_${index}`, align: VerticalAlign.Top },
middle: { anchor: `e_row2_${index}`, align: HorizontalAlign.Center }
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id(`e_row3_${index}`)
.id(`e_row1_${index}`)
}
.id(`e_icon_${index}`)
}
.id(`e_icon_${index}`)
}
.margin(5)
.alignItems(HorizontalAlign.Center)
.hoverEffect(HoverEffect.Scale)
.onClick(() => {
Logger.info(TAG, `buildOperationItem onClick event index: ${index}`);
ToastUtils.showToast('体验版,本功能暂未开发', 1000);
})
}
/**
... ... @@ -180,4 +313,94 @@ export struct OperRowListView {
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
}
}
// 已登录->查询用户对作品点赞、收藏状态
private async getInteractDataStatus() {
try {
const params: batchLikeAndCollectParams = {
contentList: [
{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
}
]
}
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) {
}
}
/**
* 点赞、取消点赞
*/
toggleLikeStatus() {
// 未登录,跳转登录
if (!HttpUrlUtils.getUserId()) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params: postExecuteLikeParams = {
status: this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1',
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
}
PageRepository.postExecuteLike(params).then(res => {
console.log('toggleLikeStatus==',)
if (this.newsStatusOfUser) {
this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1'
this.queryContentInteractCount()
}
})
}
/**
* 收藏、取消收藏
*/
toggleCollectStatus() {
// 未登录,跳转登录
if (!HttpUrlUtils.getUserId()) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params: postExecuteCollectRecordParams = {
status: this.newsStatusOfUser?.collectStatus === 1 ? '0' : '1',
contentList: [{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
}],
}
PageRepository.postExecuteCollectRecord(params).then(res => {
console.log('toggleLikeStatus==',)
if (this.newsStatusOfUser) {
this.newsStatusOfUser.collectStatus = this.newsStatusOfUser?.collectStatus === 1 ? 0 : 1
this.queryContentInteractCount()
}
})
}
/**
* 查询点赞、收藏数量
*/
queryContentInteractCount() {
const params: contentListParams = {
contentList: [{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType,
}]
}
PageRepository.getContentInteract(params).then(res => {
if (res.data && this.interactData) {
this.interactData.likeNum = res.data[0]?.likeNum
this.interactData.collectNum = res.data[0]?.collectNum
this.interactData.commentNum = res.data[0]?.commentNum
}
console.log('获取互动点赞等数据===', JSON.stringify(res))
})
}
}
\ No newline at end of file
... ...
... ... @@ -5,13 +5,18 @@ import {
CompInfoBean,
ContentDetailDTO,
InteractDataDTO,
InteractDataStatusBean,
batchLikeAndCollectResult,
MorningEveningPaperDTO,
NavigationBodyDTO,
NewspaperListBean,
NewspaperTimeInfoBean,
PageDTO,
PageInfoBean
PageInfoBean,
postBatchAttentionStatusParams,
postBatchAttentionStatusResult,
postExecuteLikeParams,
postExecuteCollectRecordParams,
contentListParams
} from 'wdBean';
const TAG = 'HttpRequest';
... ... @@ -174,9 +179,41 @@ export class PageRepository {
static fetchInteractDataStatus(param: object) {
let url = PageRepository.getInteractDataStatusUrl()
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.post<ResponseDTO<InteractDataStatusBean[]>>(url, param, headers)
return WDHttp.post<ResponseDTO<batchLikeAndCollectResult[]>>(url, param, headers)
};
/**
* 用户点赞、取消点赞
* @param params
* @returns
*/
static postExecuteLike(params: postExecuteLikeParams): Promise<ResponseDTO> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_EXECUTELIKE
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.post0(url, params, headers)
}
/**
* 用户收藏、取消收藏
* @param params
* @returns
*/
static postExecuteCollectRecord(params: postExecuteCollectRecordParams): Promise<ResponseDTO> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_EXECUTECOLLECTRECORD
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.post0(url, params, headers)
}
/**
*
* @returns
*/
static getContentInteract(params: contentListParams): Promise<ResponseDTO<InteractDataDTO[]>> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.post0(url, params, headers)
}
// 浏览历史新增、删除接口
static fetchInteractBrowsOperate(param: object) {
let url = PageRepository.getInteractBrowsOperateUrl()
... ... @@ -184,6 +221,16 @@ export class PageRepository {
return WDHttp.post<ResponseDTO<null>>(url, param, headers)
};
/**
* 批量查号主是否为用户关注
* @returns
*/
static fetchBatchAttentionStatus(params: postBatchAttentionStatusParams): Promise<ResponseDTO<postBatchAttentionStatusResult[]>> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.FOLLOW_LIST_STATUS_DATA_PATH
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.post0(url, params, headers)
}
static fetchNewspaperInfo(date: string) {
let url = PageRepository.getNewspaperInfoUrl(date)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
... ...
import { Logger } from 'wdKit';
import { ResponseDTO } from 'wdNetwork';
import { ContentDetailDTO } from 'wdBean';
import { ContentDetailDTO,
batchLikeAndCollectParams,
batchLikeAndCollectResult,
postBatchAttentionStatusParams,
postBatchAttentionStatusResult,
postInteractBrowsOperateParams
} from 'wdBean';
import { PageRepository } from '../repository/PageRepository';
const TAG = 'MultiPictureDetailViewModel';
export class MultiPictureDetailViewModel {
/*fetchDetailData
fetchInteractData
fetchInteractDataStatus
fetchInteractBrowsOperate*/
static async getDetailData(relId: string, contentId: string, relType: string): Promise<ContentDetailDTO[]> {
return new Promise<ContentDetailDTO[]>((success, error) => {
Logger.info(TAG, `fetchDetailData start`);
... ... @@ -34,4 +35,75 @@ export class MultiPictureDetailViewModel {
})
})
}
/**
* 批量查询作品查询点赞、收藏状态
* @returns
*/
static async getInteractDataStatus(params:batchLikeAndCollectParams): Promise<batchLikeAndCollectResult[]> {
return new Promise<batchLikeAndCollectResult[]>((success, error) => {
Logger.info(TAG, `fetchInteractDataStatus start`);
PageRepository.fetchInteractDataStatus(params).then((resDTO: ResponseDTO<batchLikeAndCollectResult[]>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'fetchInteractDataStatus is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `fetchInteractDataStatus then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.info(TAG, "fetchInteractDataStatus then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
}).catch((err: Error) => {
Logger.error(TAG, `fetchInteractDataStatus catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
// 已登录->批量查作品是否被号主关注
static async getBatchAttentionStatus(params: postBatchAttentionStatusParams): Promise<postBatchAttentionStatusResult[]> {
return new Promise<postBatchAttentionStatusResult[]>((success, error) => {
Logger.info(TAG, `fetchBatchAttentionStatus start`);
PageRepository.fetchBatchAttentionStatus(params).then((resDTO: ResponseDTO<postBatchAttentionStatusResult[]>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'fetchBatchAttentionStatus is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `fetchBatchAttentionStatus then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.info(TAG, "fetchBatchAttentionStatus then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
}).catch((err: Error) => {
Logger.error(TAG, `fetchBatchAttentionStatus catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
// 记录浏览历史
static async getInteractBrowsOperate(params: postInteractBrowsOperateParams): Promise<ResponseDTO<null>> {
return new Promise<ResponseDTO<null>>((success, error) => {
Logger.info(TAG, `fetchInteractBrowsOperate start`);
PageRepository.fetchInteractBrowsOperate(params).then((resDTO: ResponseDTO<null>) => {
if (resDTO.code != 0) {
Logger.error(TAG, `fetchInteractBrowsOperate then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.info(TAG, "fetchInteractBrowsOperate then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO);
}).catch((err: Error) => {
Logger.error(TAG, `fetchInteractBrowsOperate catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
}
... ...