Showing
4 changed files
with
203 additions
and
83 deletions
| @@ -24,6 +24,7 @@ export class UserDataLocal { | @@ -24,6 +24,7 @@ export class UserDataLocal { | ||
| 24 | static USER_HEADER_URL="userHeaderUrl" | 24 | static USER_HEADER_URL="userHeaderUrl" |
| 25 | static USER_LEVEL="userLevel" | 25 | static USER_LEVEL="userLevel" |
| 26 | static USER_LEVEL_HEADER_URL="userLevelHeaderUrl" | 26 | static USER_LEVEL_HEADER_URL="userLevelHeaderUrl" |
| 27 | + static USER_FOLLOW_OPERATION="user_follow_operation" | ||
| 27 | 28 | ||
| 28 | //刷新token 用到 | 29 | //刷新token 用到 |
| 29 | static USER_REFRESH_TOKEN="refreshToken" | 30 | static USER_REFRESH_TOKEN="refreshToken" |
| @@ -89,6 +90,10 @@ export class UserDataLocal { | @@ -89,6 +90,10 @@ export class UserDataLocal { | ||
| 89 | SPHelper.default.save(UserDataLocal.USER_HEADER_URL, url) | 90 | SPHelper.default.save(UserDataLocal.USER_HEADER_URL, url) |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 93 | + public static setUserFollowOperation(timestamp:string) { | ||
| 94 | + SPHelper.default.saveSync(UserDataLocal.USER_FOLLOW_OPERATION, timestamp) | ||
| 95 | + } | ||
| 96 | + | ||
| 92 | 97 | ||
| 93 | public static getUserLevel() { | 98 | public static getUserLevel() { |
| 94 | if(UserDataLocal.userLevel != -1){ | 99 | if(UserDataLocal.userLevel != -1){ |
| 1 | -import { StringUtils, ToastUtils } from 'wdKit/Index' | 1 | +import { DateTimeUtils, StringUtils, ToastUtils, UserDataLocal } from 'wdKit/Index' |
| 2 | import { HttpUrlUtils } from 'wdNetwork/Index' | 2 | import { HttpUrlUtils } from 'wdNetwork/Index' |
| 3 | import { WDRouterRule, WDRouterPage } from 'wdRouter/Index' | 3 | import { WDRouterRule, WDRouterPage } from 'wdRouter/Index' |
| 4 | import MinePageDatasModel from '../../../model/MinePageDatasModel' | 4 | import MinePageDatasModel from '../../../model/MinePageDatasModel' |
| @@ -133,14 +133,17 @@ export struct FollowChildComponent{ | @@ -133,14 +133,17 @@ export struct FollowChildComponent{ | ||
| 133 | .maxLines(1) | 133 | .maxLines(1) |
| 134 | .margin({bottom:'12lpx'}) | 134 | .margin({bottom:'12lpx'}) |
| 135 | Row(){ | 135 | Row(){ |
| 136 | + if(this.data.cnFansNum!="0"){ | ||
| 136 | Text(`粉丝${this.data.cnFansNum}`) | 137 | Text(`粉丝${this.data.cnFansNum}`) |
| 137 | .fontColor($r('app.color.color_B0B0B0')) | 138 | .fontColor($r('app.color.color_B0B0B0')) |
| 138 | .fontSize('23lpx') | 139 | .fontSize('23lpx') |
| 139 | - | 140 | + } |
| 141 | + if(this.data.cnFansNum!="0" && StringUtils.isNotEmpty(this.data.introduction)){ | ||
| 140 | Image($r("app.media.point")) | 142 | Image($r("app.media.point")) |
| 141 | .width('31lpx') | 143 | .width('31lpx') |
| 142 | .height('31lpx') | 144 | .height('31lpx') |
| 143 | .objectFit(ImageFit.Auto) | 145 | .objectFit(ImageFit.Auto) |
| 146 | + } | ||
| 144 | 147 | ||
| 145 | Text(`${this.data.introduction}`) | 148 | Text(`${this.data.introduction}`) |
| 146 | .fontColor($r('app.color.color_B0B0B0')) | 149 | .fontColor($r('app.color.color_B0B0B0')) |
| @@ -222,6 +225,12 @@ export struct FollowChildComponent{ | @@ -222,6 +225,12 @@ export struct FollowChildComponent{ | ||
| 222 | if(value!=null){ | 225 | if(value!=null){ |
| 223 | if (value.code === 0 || value.code.toString() === "0") { | 226 | if (value.code === 0 || value.code.toString() === "0") { |
| 224 | this.data.status = this.data.status ==="0"?"1":"0" | 227 | this.data.status = this.data.status ==="0"?"1":"0" |
| 228 | + | ||
| 229 | + if(this.data.status === "1"){ | ||
| 230 | + UserDataLocal.setUserFollowOperation(DateTimeUtils.getTimeStamp()+"") | ||
| 231 | + }else{ | ||
| 232 | + UserDataLocal.setUserFollowOperation(DateTimeUtils.getTimeStamp()+","+this.data.creatorId) | ||
| 233 | + } | ||
| 225 | } | 234 | } |
| 226 | } | 235 | } |
| 227 | }) | 236 | }) |
| 1 | -import { LazyDataSource } from 'wdKit'; | 1 | +import { LazyDataSource, SPHelper, UserDataLocal } from 'wdKit'; |
| 2 | import MinePageDatasModel from '../../../model/MinePageDatasModel'; | 2 | import MinePageDatasModel from '../../../model/MinePageDatasModel'; |
| 3 | import SearcherAboutDataModel from '../../../model/SearcherAboutDataModel'; | 3 | import SearcherAboutDataModel from '../../../model/SearcherAboutDataModel'; |
| 4 | import { CreatorDetailRequestItem } from '../../../viewmodel/CreatorDetailRequestItem'; | 4 | import { CreatorDetailRequestItem } from '../../../viewmodel/CreatorDetailRequestItem'; |
| @@ -9,50 +9,55 @@ import { MineFollowListDetailItem } from '../../../viewmodel/MineFollowListDetai | @@ -9,50 +9,55 @@ import { MineFollowListDetailItem } from '../../../viewmodel/MineFollowListDetai | ||
| 9 | import { QueryListIsFollowedItem } from '../../../viewmodel/QueryListIsFollowedItem'; | 9 | import { QueryListIsFollowedItem } from '../../../viewmodel/QueryListIsFollowedItem'; |
| 10 | import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; | 10 | import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; |
| 11 | import { FollowChildComponent } from './FollowChildComponent'; | 11 | import { FollowChildComponent } from './FollowChildComponent'; |
| 12 | +import dataPreferences from '@ohos.data.preferences'; | ||
| 12 | 13 | ||
| 13 | const TAG = "FollowListDetailUI" | 14 | const TAG = "FollowListDetailUI" |
| 15 | + | ||
| 14 | @Component | 16 | @Component |
| 15 | -export struct FollowListDetailUI{ | ||
| 16 | - @State creatorDirectoryId:number = -1; | ||
| 17 | - @State type:number = 0 | 17 | +export struct FollowListDetailUI { |
| 18 | + @State creatorDirectoryId: number = -1; | ||
| 19 | + @State type: number = 0 | ||
| 18 | @State data: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); | 20 | @State data: LazyDataSource<FollowListDetailItem> = new LazyDataSource(); |
| 19 | - @State count:number = 0; | ||
| 20 | - @State isLoading:boolean = false | ||
| 21 | - @State hasMore:boolean = true | ||
| 22 | - curPageNum:number = 1; | 21 | + @State count: number = 0; |
| 22 | + @State isLoading: boolean = false | ||
| 23 | + @State hasMore: boolean = true | ||
| 24 | + curPageNum: number = 1; | ||
| 25 | + preferences: dataPreferences.Preferences | null = null; | ||
| 23 | 26 | ||
| 24 | - aboutToAppear(){ | 27 | + aboutToAppear() { |
| 25 | this.getNewPageData() | 28 | this.getNewPageData() |
| 29 | + this.addFollowStatusObserver() | ||
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | - build(){ | ||
| 29 | - Column(){ | ||
| 30 | - if(this.count === 0){ | ||
| 31 | - ListHasNoMoreDataUI({style:2}) | 32 | + build() { |
| 33 | + Column() { | ||
| 34 | + if (this.count === 0) { | ||
| 35 | + ListHasNoMoreDataUI({ style: 2 }) | ||
| 32 | .height('100%') | 36 | .height('100%') |
| 33 | - }else{ | 37 | + } else { |
| 34 | List({ space: 3 }) { | 38 | List({ space: 3 }) { |
| 35 | LazyForEach(this.data, (item: FollowListDetailItem, index: number = 0) => { | 39 | LazyForEach(this.data, (item: FollowListDetailItem, index: number = 0) => { |
| 36 | ListItem() { | 40 | ListItem() { |
| 37 | - FollowChildComponent({data: item,type:this.type}) | 41 | + FollowChildComponent({ data: item, type: this.type }) |
| 38 | } | 42 | } |
| 39 | .onClick(() => { | 43 | .onClick(() => { |
| 40 | }) | 44 | }) |
| 41 | - }, (item: FollowListDetailItem, index: number) => index.toString()) | 45 | + }, (item: FollowListDetailItem) => item.creatorId) |
| 42 | 46 | ||
| 43 | //没有更多数据 显示提示 | 47 | //没有更多数据 显示提示 |
| 44 | - if(!this.hasMore){ | ||
| 45 | - ListItem(){ | 48 | + if (!this.hasMore) { |
| 49 | + ListItem() { | ||
| 46 | ListHasNoMoreDataUI() | 50 | ListHasNoMoreDataUI() |
| 47 | } | 51 | } |
| 48 | } | 52 | } |
| 49 | - }.cachedCount(10) | ||
| 50 | - .padding({left:'31lpx',right:'31lpx'}) | 53 | + } |
| 54 | + .cachedCount(10) | ||
| 55 | + .padding({ left: '31lpx', right: '31lpx' }) | ||
| 51 | .layoutWeight(1) | 56 | .layoutWeight(1) |
| 52 | .scrollBar(BarState.Off) | 57 | .scrollBar(BarState.Off) |
| 53 | - .onReachEnd(()=>{ | ||
| 54 | - console.log(TAG,"触底了"); | ||
| 55 | - if(!this.isLoading){ | 58 | + .onReachEnd(() => { |
| 59 | + console.log(TAG, "触底了"); | ||
| 60 | + if (!this.isLoading) { | ||
| 56 | this.isLoading = true | 61 | this.isLoading = true |
| 57 | //加载分页数据 | 62 | //加载分页数据 |
| 58 | this.getNewPageData() | 63 | this.getNewPageData() |
| @@ -63,79 +68,128 @@ export struct FollowListDetailUI{ | @@ -63,79 +68,128 @@ export struct FollowListDetailUI{ | ||
| 63 | .width('100%') | 68 | .width('100%') |
| 64 | } | 69 | } |
| 65 | 70 | ||
| 66 | - getNewPageData(){ | 71 | + async addFollowStatusObserver() { |
| 72 | + this.preferences = await SPHelper.default.getPreferences(); | ||
| 73 | + let observer = (key: string) => { | ||
| 74 | + if (key == UserDataLocal.USER_FOLLOW_OPERATION) { | ||
| 75 | + if (this.creatorDirectoryId === -1) { | ||
| 76 | + let value = SPHelper.default.getSync(UserDataLocal.USER_FOLLOW_OPERATION,"") as string | ||
| 77 | + let arr = value.split(',') | ||
| 78 | + if(arr!=null && arr.length === 2){ | ||
| 79 | + this.data.getDataArray().forEach((element,index) => { | ||
| 80 | + if (element.creatorId === arr[1]) { | ||
| 81 | + this.data.deleteItem(index) | ||
| 82 | + } | ||
| 83 | + }); | ||
| 84 | + }else{ | ||
| 85 | + if(!this.isLoading){ | ||
| 67 | this.isLoading = true | 86 | this.isLoading = true |
| 68 | - //我的关注列表 | ||
| 69 | - if (this.creatorDirectoryId === -1){ | ||
| 70 | - if(this.hasMore){ | ||
| 71 | - let object = new FollowListDetailRequestItem(-1,20,this.curPageNum) | 87 | + this.hasMore = true |
| 88 | + this.curPageNum = 1 | ||
| 89 | + this.data.clear() | ||
| 90 | + this.data.notifyDataReload() | ||
| 91 | + this.getMyFollowListDetail() | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + this.preferences.on('change', observer); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + getMyFollowListDetail() { | ||
| 101 | + if (this.hasMore) { | ||
| 102 | + let object = new FollowListDetailRequestItem(-1, 20, this.curPageNum) | ||
| 72 | 103 | ||
| 73 | - MinePageDatasModel.getMineFollowListData(object,getContext(this)).then((value)=>{ | ||
| 74 | - if (!this.data || value.list.length == 0){ | 104 | + MinePageDatasModel.getMineFollowListData(object, getContext(this)).then((value) => { |
| 105 | + if (!this.data || value.list.length == 0) { | ||
| 75 | this.hasMore = false | 106 | this.hasMore = false |
| 76 | - }else{ | ||
| 77 | - value.list.forEach((value)=>{ | ||
| 78 | - this.data.push(new FollowListDetailItem(value.attentionHeadPhotoUrl,value.attentionUserName,value.fansNum+"",value.introduction,value.attentionCreatorId,"1",value.attentionUserId,value.attentionUserType,value.attentionUserId,value.mainControl,value.banControl)) | 107 | + this.isLoading = false |
| 108 | + } else { | ||
| 109 | + value.list.forEach((value) => { | ||
| 110 | + let fansNum:number = value.fansNum | ||
| 111 | + let fansNumString = "" | ||
| 112 | + if (fansNum > 10000) { | ||
| 113 | + let temp = (fansNum / 10000) + "" | ||
| 114 | + let index = temp.indexOf('.') | ||
| 115 | + if (index != -1) { | ||
| 116 | + temp = temp.substring(0, index + 2) | ||
| 117 | + } else { | ||
| 118 | + temp = temp | ||
| 119 | + } | ||
| 120 | + fansNumString = temp + "万" | ||
| 121 | + } else { | ||
| 122 | + fansNumString = fansNum + "" | ||
| 123 | + } | ||
| 124 | + this.data.push(new FollowListDetailItem(value.attentionHeadPhotoUrl, value.attentionUserName, fansNumString, value.introduction, value.attentionCreatorId, "1", value.attentionUserId, value.attentionUserType, value.attentionUserId, value.mainControl, value.banControl)) | ||
| 79 | }) | 125 | }) |
| 80 | this.data.notifyDataReload() | 126 | this.data.notifyDataReload() |
| 81 | this.count = this.data.totalCount() | 127 | this.count = this.data.totalCount() |
| 82 | if (this.data.totalCount() < value.totalCount) { | 128 | if (this.data.totalCount() < value.totalCount) { |
| 83 | this.curPageNum++ | 129 | this.curPageNum++ |
| 84 | - }else { | 130 | + } else { |
| 85 | this.hasMore = false | 131 | this.hasMore = false |
| 86 | } | 132 | } |
| 87 | } | 133 | } |
| 88 | this.isLoading = false | 134 | this.isLoading = false |
| 89 | - }).catch((err:Error)=>{ | ||
| 90 | - console.log(TAG,"请求失败") | 135 | + }).catch((err: Error) => { |
| 136 | + console.log(TAG, "请求失败") | ||
| 91 | this.isLoading = false | 137 | this.isLoading = false |
| 92 | }) | 138 | }) |
| 139 | + }else { | ||
| 140 | + this.isLoading = false | ||
| 141 | + } | ||
| 93 | } | 142 | } |
| 94 | - }else{ | ||
| 95 | - if(this.hasMore){ | ||
| 96 | - let object = new FollowListDetailRequestItem(this.creatorDirectoryId,20,this.curPageNum) | ||
| 97 | 143 | ||
| 98 | - MinePageDatasModel.getFollowListDetailData(object,getContext(this)).then((value)=>{ | ||
| 99 | - if (!this.data || value.list.length == 0){ | 144 | + getNewPageData() { |
| 145 | + //我的关注列表 | ||
| 146 | + if (this.creatorDirectoryId === -1) { | ||
| 147 | + this.getMyFollowListDetail() | ||
| 148 | + } else { | ||
| 149 | + if (this.hasMore) { | ||
| 150 | + let object = new FollowListDetailRequestItem(this.creatorDirectoryId, 20, this.curPageNum) | ||
| 151 | + | ||
| 152 | + MinePageDatasModel.getFollowListDetailData(object, getContext(this)).then((value) => { | ||
| 153 | + if (!this.data || value.list.length == 0) { | ||
| 100 | this.hasMore = false | 154 | this.hasMore = false |
| 101 | this.isLoading = false | 155 | this.isLoading = false |
| 102 | - }else{ | 156 | + } else { |
| 103 | this.getFollowListStatus(value) | 157 | this.getFollowListStatus(value) |
| 104 | } | 158 | } |
| 105 | - }).catch((err:Error)=>{ | ||
| 106 | - console.log(TAG,"请求失败") | 159 | + }).catch((err: Error) => { |
| 160 | + console.log(TAG, "请求失败") | ||
| 107 | this.isLoading = false | 161 | this.isLoading = false |
| 108 | }) | 162 | }) |
| 109 | } | 163 | } |
| 110 | } | 164 | } |
| 111 | } | 165 | } |
| 112 | 166 | ||
| 113 | - getFollowListStatus(result:MineFollowListDetailItem){ | ||
| 114 | - let data_temp : FollowListDetailItem[] = [] | ||
| 115 | - result.list.forEach((item)=>{ | ||
| 116 | - data_temp.push(new FollowListDetailItem(item.headPhotoUrl,item.cnUserName,item.cnFansNum,item.introduction,item.creatorId,"0",item.attentionUserId,item.cnUserType,item.cnUserId,item.cnMainControl,-1)) | 167 | + getFollowListStatus(result: MineFollowListDetailItem) { |
| 168 | + let data_temp: FollowListDetailItem[] = [] | ||
| 169 | + result.list.forEach((item) => { | ||
| 170 | + data_temp.push(new FollowListDetailItem(item.headPhotoUrl, item.cnUserName, item.cnFansNum, item.introduction, item.creatorId, "0", item.attentionUserId, item.cnUserType, item.cnUserId, item.cnMainControl, -1)) | ||
| 117 | }) | 171 | }) |
| 118 | let request = new CreatorDetailRequestItem() | 172 | let request = new CreatorDetailRequestItem() |
| 119 | 173 | ||
| 120 | - data_temp.forEach((data)=>{ | 174 | + data_temp.forEach((data) => { |
| 121 | request.creatorIdList.push(data.creatorId) | 175 | request.creatorIdList.push(data.creatorId) |
| 122 | }) | 176 | }) |
| 123 | - SearcherAboutDataModel.getCreatorDetailListData(request).then((value)=>{ | ||
| 124 | - if(value!=null && value.length>0){ | ||
| 125 | - data_temp.forEach((data)=>{ | ||
| 126 | - value.forEach((item)=>{ | ||
| 127 | - if(data.creatorId == item.creatorId){ | 177 | + SearcherAboutDataModel.getCreatorDetailListData(request).then((value) => { |
| 178 | + if (value != null && value.length > 0) { | ||
| 179 | + data_temp.forEach((data) => { | ||
| 180 | + value.forEach((item) => { | ||
| 181 | + if (data.creatorId == item.creatorId) { | ||
| 128 | data.headPhotoUrl = item.headPhotoUrl | 182 | data.headPhotoUrl = item.headPhotoUrl |
| 129 | - if(item.fansNum>10000){ | ||
| 130 | - let temp = (item.fansNum/10000)+"" | 183 | + if (item.fansNum > 10000) { |
| 184 | + let temp = (item.fansNum / 10000) + "" | ||
| 131 | let index = temp.indexOf('.') | 185 | let index = temp.indexOf('.') |
| 132 | - if(index != -1){ | ||
| 133 | - temp = temp.substring(0,index+2) | ||
| 134 | - }else{ | 186 | + if (index != -1) { |
| 187 | + temp = temp.substring(0, index + 2) | ||
| 188 | + } else { | ||
| 135 | temp = temp | 189 | temp = temp |
| 136 | } | 190 | } |
| 137 | data.cnFansNum = temp + "万" | 191 | data.cnFansNum = temp + "万" |
| 138 | - }else{ | 192 | + } else { |
| 139 | data.cnFansNum = item.fansNum + "" | 193 | data.cnFansNum = item.fansNum + "" |
| 140 | } | 194 | } |
| 141 | data.introduction = item.introduction | 195 | data.introduction = item.introduction |
| @@ -144,32 +198,32 @@ export struct FollowListDetailUI{ | @@ -144,32 +198,32 @@ export struct FollowListDetailUI{ | ||
| 144 | } | 198 | } |
| 145 | }) | 199 | }) |
| 146 | }) | 200 | }) |
| 147 | - this.getFollowStatus(data_temp,result.totalCount) | 201 | + this.getFollowStatus(data_temp, result.totalCount) |
| 148 | } | 202 | } |
| 149 | - }).catch((err:Error)=>{ | ||
| 150 | - console.log(TAG,JSON.stringify(err)) | 203 | + }).catch((err: Error) => { |
| 204 | + console.log(TAG, JSON.stringify(err)) | ||
| 151 | this.isLoading = false | 205 | this.isLoading = false |
| 152 | - this.count = this.count===-1?0:this.count | 206 | + this.count = this.count === -1 ? 0 : this.count |
| 153 | }) | 207 | }) |
| 154 | } | 208 | } |
| 155 | 209 | ||
| 156 | - getFollowStatus(result : FollowListDetailItem[],totalCount:number){ | 210 | + getFollowStatus(result: FollowListDetailItem[], totalCount: number) { |
| 157 | let status = new FollowListStatusRequestItem() | 211 | let status = new FollowListStatusRequestItem() |
| 158 | - result.forEach((item)=>{ | 212 | + result.forEach((item) => { |
| 159 | status.creatorIds.push(new QueryListIsFollowedItem(item.creatorId)) | 213 | status.creatorIds.push(new QueryListIsFollowedItem(item.creatorId)) |
| 160 | }) | 214 | }) |
| 161 | 215 | ||
| 162 | - MinePageDatasModel.getFollowListStatusData(status,getContext(this)).then((newValue)=>{ | ||
| 163 | - newValue.forEach((item)=>{ | ||
| 164 | - result.forEach((list)=>{ | 216 | + MinePageDatasModel.getFollowListStatusData(status, getContext(this)).then((newValue) => { |
| 217 | + newValue.forEach((item) => { | ||
| 218 | + result.forEach((list) => { | ||
| 165 | if (item.creatorId == list.creatorId) { | 219 | if (item.creatorId == list.creatorId) { |
| 166 | list.status = item.status | 220 | list.status = item.status |
| 167 | } | 221 | } |
| 168 | }) | 222 | }) |
| 169 | }) | 223 | }) |
| 170 | 224 | ||
| 171 | - result.forEach((item)=>{ | ||
| 172 | - this.data.push(new FollowListDetailItem(item.headPhotoUrl,item.cnUserName,item.cnFansNum,item.introduction,item.creatorId,item.status,item.attentionUserId,item.cnUserType,item.cnUserId,item.mainControl,item.banControl)) | 225 | + result.forEach((item) => { |
| 226 | + this.data.push(new FollowListDetailItem(item.headPhotoUrl, item.cnUserName, item.cnFansNum, item.introduction, item.creatorId, item.status, item.attentionUserId, item.cnUserType, item.cnUserId, item.mainControl, item.banControl)) | ||
| 173 | }) | 227 | }) |
| 174 | 228 | ||
| 175 | this.data.notifyDataReload() | 229 | this.data.notifyDataReload() |
| @@ -177,15 +231,14 @@ export struct FollowListDetailUI{ | @@ -177,15 +231,14 @@ export struct FollowListDetailUI{ | ||
| 177 | this.count = this.data.totalCount() | 231 | this.count = this.data.totalCount() |
| 178 | if (this.data.totalCount() < totalCount) { | 232 | if (this.data.totalCount() < totalCount) { |
| 179 | this.curPageNum++ | 233 | this.curPageNum++ |
| 180 | - }else { | 234 | + } else { |
| 181 | this.hasMore = false | 235 | this.hasMore = false |
| 182 | } | 236 | } |
| 183 | 237 | ||
| 184 | this.isLoading = false | 238 | this.isLoading = false |
| 185 | - }).catch((err:Error)=>{ | ||
| 186 | - console.log(TAG,"请求失败") | 239 | + }).catch((err: Error) => { |
| 240 | + console.log(TAG, "请求失败") | ||
| 187 | this.isLoading = false | 241 | this.isLoading = false |
| 188 | }) | 242 | }) |
| 189 | } | 243 | } |
| 190 | - | ||
| 191 | } | 244 | } |
| 1 | import { Params } from 'wdBean'; | 1 | import { Params } from 'wdBean'; |
| 2 | -import { DateTimeUtils, LazyDataSource,UserDataLocal } from 'wdKit'; | 2 | +import { DateTimeUtils, LazyDataSource, SPHelper,UserDataLocal } from 'wdKit'; |
| 3 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; | 3 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 4 | import MinePageDatasModel from '../../../model/MinePageDatasModel'; | 4 | import MinePageDatasModel from '../../../model/MinePageDatasModel'; |
| 5 | import { CommentListItem } from '../../../viewmodel/CommentListItem'; | 5 | import { CommentListItem } from '../../../viewmodel/CommentListItem'; |
| @@ -7,6 +7,7 @@ import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem'; | @@ -7,6 +7,7 @@ import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem'; | ||
| 7 | import { FollowListDetailRequestItem } from '../../../viewmodel/FollowListDetailRequestItem'; | 7 | import { FollowListDetailRequestItem } from '../../../viewmodel/FollowListDetailRequestItem'; |
| 8 | import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; | 8 | import { ListHasNoMoreDataUI } from '../../reusable/ListHasNoMoreDataUI'; |
| 9 | import { FollowChildComponent } from '../follow/FollowChildComponent'; | 9 | import { FollowChildComponent } from '../follow/FollowChildComponent'; |
| 10 | +import dataPreferences from '@ohos.data.preferences'; | ||
| 10 | 11 | ||
| 11 | const TAG = "HomePageBottomComponent" | 12 | const TAG = "HomePageBottomComponent" |
| 12 | @Component | 13 | @Component |
| @@ -21,9 +22,38 @@ export struct HomePageBottomComponent{ | @@ -21,9 +22,38 @@ export struct HomePageBottomComponent{ | ||
| 21 | @State isMineAccount:boolean = true; | 22 | @State isMineAccount:boolean = true; |
| 22 | @State userId:string = ""; | 23 | @State userId:string = ""; |
| 23 | @Link commentNum:number | 24 | @Link commentNum:number |
| 25 | + preferences: dataPreferences.Preferences | null = null; | ||
| 24 | 26 | ||
| 25 | aboutToAppear(){ | 27 | aboutToAppear(){ |
| 26 | this.getNewPageData() | 28 | this.getNewPageData() |
| 29 | + this.addFollowStatusObserver() | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + async addFollowStatusObserver() { | ||
| 33 | + this.preferences = await SPHelper.default.getPreferences(); | ||
| 34 | + let observer = (key: string) => { | ||
| 35 | + if (key == UserDataLocal.USER_FOLLOW_OPERATION) { | ||
| 36 | + let value = SPHelper.default.getSync(UserDataLocal.USER_FOLLOW_OPERATION,"") as string | ||
| 37 | + let arr = value.split(',') | ||
| 38 | + if(arr!=null && arr.length === 2){ | ||
| 39 | + this.data_follow.getDataArray().forEach((element,index) => { | ||
| 40 | + if (element.creatorId === arr[1]) { | ||
| 41 | + this.data_follow.deleteItem(index) | ||
| 42 | + } | ||
| 43 | + }); | ||
| 44 | + }else{ | ||
| 45 | + if(!this.isLoading){ | ||
| 46 | + this.isLoading = true | ||
| 47 | + this.hasMore = true | ||
| 48 | + this.curPageNum = 1 | ||
| 49 | + this.data_follow.clear() | ||
| 50 | + this.data_follow.notifyDataReload() | ||
| 51 | + this.getMyFollowListDetail() | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + this.preferences.on('change', observer); | ||
| 27 | } | 57 | } |
| 28 | 58 | ||
| 29 | build(){ | 59 | build(){ |
| @@ -175,10 +205,8 @@ export struct HomePageBottomComponent{ | @@ -175,10 +205,8 @@ export struct HomePageBottomComponent{ | ||
| 175 | .borderRadius(12) | 205 | .borderRadius(12) |
| 176 | } | 206 | } |
| 177 | 207 | ||
| 178 | - getNewPageData(){ | ||
| 179 | - this.isLoading = true | ||
| 180 | - //我的关注列表 | ||
| 181 | - if (this.style === 1){ | 208 | + |
| 209 | + getMyFollowListDetail(){ | ||
| 182 | if(this.hasMore){ | 210 | if(this.hasMore){ |
| 183 | let object = new FollowListDetailRequestItem(-1,20,this.curPageNum) | 211 | let object = new FollowListDetailRequestItem(-1,20,this.curPageNum) |
| 184 | 212 | ||
| @@ -187,7 +215,21 @@ export struct HomePageBottomComponent{ | @@ -187,7 +215,21 @@ export struct HomePageBottomComponent{ | ||
| 187 | this.hasMore = false | 215 | this.hasMore = false |
| 188 | }else{ | 216 | }else{ |
| 189 | value.list.forEach((value)=>{ | 217 | value.list.forEach((value)=>{ |
| 190 | - this.data_follow.push(new FollowListDetailItem(value.attentionHeadPhotoUrl,value.attentionUserName,value.fansNum+"",value.introduction,value.attentionCreatorId,"1",value.attentionUserId,value.attentionUserType,value.attentionUserId,value.mainControl,value.banControl)) | 218 | + let fansNum:number = value.fansNum |
| 219 | + let fansNumString = "" | ||
| 220 | + if (fansNum > 10000) { | ||
| 221 | + let temp = (fansNum / 10000) + "" | ||
| 222 | + let index = temp.indexOf('.') | ||
| 223 | + if (index != -1) { | ||
| 224 | + temp = temp.substring(0, index + 2) | ||
| 225 | + } else { | ||
| 226 | + temp = temp | ||
| 227 | + } | ||
| 228 | + fansNumString = temp + "万" | ||
| 229 | + } else { | ||
| 230 | + fansNumString = fansNum + "" | ||
| 231 | + } | ||
| 232 | + 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)) | ||
| 191 | }) | 233 | }) |
| 192 | this.data_follow.notifyDataReload() | 234 | this.data_follow.notifyDataReload() |
| 193 | this.count = this.data_follow.totalCount() | 235 | this.count = this.data_follow.totalCount() |
| @@ -202,7 +244,16 @@ export struct HomePageBottomComponent{ | @@ -202,7 +244,16 @@ export struct HomePageBottomComponent{ | ||
| 202 | console.log(TAG,"请求失败") | 244 | console.log(TAG,"请求失败") |
| 203 | this.isLoading = false | 245 | this.isLoading = false |
| 204 | }) | 246 | }) |
| 247 | + }else{ | ||
| 248 | + this.isLoading = false | ||
| 249 | + } | ||
| 205 | } | 250 | } |
| 251 | + | ||
| 252 | + getNewPageData(){ | ||
| 253 | + this.isLoading = true | ||
| 254 | + //我的关注列表 | ||
| 255 | + if (this.style === 1){ | ||
| 256 | + this.getMyFollowListDetail() | ||
| 206 | }else if(this.style === 0){ | 257 | }else if(this.style === 0){ |
| 207 | if(this.hasMore){ | 258 | if(this.hasMore){ |
| 208 | let time = encodeURI(DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) | 259 | let time = encodeURI(DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)) |
| @@ -230,6 +281,8 @@ export struct HomePageBottomComponent{ | @@ -230,6 +281,8 @@ export struct HomePageBottomComponent{ | ||
| 230 | console.log(TAG,"请求失败") | 281 | console.log(TAG,"请求失败") |
| 231 | this.isLoading = false | 282 | this.isLoading = false |
| 232 | }) | 283 | }) |
| 284 | + }else{ | ||
| 285 | + this.isLoading = false | ||
| 233 | } | 286 | } |
| 234 | } | 287 | } |
| 235 | } | 288 | } |
-
Please register or login to post a comment