Showing
6 changed files
with
441 additions
and
386 deletions
| 1 | +import { DateTimeUtils, LazyDataSource, UserDataLocal } from 'wdKit'; | ||
| 2 | +import MinePageDatasModel from '../../../model/MinePageDatasModel'; | ||
| 3 | +import { CommentListItem } from '../../../viewmodel/CommentListItem'; | ||
| 4 | +import { FollowListDetailRequestItem } from '../../../viewmodel/FollowListDetailRequestItem'; | ||
| 5 | +import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; | ||
| 6 | +import { EmptyComponent } from '../../view/EmptyComponent'; | ||
| 7 | +import { ChildCommentComponent } from './ChildCommentComponent'; | ||
| 8 | +import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDetailItem'; | ||
| 9 | +import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem'; | ||
| 10 | + | ||
| 11 | +const TAG = "HomePageBottomCommentComponent" | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 我的主页 评论tab | ||
| 15 | + */ | ||
| 16 | +@Component | ||
| 17 | +export struct HomePageBottomCommentComponent { | ||
| 18 | + @State data_comment: LazyDataSource<CommentListItem> = new LazyDataSource(); | ||
| 19 | + @State isLoading: boolean = false | ||
| 20 | + @State hasMore: boolean = true | ||
| 21 | + curPageNum: number = 1; | ||
| 22 | + @State count: number = 0; | ||
| 23 | + @Link commentNum: number | ||
| 24 | + @State isGetRequest: boolean = false | ||
| 25 | + | ||
| 26 | + aboutToAppear() { | ||
| 27 | + this.getNewPageData() | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + build() { | ||
| 31 | + Column() { | ||
| 32 | + if (this.isGetRequest == true) { | ||
| 33 | + Divider().width('100%') | ||
| 34 | + .height('2lpx') | ||
| 35 | + .strokeWidth('1lpx') | ||
| 36 | + .backgroundColor($r('app.color.color_EDEDED')) | ||
| 37 | + } | ||
| 38 | + if (this.count === 0) { | ||
| 39 | + if (this.isGetRequest == true) { | ||
| 40 | + EmptyComponent({ emptyType: 11 }) | ||
| 41 | + .layoutWeight(1) | ||
| 42 | + .width('100%') | ||
| 43 | + .offset({ y: "-200lpx" }) | ||
| 44 | + } | ||
| 45 | + } else { | ||
| 46 | + List({ space: 3 }) { | ||
| 47 | + LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => { | ||
| 48 | + ListItem() { | ||
| 49 | + ChildCommentComponent({ | ||
| 50 | + data: item, | ||
| 51 | + levelHead: UserDataLocal.getUserLevelHeaderUrl(), | ||
| 52 | + isLastItem: index === this.data_comment.totalCount() - 1 | ||
| 53 | + }) | ||
| 54 | + } | ||
| 55 | + }, (item: CommentListItem, index: number) => index.toString()) | ||
| 56 | + | ||
| 57 | + //没有更多数据 显示提示 | ||
| 58 | + if (!this.hasMore) { | ||
| 59 | + ListItem() { | ||
| 60 | + ListHasNoMoreDataUI() | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + .cachedCount(15) | ||
| 65 | + .layoutWeight(1) | ||
| 66 | + .scrollBar(BarState.Off) | ||
| 67 | + .edgeEffect(EdgeEffect.None) | ||
| 68 | + .nestedScroll({ | ||
| 69 | + scrollForward: NestedScrollMode.PARENT_FIRST, | ||
| 70 | + scrollBackward: NestedScrollMode.SELF_FIRST | ||
| 71 | + }) | ||
| 72 | + .onReachEnd(() => { | ||
| 73 | + console.log(TAG, "触底了"); | ||
| 74 | + if (!this.isLoading) { | ||
| 75 | + this.isLoading = true | ||
| 76 | + //加载分页数据 | ||
| 77 | + this.getNewPageData() | ||
| 78 | + } | ||
| 79 | + }) | ||
| 80 | + } | ||
| 81 | + }.layoutWeight(1) | ||
| 82 | + .justifyContent(FlexAlign.Start) | ||
| 83 | + .width('100%') | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + getNewPageData() { | ||
| 87 | + this.isLoading = true | ||
| 88 | + if (this.hasMore) { | ||
| 89 | + let time = encodeURI(DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 90 | + let object = new FollowListDetailRequestItem(-1, 20, this.curPageNum) | ||
| 91 | + | ||
| 92 | + MinePageDatasModel.getMineCommentListData(time, object, getContext(this)).then((value) => { | ||
| 93 | + if (!this.data_comment || value.list.length == 0) { | ||
| 94 | + this.hasMore = false | ||
| 95 | + this.isLoading = false | ||
| 96 | + this.isGetRequest = true | ||
| 97 | + } else { | ||
| 98 | + this.getCommentListStatus(value) | ||
| 99 | + } | ||
| 100 | + }).catch((err: Error) => { | ||
| 101 | + console.log(TAG, "请求失败") | ||
| 102 | + this.isLoading = false | ||
| 103 | + this.isGetRequest = true | ||
| 104 | + }) | ||
| 105 | + } else { | ||
| 106 | + this.isLoading = false | ||
| 107 | + this.isGetRequest = true | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + getCommentListStatus(value: MineCommentListDetailItem) { | ||
| 112 | + | ||
| 113 | + let status = new OtherUserCommentLikeStatusRequestItem() | ||
| 114 | + let data: CommentListItem[] = [] | ||
| 115 | + value.list.forEach((item) => { | ||
| 116 | + if (item.checkStatus === 2) { | ||
| 117 | + status.commentIdList.push(item.id) | ||
| 118 | + } | ||
| 119 | + let commentContent = item.commentContent | ||
| 120 | + if (item.sensitiveShow === 0 && item.sensitiveExist === 1) { | ||
| 121 | + commentContent = item.commentContentSensitive | ||
| 122 | + } | ||
| 123 | + let parentCommentContent = "" | ||
| 124 | + if (item.parentCommentVo != null) { | ||
| 125 | + parentCommentContent = item.parentCommentVo.commentContent | ||
| 126 | + } | ||
| 127 | + let parentCommentUserName = "" | ||
| 128 | + if (item.parentCommentVo != null) { | ||
| 129 | + parentCommentUserName = item.parentCommentVo.fromUserName | ||
| 130 | + } | ||
| 131 | + data.push(new CommentListItem(item.fromUserHeader, item.fromUserName, item.targetTitle, item.createTime, | ||
| 132 | + commentContent, item.likeNum, 0, item.id, item.targetId, item.targetType, item.targetRelId, | ||
| 133 | + item.targetRelObjectId, item.targetRelType, item.targetStatus, item.checkStatus, parentCommentContent, | ||
| 134 | + parentCommentUserName)) | ||
| 135 | + }) | ||
| 136 | + | ||
| 137 | + if (status.commentIdList.length === 0) { | ||
| 138 | + data.forEach((item) => { | ||
| 139 | + let publishTime = | ||
| 140 | + DateTimeUtils.getCommentTime(DateTimeUtils.parseDate(item.createTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 141 | + this.data_comment.push(new CommentListItem(item.fromUserHeader, item.fromUserName, item.targetTitle, | ||
| 142 | + publishTime, item.commentContent, item.likeNum, item.like_status, item.id, item.targetId, item.targetType, | ||
| 143 | + item.targetRelId, item.targetRelObjectId, item.targetRelType, item.targetStatus, item.checkStatus, | ||
| 144 | + item.parentCommentContent, item.parentCommentUserName)) | ||
| 145 | + }) | ||
| 146 | + | ||
| 147 | + this.data_comment.notifyDataReload() | ||
| 148 | + | ||
| 149 | + this.count = this.data_comment.totalCount() | ||
| 150 | + this.commentNum = value.totalCount | ||
| 151 | + if (this.data_comment.totalCount() < value.totalCount) { | ||
| 152 | + this.curPageNum++ | ||
| 153 | + } else { | ||
| 154 | + this.hasMore = false | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + this.isLoading = false | ||
| 158 | + this.isGetRequest = true | ||
| 159 | + return | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + MinePageDatasModel.getOtherUserCommentLikeStatusData(status, getContext(this)).then((newValue) => { | ||
| 163 | + newValue.forEach((item) => { | ||
| 164 | + data.forEach((list) => { | ||
| 165 | + if (item.commentId == list.id) { | ||
| 166 | + list.like_status = item.status | ||
| 167 | + } | ||
| 168 | + }) | ||
| 169 | + }) | ||
| 170 | + | ||
| 171 | + data.forEach((item) => { | ||
| 172 | + let publishTime = | ||
| 173 | + DateTimeUtils.getCommentTime(DateTimeUtils.parseDate(item.createTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 174 | + this.data_comment.push(new CommentListItem(item.fromUserHeader, item.fromUserName, item.targetTitle, | ||
| 175 | + publishTime, item.commentContent, item.likeNum, item.like_status, item.id, item.targetId, item.targetType, | ||
| 176 | + item.targetRelId, item.targetRelObjectId, item.targetRelType, item.targetStatus, item.checkStatus, | ||
| 177 | + item.parentCommentContent, item.parentCommentUserName)) | ||
| 178 | + }) | ||
| 179 | + | ||
| 180 | + this.data_comment.notifyDataReload() | ||
| 181 | + | ||
| 182 | + this.count = this.data_comment.totalCount() | ||
| 183 | + this.commentNum = value.totalCount | ||
| 184 | + if (this.data_comment.totalCount() < value.totalCount) { | ||
| 185 | + this.curPageNum++ | ||
| 186 | + } else { | ||
| 187 | + this.hasMore = false | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + this.isLoading = false | ||
| 191 | + this.isGetRequest = true | ||
| 192 | + }).catch((err: Error) => { | ||
| 193 | + console.log(TAG, "请求失败") | ||
| 194 | + this.isLoading = false | ||
| 195 | + this.isGetRequest = true | ||
| 196 | + }) | ||
| 197 | + } | ||
| 198 | +} |
| 1 | -import { DateTimeUtils, LazyDataSource, SPHelper,UserDataLocal } from 'wdKit'; | ||
| 2 | -import { WDRouterPage, WDRouterRule } from 'wdRouter'; | ||
| 3 | -import MinePageDatasModel from '../../../model/MinePageDatasModel'; | ||
| 4 | -import { CommentListItem } from '../../../viewmodel/CommentListItem'; | ||
| 5 | -import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem'; | ||
| 6 | -import { FollowListDetailRequestItem } from '../../../viewmodel/FollowListDetailRequestItem'; | ||
| 7 | -import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; | ||
| 8 | -import { FollowChildComponent } from '../follow/FollowChildComponent'; | ||
| 9 | -import dataPreferences from '@ohos.data.preferences'; | ||
| 10 | -import { EmptyComponent } from '../../view/EmptyComponent'; | ||
| 11 | -import { ChildCommentComponent } from './ChildCommentComponent'; | ||
| 12 | -import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDetailItem'; | ||
| 13 | -import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem'; | ||
| 14 | - | ||
| 15 | -const TAG = "HomePageBottomComponent" | ||
| 16 | -@Component | ||
| 17 | -export struct HomePageBottomComponent{ | ||
| 18 | - @State style:number = 0; //0 评论 ,1 关注 | ||
| 19 | - @State data_follow: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); | ||
| 20 | - @State data_comment: LazyDataSource<CommentListItem> = new LazyDataSource(); | ||
| 21 | - @State isLoading:boolean = false | ||
| 22 | - @State hasMore:boolean = true | ||
| 23 | - curPageNum:number = 1; | ||
| 24 | - @State count:number = 0; | ||
| 25 | - @State isMineAccount:boolean = true; | ||
| 26 | - @State userId:string = ""; | ||
| 27 | - @Link commentNum:number | ||
| 28 | - preferences: dataPreferences.Preferences | null = null; | ||
| 29 | - @State isGetRequest:boolean = false | ||
| 30 | - observer = (key: string) => { | ||
| 31 | - if (key == UserDataLocal.USER_FOLLOW_OPERATION) { | ||
| 32 | - let value = SPHelper.default.getSync(UserDataLocal.USER_FOLLOW_OPERATION,"") as string | ||
| 33 | - let arr = value.split(',') | ||
| 34 | - if(arr[1] == "0"){ | ||
| 35 | - this.data_follow.getDataArray().forEach((element,index) => { | ||
| 36 | - if (element.creatorId === arr[0]) { | ||
| 37 | - this.data_follow.deleteItem(index) | ||
| 38 | - this.count = this.data_follow.size() | ||
| 39 | - } | ||
| 40 | - }); | ||
| 41 | - }else{ | ||
| 42 | - if(!this.isLoading){ | ||
| 43 | - this.isLoading = true | ||
| 44 | - this.hasMore = true | ||
| 45 | - this.curPageNum = 1 | ||
| 46 | - this.data_follow.clear() | ||
| 47 | - this.data_follow.notifyDataReload() | ||
| 48 | - this.getMyFollowListDetail() | ||
| 49 | - } | ||
| 50 | - } | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - aboutToAppear(){ | ||
| 55 | - this.getNewPageData() | ||
| 56 | - this.addFollowStatusObserver() | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - async addFollowStatusObserver() { | ||
| 60 | - this.preferences = await SPHelper.default.getPreferences(); | ||
| 61 | - this.preferences.on('change', this.observer); | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - aboutToDisappear(): void { | ||
| 65 | - if(this.preferences){ | ||
| 66 | - this.preferences.off('change', this.observer); | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - build(){ | ||
| 71 | - Column(){ | ||
| 72 | - if(this.isGetRequest == true){ | ||
| 73 | - Divider().width('100%') | ||
| 74 | - .height('2lpx') | ||
| 75 | - .strokeWidth('1lpx') | ||
| 76 | - .backgroundColor($r('app.color.color_EDEDED')) | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - if(this.count === 0 ){ | ||
| 80 | - if(this.style === 1){ | ||
| 81 | - Column(){ | ||
| 82 | - Row(){ | ||
| 83 | - Text("关注更多人民号") | ||
| 84 | - .fontWeight('400lpx') | ||
| 85 | - .fontColor($r('app.color.color_222222')) | ||
| 86 | - .lineHeight('38lpx') | ||
| 87 | - .fontSize('27lpx') | ||
| 88 | - .textAlign(TextAlign.Center) | ||
| 89 | - .margin({right:'4lpx'}) | ||
| 90 | - Image($r('app.media.arrow_icon_right')) | ||
| 91 | - .objectFit(ImageFit.Auto) | ||
| 92 | - .width('27lpx') | ||
| 93 | - .height('27lpx') | ||
| 94 | - }.height('69lpx') | ||
| 95 | - .width('659lpx') | ||
| 96 | - .alignItems(VerticalAlign.Center) | ||
| 97 | - .justifyContent(FlexAlign.Center) | ||
| 98 | - .backgroundColor($r('app.color.color_F5F5F5')) | ||
| 99 | - .margin({top:'31lpx',bottom:'4lpx'}) | ||
| 100 | - .onClick(()=>{ | ||
| 101 | - let params = {'index': "1"} as Record<string, string> | ||
| 102 | - WDRouterRule.jumpWithPage(WDRouterPage.followListPage,params) | ||
| 103 | - }) | ||
| 104 | - if(this.isGetRequest == true){ | ||
| 105 | - EmptyComponent({emptyType:14}) | ||
| 106 | - .layoutWeight(1) | ||
| 107 | - .width('100%') | ||
| 108 | - .offset({y:"-200lpx"}) | ||
| 109 | - } | ||
| 110 | - }.layoutWeight(1) | ||
| 111 | - .justifyContent(FlexAlign.Start) | ||
| 112 | - }else{ | ||
| 113 | - if(this.isGetRequest == true){ | ||
| 114 | - EmptyComponent({emptyType:11}) | ||
| 115 | - .layoutWeight(1) | ||
| 116 | - .width('100%') | ||
| 117 | - .offset({y:"-200lpx"}) | ||
| 118 | - } | ||
| 119 | - } | ||
| 120 | - }else{ | ||
| 121 | - if(this.style === 1){ | ||
| 122 | - List({ space: 3 }) { | ||
| 123 | - | ||
| 124 | - ListItem() { | ||
| 125 | - Row(){ | ||
| 126 | - Text("关注更多人民号") | ||
| 127 | - .fontWeight('400lpx') | ||
| 128 | - .fontColor($r('app.color.color_222222')) | ||
| 129 | - .lineHeight('38lpx') | ||
| 130 | - .fontSize('27lpx') | ||
| 131 | - .textAlign(TextAlign.Center) | ||
| 132 | - .margin({right:'4lpx'}) | ||
| 133 | - Image($r('app.media.arrow_icon_right')) | ||
| 134 | - .objectFit(ImageFit.Auto) | ||
| 135 | - .width('27lpx') | ||
| 136 | - .height('27lpx') | ||
| 137 | - }.height('69lpx') | ||
| 138 | - .width('659lpx') | ||
| 139 | - .alignItems(VerticalAlign.Center) | ||
| 140 | - .justifyContent(FlexAlign.Center) | ||
| 141 | - .backgroundColor($r('app.color.color_F5F5F5')) | ||
| 142 | - .margin({top:'31lpx',bottom:'4lpx'}) | ||
| 143 | - }.onClick(()=>{ | ||
| 144 | - let params = {'index': "1"} as Record<string, string> | ||
| 145 | - WDRouterRule.jumpWithPage(WDRouterPage.followListPage,params) | ||
| 146 | - }) | ||
| 147 | - | ||
| 148 | - LazyForEach(this.data_follow, (item: FollowListDetailItem, index: number = 0) => { | ||
| 149 | - ListItem() { | ||
| 150 | - FollowChildComponent({data: item,type:2}) | ||
| 151 | - } | ||
| 152 | - .onClick(() => { | ||
| 153 | - }) | ||
| 154 | - }, (item: FollowListDetailItem, index: number) => index.toString()) | ||
| 155 | - | ||
| 156 | - //没有更多数据 显示提示 | ||
| 157 | - if(!this.hasMore){ | ||
| 158 | - ListItem(){ | ||
| 159 | - ListHasNoMoreDataUI() | ||
| 160 | - } | ||
| 161 | - } | ||
| 162 | - }.cachedCount(15) | ||
| 163 | - .padding({left:'31lpx',right:'31lpx'}) | ||
| 164 | - .layoutWeight(1) | ||
| 165 | - .scrollBar(BarState.Off) | ||
| 166 | - .edgeEffect(EdgeEffect.None) | ||
| 167 | - .nestedScroll({ | ||
| 168 | - scrollForward: NestedScrollMode.PARENT_FIRST, | ||
| 169 | - scrollBackward: NestedScrollMode.SELF_FIRST | ||
| 170 | - }) | ||
| 171 | - .onReachEnd(()=>{ | ||
| 172 | - console.log(TAG,"触底了"); | ||
| 173 | - if(!this.isLoading){ | ||
| 174 | - this.isLoading = true | ||
| 175 | - //加载分页数据 | ||
| 176 | - this.getNewPageData() | ||
| 177 | - } | ||
| 178 | - }) | ||
| 179 | - }else if(this.style === 0){ | ||
| 180 | - List({ space: 3 }) { | ||
| 181 | - LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => { | ||
| 182 | - ListItem() { | ||
| 183 | - ChildCommentComponent({data: item,levelHead:UserDataLocal.getUserLevelHeaderUrl(),isLastItem:index===this.data_comment.totalCount()-1}) | ||
| 184 | - } | ||
| 185 | - .onClick(() => { | ||
| 186 | - }) | ||
| 187 | - }, (item: CommentListItem, index: number) => index.toString()) | ||
| 188 | - | ||
| 189 | - //没有更多数据 显示提示 | ||
| 190 | - if(!this.hasMore){ | ||
| 191 | - ListItem(){ | ||
| 192 | - ListHasNoMoreDataUI() | ||
| 193 | - } | ||
| 194 | - } | ||
| 195 | - }.cachedCount(15) | ||
| 196 | - .layoutWeight(1) | ||
| 197 | - .scrollBar(BarState.Off) | ||
| 198 | - .edgeEffect(EdgeEffect.None) | ||
| 199 | - .nestedScroll({ | ||
| 200 | - scrollForward: NestedScrollMode.PARENT_FIRST, | ||
| 201 | - scrollBackward: NestedScrollMode.SELF_FIRST | ||
| 202 | - }) | ||
| 203 | - .onReachEnd(()=>{ | ||
| 204 | - console.log(TAG,"触底了"); | ||
| 205 | - if(!this.isLoading){ | ||
| 206 | - this.isLoading = true | ||
| 207 | - //加载分页数据 | ||
| 208 | - this.getNewPageData() | ||
| 209 | - } | ||
| 210 | - }) | ||
| 211 | - } | ||
| 212 | - } | ||
| 213 | - }.layoutWeight(1) | ||
| 214 | - .justifyContent(FlexAlign.Start) | ||
| 215 | - .width('100%') | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - | ||
| 219 | - @Styles | ||
| 220 | - listStyle() { | ||
| 221 | - .backgroundColor(Color.White) | ||
| 222 | - .height(72) | ||
| 223 | - .width("100%") | ||
| 224 | - .borderRadius(12) | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | - | ||
| 228 | - getMyFollowListDetail(){ | ||
| 229 | - if(this.hasMore){ | ||
| 230 | - let object = new FollowListDetailRequestItem(-1,20,this.curPageNum) | ||
| 231 | - | ||
| 232 | - MinePageDatasModel.getMineFollowListData(object,getContext(this)).then((value)=>{ | ||
| 233 | - if (!this.data_follow || value.list.length == 0){ | ||
| 234 | - this.hasMore = false | ||
| 235 | - }else{ | ||
| 236 | - value.list.forEach((value)=>{ | ||
| 237 | - let fansNum:number = value.fansNum | ||
| 238 | - let fansNumString = "" | ||
| 239 | - if (fansNum > 10000) { | ||
| 240 | - let temp = (fansNum / 10000) + "" | ||
| 241 | - let index = temp.indexOf('.') | ||
| 242 | - if (index != -1) { | ||
| 243 | - temp = temp.substring(0, index + 2) | ||
| 244 | - } else { | ||
| 245 | - temp = temp | ||
| 246 | - } | ||
| 247 | - fansNumString = temp + "万" | ||
| 248 | - } else { | ||
| 249 | - fansNumString = fansNum + "" | ||
| 250 | - } | ||
| 251 | - this.data_follow.push(new FollowListDetailItem(value.attentionHeadPhotoUrl,value.attentionUserName,fansNumString,value.introduction,value.attentionCreatorId,"1",value.attentionUserId,value.attentionUserType,value.attentionUserId,value.mainControl,value.banControl,value.authIcon)) | ||
| 252 | - }) | ||
| 253 | - this.data_follow.notifyDataReload() | ||
| 254 | - this.count = this.data_follow.totalCount() | ||
| 255 | - if (this.data_follow.totalCount() < value.totalCount) { | ||
| 256 | - this.curPageNum++ | ||
| 257 | - }else { | ||
| 258 | - this.hasMore = false | ||
| 259 | - } | ||
| 260 | - } | ||
| 261 | - this.isLoading = false | ||
| 262 | - this.isGetRequest = true | ||
| 263 | - }).catch((err:Error)=>{ | ||
| 264 | - console.log(TAG,"请求失败") | ||
| 265 | - this.isLoading = false | ||
| 266 | - this.isGetRequest = true | ||
| 267 | - }) | ||
| 268 | - }else{ | ||
| 269 | - this.isLoading = false | ||
| 270 | - this.isGetRequest = true | ||
| 271 | - } | ||
| 272 | - } | ||
| 273 | - | ||
| 274 | - getNewPageData(){ | ||
| 275 | - this.isLoading = true | ||
| 276 | - //我的关注列表 | ||
| 277 | - if (this.style === 1){ | ||
| 278 | - this.getMyFollowListDetail() | ||
| 279 | - }else if(this.style === 0){ | ||
| 280 | - if(this.hasMore){ | ||
| 281 | - let time = encodeURI(DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 282 | - let object = new FollowListDetailRequestItem(-1,20,this.curPageNum) | ||
| 283 | - | ||
| 284 | - MinePageDatasModel.getMineCommentListData(time,object,getContext(this)).then((value)=>{ | ||
| 285 | - if (!this.data_comment || value.list.length == 0){ | ||
| 286 | - this.hasMore = false | ||
| 287 | - this.isLoading = false | ||
| 288 | - this.isGetRequest = true | ||
| 289 | - }else{ | ||
| 290 | - this.getCommentListStatus(value) | ||
| 291 | - } | ||
| 292 | - }).catch((err:Error)=>{ | ||
| 293 | - console.log(TAG,"请求失败") | ||
| 294 | - this.isLoading = false | ||
| 295 | - this.isGetRequest = true | ||
| 296 | - }) | ||
| 297 | - }else{ | ||
| 298 | - this.isLoading = false | ||
| 299 | - this.isGetRequest = true | ||
| 300 | - } | ||
| 301 | - } | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | - getCommentListStatus(value:MineCommentListDetailItem){ | ||
| 305 | - | ||
| 306 | - let status = new OtherUserCommentLikeStatusRequestItem() | ||
| 307 | - let data : CommentListItem[] = [] | ||
| 308 | - value.list.forEach((item)=>{ | ||
| 309 | - if(item.checkStatus === 2){ | ||
| 310 | - status.commentIdList.push(item.id) | ||
| 311 | - } | ||
| 312 | - let commentContent = item.commentContent | ||
| 313 | - if(item.sensitiveShow === 0 && item.sensitiveExist === 1){ | ||
| 314 | - commentContent = item.commentContentSensitive | ||
| 315 | - } | ||
| 316 | - let parentCommentContent = "" | ||
| 317 | - if(item.parentCommentVo!=null ){ | ||
| 318 | - parentCommentContent = item.parentCommentVo.commentContent | ||
| 319 | - } | ||
| 320 | - let parentCommentUserName = "" | ||
| 321 | - if(item.parentCommentVo!=null ){ | ||
| 322 | - parentCommentUserName = item.parentCommentVo.fromUserName | ||
| 323 | - } | ||
| 324 | - data.push(new CommentListItem(item.fromUserHeader,item.fromUserName,item.targetTitle,item.createTime,commentContent,item.likeNum,0,item.id,item.targetId,item.targetType,item.targetRelId,item.targetRelObjectId,item.targetRelType,item.targetStatus,item.checkStatus,parentCommentContent,parentCommentUserName)) | ||
| 325 | - }) | ||
| 326 | - | ||
| 327 | - if(status.commentIdList.length === 0){ | ||
| 328 | - data.forEach((item)=>{ | ||
| 329 | - let publishTime = DateTimeUtils.getCommentTime(DateTimeUtils.parseDate(item.createTime,DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 330 | - this.data_comment.push(new CommentListItem(item.fromUserHeader,item.fromUserName,item.targetTitle,publishTime,item.commentContent,item.likeNum,item.like_status,item.id,item.targetId,item.targetType,item.targetRelId,item.targetRelObjectId,item.targetRelType,item.targetStatus,item.checkStatus,item.parentCommentContent,item.parentCommentUserName)) | ||
| 331 | - }) | ||
| 332 | - | ||
| 333 | - this.data_comment.notifyDataReload() | ||
| 334 | - | ||
| 335 | - this.count = this.data_comment.totalCount() | ||
| 336 | - this.commentNum = value.totalCount | ||
| 337 | - if (this.data_comment.totalCount() < value.totalCount) { | ||
| 338 | - this.curPageNum++ | ||
| 339 | - }else { | ||
| 340 | - this.hasMore = false | ||
| 341 | - } | ||
| 342 | - | ||
| 343 | - this.isLoading = false | ||
| 344 | - this.isGetRequest = true | ||
| 345 | - return | ||
| 346 | - } | ||
| 347 | - | ||
| 348 | - MinePageDatasModel.getOtherUserCommentLikeStatusData(status,getContext(this)).then((newValue)=>{ | ||
| 349 | - newValue.forEach((item)=>{ | ||
| 350 | - data.forEach((list)=>{ | ||
| 351 | - if (item.commentId == list.id) { | ||
| 352 | - list.like_status = item.status | ||
| 353 | - } | ||
| 354 | - }) | ||
| 355 | - }) | ||
| 356 | - | ||
| 357 | - data.forEach((item)=>{ | ||
| 358 | - let publishTime = DateTimeUtils.getCommentTime(DateTimeUtils.parseDate(item.createTime,DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | ||
| 359 | - this.data_comment.push(new CommentListItem(item.fromUserHeader,item.fromUserName,item.targetTitle,publishTime,item.commentContent,item.likeNum,item.like_status,item.id,item.targetId,item.targetType,item.targetRelId,item.targetRelObjectId,item.targetRelType,item.targetStatus,item.checkStatus,item.parentCommentContent,item.parentCommentUserName)) | ||
| 360 | - }) | ||
| 361 | - | ||
| 362 | - this.data_comment.notifyDataReload() | ||
| 363 | - | ||
| 364 | - this.count = this.data_comment.totalCount() | ||
| 365 | - this.commentNum = value.totalCount | ||
| 366 | - if (this.data_comment.totalCount() < value.totalCount) { | ||
| 367 | - this.curPageNum++ | ||
| 368 | - }else { | ||
| 369 | - this.hasMore = false | ||
| 370 | - } | ||
| 371 | - | ||
| 372 | - this.isLoading = false | ||
| 373 | - this.isGetRequest = true | ||
| 374 | - }).catch((err:Error)=>{ | ||
| 375 | - console.log(TAG,"请求失败") | ||
| 376 | - this.isLoading = false | ||
| 377 | - this.isGetRequest = true | ||
| 378 | - }) | ||
| 379 | - } | ||
| 380 | - | ||
| 381 | -} |
| 1 | +import { LazyDataSource, SPHelper, UserDataLocal } from 'wdKit'; | ||
| 2 | +import { WDRouterPage, WDRouterRule } from 'wdRouter'; | ||
| 3 | +import MinePageDatasModel from '../../../model/MinePageDatasModel'; | ||
| 4 | +import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem'; | ||
| 5 | +import { FollowListDetailRequestItem } from '../../../viewmodel/FollowListDetailRequestItem'; | ||
| 6 | +import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; | ||
| 7 | +import { FollowChildComponent } from '../follow/FollowChildComponent'; | ||
| 8 | +import dataPreferences from '@ohos.data.preferences'; | ||
| 9 | +import { EmptyComponent } from '../../view/EmptyComponent'; | ||
| 10 | + | ||
| 11 | +const TAG = "HomePageBottomFollowComponent" | ||
| 12 | +/** | ||
| 13 | + * 我的主页 关注 tab | ||
| 14 | + */ | ||
| 15 | +@Component | ||
| 16 | +export struct HomePageBottomFollowComponent { | ||
| 17 | + @State data_follow: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); | ||
| 18 | + @State isLoading: boolean = false | ||
| 19 | + @State hasMore: boolean = true | ||
| 20 | + curPageNum: number = 1; | ||
| 21 | + @State count: number = 0; | ||
| 22 | + preferences: dataPreferences.Preferences | null = null; | ||
| 23 | + @State isGetRequest: boolean = false | ||
| 24 | + observer = (key: string) => { | ||
| 25 | + if (key == UserDataLocal.USER_FOLLOW_OPERATION) { | ||
| 26 | + let value = SPHelper.default.getSync(UserDataLocal.USER_FOLLOW_OPERATION, "") as string | ||
| 27 | + let arr = value.split(',') | ||
| 28 | + if (arr[1] == "0") { | ||
| 29 | + this.data_follow.getDataArray().forEach((element, index) => { | ||
| 30 | + if (element.creatorId === arr[0]) { | ||
| 31 | + this.data_follow.deleteItem(index) | ||
| 32 | + this.count = this.data_follow.size() | ||
| 33 | + } | ||
| 34 | + }); | ||
| 35 | + } else { | ||
| 36 | + if (!this.isLoading) { | ||
| 37 | + this.isLoading = true | ||
| 38 | + this.hasMore = true | ||
| 39 | + this.curPageNum = 1 | ||
| 40 | + this.data_follow.clear() | ||
| 41 | + this.data_follow.notifyDataReload() | ||
| 42 | + this.getMyFollowListDetail() | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + aboutToAppear() { | ||
| 49 | + this.getNewPageData() | ||
| 50 | + this.addFollowStatusObserver() | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + async addFollowStatusObserver() { | ||
| 54 | + this.preferences = await SPHelper.default.getPreferences(); | ||
| 55 | + this.preferences.on('change', this.observer); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + aboutToDisappear(): void { | ||
| 59 | + if (this.preferences) { | ||
| 60 | + this.preferences.off('change', this.observer); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + build() { | ||
| 65 | + | ||
| 66 | + Column() { | ||
| 67 | + if (this.isGetRequest == true) { | ||
| 68 | + Divider().width('100%') | ||
| 69 | + .height('2lpx') | ||
| 70 | + .strokeWidth('1lpx') | ||
| 71 | + .backgroundColor($r('app.color.color_EDEDED')) | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + if (this.count === 0) { | ||
| 75 | + Stack({ alignContent: Alignment.Top }) { | ||
| 76 | + if (this.isGetRequest == true) { | ||
| 77 | + EmptyComponent({ emptyType: 14 }) | ||
| 78 | + .layoutWeight(1) | ||
| 79 | + .width('100%') | ||
| 80 | + .offset({ y: "-200lpx" }) | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + Row() { | ||
| 84 | + Text("关注更多人民号") | ||
| 85 | + .fontWeight('400lpx') | ||
| 86 | + .fontColor($r('app.color.color_222222')) | ||
| 87 | + .lineHeight('38lpx') | ||
| 88 | + .fontSize('27lpx') | ||
| 89 | + .textAlign(TextAlign.Center) | ||
| 90 | + .margin({ right: '4lpx' }) | ||
| 91 | + Image($r('app.media.arrow_icon_right')) | ||
| 92 | + .objectFit(ImageFit.Auto) | ||
| 93 | + .width('27lpx') | ||
| 94 | + .height('27lpx') | ||
| 95 | + } | ||
| 96 | + .height('69lpx') | ||
| 97 | + .width('659lpx') | ||
| 98 | + .alignItems(VerticalAlign.Center) | ||
| 99 | + .justifyContent(FlexAlign.Center) | ||
| 100 | + .backgroundColor($r('app.color.color_F5F5F5')) | ||
| 101 | + .margin({ top: '31lpx', bottom: '4lpx' }) | ||
| 102 | + .onClick(() => { | ||
| 103 | + let params = { 'index': "1" } as Record<string, string> | ||
| 104 | + WDRouterRule.jumpWithPage(WDRouterPage.followListPage, params) | ||
| 105 | + }) | ||
| 106 | + }.layoutWeight(1) | ||
| 107 | + } else { | ||
| 108 | + List({ space: 3 }) { | ||
| 109 | + | ||
| 110 | + ListItem() { | ||
| 111 | + Row() { | ||
| 112 | + Text("关注更多人民号") | ||
| 113 | + .fontWeight('400lpx') | ||
| 114 | + .fontColor($r('app.color.color_222222')) | ||
| 115 | + .lineHeight('38lpx') | ||
| 116 | + .fontSize('27lpx') | ||
| 117 | + .textAlign(TextAlign.Center) | ||
| 118 | + .margin({ right: '4lpx' }) | ||
| 119 | + Image($r('app.media.arrow_icon_right')) | ||
| 120 | + .objectFit(ImageFit.Auto) | ||
| 121 | + .width('27lpx') | ||
| 122 | + .height('27lpx') | ||
| 123 | + } | ||
| 124 | + .height('69lpx') | ||
| 125 | + .width('659lpx') | ||
| 126 | + .alignItems(VerticalAlign.Center) | ||
| 127 | + .justifyContent(FlexAlign.Center) | ||
| 128 | + .backgroundColor($r('app.color.color_F5F5F5')) | ||
| 129 | + .margin({ top: '31lpx', bottom: '4lpx' }) | ||
| 130 | + }.onClick(() => { | ||
| 131 | + let params = { 'index': "1" } as Record<string, string> | ||
| 132 | + WDRouterRule.jumpWithPage(WDRouterPage.followListPage, params) | ||
| 133 | + }) | ||
| 134 | + | ||
| 135 | + LazyForEach(this.data_follow, (item: FollowListDetailItem, index: number = 0) => { | ||
| 136 | + ListItem() { | ||
| 137 | + FollowChildComponent({ data: item, type: 2 }) | ||
| 138 | + } | ||
| 139 | + }, (item: FollowListDetailItem, index: number) => index.toString()) | ||
| 140 | + | ||
| 141 | + //没有更多数据 显示提示 | ||
| 142 | + if (!this.hasMore) { | ||
| 143 | + ListItem() { | ||
| 144 | + ListHasNoMoreDataUI() | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + .cachedCount(15) | ||
| 149 | + .padding({ left: '31lpx', right: '31lpx' }) | ||
| 150 | + .layoutWeight(1) | ||
| 151 | + .scrollBar(BarState.Off) | ||
| 152 | + .edgeEffect(EdgeEffect.None) | ||
| 153 | + .nestedScroll({ | ||
| 154 | + scrollForward: NestedScrollMode.PARENT_FIRST, | ||
| 155 | + scrollBackward: NestedScrollMode.SELF_FIRST | ||
| 156 | + }) | ||
| 157 | + .onReachEnd(() => { | ||
| 158 | + console.log(TAG, "触底了"); | ||
| 159 | + if (!this.isLoading) { | ||
| 160 | + this.isLoading = true | ||
| 161 | + //加载分页数据 | ||
| 162 | + this.getNewPageData() | ||
| 163 | + } | ||
| 164 | + }) | ||
| 165 | + } | ||
| 166 | + }.layoutWeight(1) | ||
| 167 | + .justifyContent(FlexAlign.Start) | ||
| 168 | + .width('100%') | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + @Styles | ||
| 172 | + listStyle() { | ||
| 173 | + .backgroundColor(Color.White) | ||
| 174 | + .height(72) | ||
| 175 | + .width("100%") | ||
| 176 | + .borderRadius(12) | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + getMyFollowListDetail() { | ||
| 180 | + if (this.hasMore) { | ||
| 181 | + let object = new FollowListDetailRequestItem(-1, 20, this.curPageNum) | ||
| 182 | + | ||
| 183 | + MinePageDatasModel.getMineFollowListData(object, getContext(this)).then((value) => { | ||
| 184 | + if (!this.data_follow || value.list.length == 0) { | ||
| 185 | + this.hasMore = false | ||
| 186 | + } else { | ||
| 187 | + value.list.forEach((value) => { | ||
| 188 | + let fansNum: number = value.fansNum | ||
| 189 | + let fansNumString = "" | ||
| 190 | + if (fansNum > 10000) { | ||
| 191 | + let temp = (fansNum / 10000) + "" | ||
| 192 | + let index = temp.indexOf('.') | ||
| 193 | + if (index != -1) { | ||
| 194 | + temp = temp.substring(0, index + 2) | ||
| 195 | + } else { | ||
| 196 | + temp = temp | ||
| 197 | + } | ||
| 198 | + fansNumString = temp + "万" | ||
| 199 | + } else { | ||
| 200 | + fansNumString = fansNum + "" | ||
| 201 | + } | ||
| 202 | + this.data_follow.push(new FollowListDetailItem(value.attentionHeadPhotoUrl, value.attentionUserName, | ||
| 203 | + fansNumString, value.introduction, value.attentionCreatorId, "1", value.attentionUserId, | ||
| 204 | + value.attentionUserType, value.attentionUserId, value.mainControl, value.banControl, value.authIcon)) | ||
| 205 | + }) | ||
| 206 | + this.data_follow.notifyDataReload() | ||
| 207 | + this.count = this.data_follow.totalCount() | ||
| 208 | + if (this.data_follow.totalCount() < value.totalCount) { | ||
| 209 | + this.curPageNum++ | ||
| 210 | + } else { | ||
| 211 | + this.hasMore = false | ||
| 212 | + } | ||
| 213 | + } | ||
| 214 | + this.isLoading = false | ||
| 215 | + this.isGetRequest = true | ||
| 216 | + }).catch((err: Error) => { | ||
| 217 | + console.log(TAG, "请求失败") | ||
| 218 | + this.isLoading = false | ||
| 219 | + this.isGetRequest = true | ||
| 220 | + }) | ||
| 221 | + } else { | ||
| 222 | + this.isLoading = false | ||
| 223 | + this.isGetRequest = true | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + getNewPageData() { | ||
| 228 | + this.isLoading = true | ||
| 229 | + //我的关注列表 | ||
| 230 | + this.getMyFollowListDetail() | ||
| 231 | + } | ||
| 232 | +} |
| @@ -9,7 +9,9 @@ import { ChildCommentComponent } from './ChildCommentComponent'; | @@ -9,7 +9,9 @@ import { ChildCommentComponent } from './ChildCommentComponent'; | ||
| 9 | import { EmptyComponent } from '../../view/EmptyComponent'; | 9 | import { EmptyComponent } from '../../view/EmptyComponent'; |
| 10 | 10 | ||
| 11 | const TAG = "HomePageBottomComponent" | 11 | const TAG = "HomePageBottomComponent" |
| 12 | - | 12 | +/** |
| 13 | + * 普通用户的主页 评论 tab | ||
| 14 | + */ | ||
| 13 | @Component | 15 | @Component |
| 14 | export struct OtherHomePageBottomCommentComponent { | 16 | export struct OtherHomePageBottomCommentComponent { |
| 15 | @Prop curUserId: string | 17 | @Prop curUserId: string |
| @@ -9,6 +9,10 @@ import { EmptyComponent } from '../../view/EmptyComponent'; | @@ -9,6 +9,10 @@ import { EmptyComponent } from '../../view/EmptyComponent'; | ||
| 9 | import { FollowChildComponent } from '../follow/FollowChildComponent'; | 9 | import { FollowChildComponent } from '../follow/FollowChildComponent'; |
| 10 | 10 | ||
| 11 | const TAG = "HomePageBottomComponent" | 11 | const TAG = "HomePageBottomComponent" |
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 普通用户的主页 关注 tab | ||
| 15 | + */ | ||
| 12 | @Component | 16 | @Component |
| 13 | export struct OtherHomePageBottomFollowComponent{ | 17 | export struct OtherHomePageBottomFollowComponent{ |
| 14 | @State data_follow: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); | 18 | @State data_follow: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); |
| 1 | import router from '@ohos.router' | 1 | import router from '@ohos.router' |
| 2 | -import { Params } from 'wdBean'; | ||
| 3 | import { StringUtils } from 'wdKit'; | 2 | import { StringUtils } from 'wdKit'; |
| 4 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; | 3 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 5 | -import { HomePageBottomComponent } from '../components/mine/home/HomePageBottomComponent'; | 4 | +import { HomePageBottomCommentComponent } from '../components/mine/home/HomePageBottomCommentComponent'; |
| 5 | +import { HomePageBottomFollowComponent } from '../components/mine/home/HomePageBottomFollowComponent'; | ||
| 6 | import MinePageDatasModel from '../model/MinePageDatasModel'; | 6 | import MinePageDatasModel from '../model/MinePageDatasModel'; |
| 7 | 7 | ||
| 8 | const TAG = "MineHomePage" | 8 | const TAG = "MineHomePage" |
| @@ -185,10 +185,10 @@ struct MineHomePage { | @@ -185,10 +185,10 @@ struct MineHomePage { | ||
| 185 | Stack({ alignContent: Alignment.Top }){ | 185 | Stack({ alignContent: Alignment.Top }){ |
| 186 | Tabs({controller: this.controller}) { | 186 | Tabs({controller: this.controller}) { |
| 187 | TabContent() { | 187 | TabContent() { |
| 188 | - HomePageBottomComponent({style:0,commentNum:$commentNum}) | 188 | + HomePageBottomCommentComponent({commentNum:$commentNum}) |
| 189 | } | 189 | } |
| 190 | TabContent() { | 190 | TabContent() { |
| 191 | - HomePageBottomComponent({style:1,commentNum:$commentNum}) | 191 | + HomePageBottomFollowComponent() |
| 192 | } | 192 | } |
| 193 | } | 193 | } |
| 194 | .backgroundColor($r('app.color.white')) | 194 | .backgroundColor($r('app.color.white')) |
-
Please register or login to post a comment