yanlu

desc:首页关注接口

import { PeopleShipAttentionContentListTopComponent } from './PeopleShipAttentionContentListTopComponent'
import { FollowListDetailItem } from '../../viewmodel/FollowListDetailItem';
import { ContentDTO } from 'wdBean'
import { CardParser } from '../CardParser'
@Preview
@Component
export struct PeopleShipAttentionContentListComponent {
@Prop followList: FollowListDetailItem[]
@Prop attentionList: ContentDTO[]
build() {
List(){
// 头部关注列表
ListItem(){
PeopleShipAttentionContentListTopComponent({
followList: this.followList
})
}
ForEach(this.attentionList, (item: ContentDTO) => {
ListItem() {
CardParser({ contentDTO: item })
}.width("100%")
.backgroundColor(Color.Transparent)
}, (item: ContentDTO, index: number) => item.objectId + index.toString())
}
.scrollBar(BarState.Off)
.width('100%')
.height('100%')
}
}
import { PeopleShipHomePageHeadComponent } from '../peopleShipHomePage/PeopleShipHomePageHeadComponent'
import { FollowListDetailItem } from '../../viewmodel/FollowListDetailItem';
@Component
export struct PeopleShipAttentionContentListHeadComponent {
@State index: number = 0
@ObjectLink item: FollowListDetailItem
build() {
Column(){
// 头像
PeopleShipHomePageHeadComponent({
diameter: 48,
iconDiameter: 16,
headPhotoUrl: this.index == 0 ? $r('app.media.attention_mine') :
((this.item.attentionHeadPhotoUrl && this.item.attentionHeadPhotoUrl.length > 0) ?
this.item.attentionHeadPhotoUrl : $r('app.media.WDAccountOwnerHedaerDefaultIcon')),
authIcon: this.index == 0 ? '' : this.item.authIcon
}).margin({
bottom: '8vp'
})
Text(this.index == 0 ? '我的关注' : this.item.attentionUserName)
.fontColor($r('app.color.color_666666'))
.fontSize($r('app.float.vp_13'))
.fontWeight(400)
.height('18vp')
.lineHeight('18vp')
.maxLines(1)
.textOverflow({overflow: TextOverflow.Ellipsis})
.padding({
left: '2vp',
right: '2vp'
})
}
.alignItems(HorizontalAlign.Center)
.width('78vp')
.margin({
left: this.index == 0 ? '8vp' : '4vp',
top: '14vp',
bottom: '14vp'
})
}
}
... ...
import { FollowListDetailItem } from '../../viewmodel/FollowListDetailItem';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
import { ProcessUtils } from 'wdRouter';
import { PeopleShipHomePageHeadComponent } from '../peopleShipHomePage/PeopleShipHomePageHeadComponent'
import { PeopleShipAttentionContentListHeadComponent } from './PeopleShipAttentionContentListHeadComponent'
@Component
export struct PeopleShipAttentionContentListTopComponent {
... ... @@ -41,45 +40,3 @@ export struct PeopleShipAttentionContentListTopComponent {
}
}
}
@Component
struct PeopleShipAttentionContentListHeadComponent {
@State index: number = 0
@ObjectLink item: FollowListDetailItem
build() {
Column(){
// 头像
PeopleShipHomePageHeadComponent({
diameter: 48,
iconDiameter: 16,
headPhotoUrl: this.index == 0 ? $r('app.media.attention_mine') :
((this.item.attentionHeadPhotoUrl && this.item.attentionHeadPhotoUrl.length > 0) ?
this.item.attentionHeadPhotoUrl : $r('app.media.WDAccountOwnerHedaerDefaultIcon')),
authIcon: this.index == 0 ? '' : this.item.authIcon
}).margin({
bottom: '8vp'
})
Text(this.index == 0 ? '我的关注' : this.item.attentionUserName)
.fontColor($r('app.color.color_666666'))
.fontSize($r('app.float.vp_13'))
.fontWeight(400)
.height('18vp')
.lineHeight('18vp')
.maxLines(1)
.textOverflow({overflow: TextOverflow.Ellipsis})
.padding({
left: '2vp',
right: '2vp'
})
}
.alignItems(HorizontalAlign.Center)
.width('78vp')
.margin({
left: this.index == 0 ? '8vp' : '4vp',
top: '14vp',
bottom: '14vp'
})
}
}
\ No newline at end of file
... ...
... ... @@ -2,7 +2,14 @@ import { PeopleShipRecommendComponent } from './PeopleShipRecommendComponent';
import { PeopleShipMainViewModel } from '../../viewmodel/PeopleShipMainViewModel';
import { HttpUtils } from 'wdNetwork/Index';
import { Logger, DateTimeUtils, EmitterEventId, EmitterUtils } from 'wdKit';
import { RmhRecommendDTO, ContentDTO, AttentionBatchDTO, CreatorDTO } from 'wdBean';
import {
RmhRecommendDTO,
ContentDTO,
AttentionBatchDTO,
CreatorDTO,
contentListParams,
InteractDataDTO
} from 'wdBean';
import { ViewType } from 'wdConstant/src/main/ets/enum/ViewType';
import { channelSkeleton } from '../skeleton/channelSkeleton'
import { EmptyComponent } from '../view/EmptyComponent';
... ... @@ -56,6 +63,13 @@ export struct PeopleShipMainComponent {
this.LoadingLayout()
} else if (this.viewType == ViewType.ERROR) {
ErrorComponent()
.onTouch((event: TouchEvent | undefined) => {
if (event) {
if (this.viewType === ViewType.ERROR) {
this.getData()
}
}
})
} else if (this.viewType == ViewType.EMPTY) {
EmptyComponent()
} else {
... ... @@ -155,11 +169,6 @@ export struct PeopleShipMainComponent {
.scrollBar(BarState.Off)
.width('100%')
.height('100%')
// PeopleShipAttentionContentListComponent({
// followList: this.followList,
// attentionList: this.attentionList
// })
}
aboutToAppear() {
... ... @@ -259,14 +268,6 @@ export struct PeopleShipMainComponent {
// 获取列表数据
let listData = await PeopleShipMainViewModel.getAttentionContentListInfo(this.currentPage, 20, this.loadTime)
Logger.debug('PeopleShipMainComponent', '获取页面信息' + `${JSON.stringify(listData)}`)
if (resolve ) {
if (this.currentPage == 1) {
resolve('已更新至最新')
}else {
resolve('')
}
}
if (listData && listData.list && listData.list.length > 0) {
if (listData.list.length === 20) {
this.hasMore = true;
... ... @@ -276,14 +277,71 @@ export struct PeopleShipMainComponent {
if (this.currentPage == 1) {
this.attentionList = []
}
this.attentionList.push(...listData.list)
//批量查询各类型内容动态数据接口
this.checkContentInteractData(listData.list, resolve)
} else {
this.resolveEnd(true, resolve)
}
this.viewType = ViewType.LOADED
this.isLoading = false
} catch (exception) {
this.resolveEnd(false, resolve)
}
}
// 批量查询各类型内容动态数据接口
private async checkContentInteractData(list: ContentDTO[], resolve?: (value: string | PromiseLike<string>) => void) {
// 批量查询内容当前用户点赞、收藏状态
try {
// 获取列表数据
const params: contentListParams = {
contentList: []
}
list.forEach((item: ContentDTO) => {
params.contentList.push({
contentId: item.objectId,
contentType: Number(item.objectType ?? '1')
})
})
let listData = await PeopleShipMainViewModel.getContentInteractInfo(params)
Logger.debug('PeopleShipMainComponent', '获取页面信息' + `${JSON.stringify(listData)}`)
this.resolveEnd(true, resolve)
list.forEach((element: ContentDTO) => {
// 获取 interactData 数据
if (listData && listData.length > 0) {
const objc = listData.find((interactModel: InteractDataDTO) => {
return element.objectId == interactModel.contentId
})
if (objc) {
element.interactData = objc
}
}
// 设置人民号都不可关注
if (element.rmhInfo) {
element.rmhInfo.cnIsAttention = 0
}
this.attentionList.push(element)
})
} catch (exception) {
this.resolveEnd(false, resolve)
}
}
private resolveEnd(isTop: boolean, resolve?: (value: string | PromiseLike<string>) => void) {
if (resolve) {
if (this.currentPage == 1 && isTop) {
resolve('已更新至最新')
}else {
resolve('')
}
}
if (this.currentPage == 1 && !isTop) {
this.viewType = ViewType.ERROR
this.isLoading = false
} else {
this.viewType = ViewType.LOADED
}
this.isLoading = false
}
// 说是首页必须要调用
... ...
import { Logger } from 'wdKit';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import HashMap from '@ohos.util.HashMap';
import {
RmhRecommendDTO,
PeopleShipContentListDTO,
AttentionBatchDTO
AttentionBatchDTO,
contentListParams,
InteractDataDTO
} from 'wdBean';
import { PageRepository } from '../repository/PageRepository'
const TAG = 'PeopleShipMainViewModel'
... ... @@ -103,5 +105,24 @@ export class PeopleShipMainViewModel {
})
}
static async getContentInteractInfo(params: contentListParams): Promise<InteractDataDTO[]> {
return new Promise<InteractDataDTO[]>((success, error) => {
Logger.debug(TAG, `getContentInteractInfo pageInfo start`);
PageRepository.getContentInteract(params)
.then((resDTO) => {
if (!resDTO.data || resDTO.code != 0) {
error(resDTO.message)
return
}
Logger.debug(TAG, "getContentInteractInfo then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
})
.catch((err: Error) => {
Logger.error(TAG, `getContentInteractInfo catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
}
\ No newline at end of file
... ...