Showing
2 changed files
with
84 additions
and
17 deletions
| @@ -8,11 +8,16 @@ import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh'; | @@ -8,11 +8,16 @@ import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh'; | ||
| 8 | import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData'; | 8 | import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData'; |
| 9 | import { EmptyComponent } from '../view/EmptyComponent'; | 9 | import { EmptyComponent } from '../view/EmptyComponent'; |
| 10 | import { ErrorComponent } from '../view/ErrorComponent'; | 10 | import { ErrorComponent } from '../view/ErrorComponent'; |
| 11 | -import LoadMoreLayout from '../page/LoadMoreLayout' | ||
| 12 | -import { LottieView } from '../../components/lottie/LottieView' | 11 | +import LoadMoreLayout from '../page/LoadMoreLayout'; |
| 12 | +import { LottieView } from '../../components/lottie/LottieView'; | ||
| 13 | +import dataPreferences from '@ohos.data.preferences'; | ||
| 14 | +import { BusinessError } from '@ohos.base'; | ||
| 13 | 15 | ||
| 14 | const TAG: string = 'LiveMorePage'; | 16 | const TAG: string = 'LiveMorePage'; |
| 15 | 17 | ||
| 18 | +const PREFERENCES_NAME = 'rmrLiveMorePage.db' | ||
| 19 | +let preferenceTheme: dataPreferences.Preferences | null = null | ||
| 20 | + | ||
| 16 | /** | 21 | /** |
| 17 | * 直播更多: | 22 | * 直播更多: |
| 18 | * type=1 直播 | 23 | * type=1 直播 |
| @@ -37,7 +42,13 @@ struct LiveMorePage { | @@ -37,7 +42,13 @@ struct LiveMorePage { | ||
| 37 | @State viewType: ViewType = ViewType.LOADING | 42 | @State viewType: ViewType = ViewType.LOADING |
| 38 | private scroller: Scroller = new Scroller() | 43 | private scroller: Scroller = new Scroller() |
| 39 | @State liveRoomList: LiveRoomDataBean[] = [] | 44 | @State liveRoomList: LiveRoomDataBean[] = [] |
| 40 | - aboutToAppear(): void { | 45 | + // 点击过的数据 |
| 46 | + @State clickDatas: Array<string> = [] | ||
| 47 | + | ||
| 48 | + async aboutToAppear() { | ||
| 49 | + await this.getPreferencesFromStorage() | ||
| 50 | + this.getLivMoreClickPreference() | ||
| 51 | + Logger.debug(TAG, '数据:' + JSON.stringify(this.clickDatas)) | ||
| 41 | this.currentPage = 1 | 52 | this.currentPage = 1 |
| 42 | this.getData() | 53 | this.getData() |
| 43 | } | 54 | } |
| @@ -93,10 +104,9 @@ struct LiveMorePage { | @@ -93,10 +104,9 @@ struct LiveMorePage { | ||
| 93 | LoadingLayout() { | 104 | LoadingLayout() { |
| 94 | } | 105 | } |
| 95 | 106 | ||
| 96 | - | ||
| 97 | @Builder | 107 | @Builder |
| 98 | ListLayout() { | 108 | ListLayout() { |
| 99 | - List({scroller: this.scroller}) { | 109 | + List({ scroller: this.scroller }) { |
| 100 | // 下拉刷新 | 110 | // 下拉刷新 |
| 101 | LazyForEach(this.data, (contentDTO: ContentDTO) => { | 111 | LazyForEach(this.data, (contentDTO: ContentDTO) => { |
| 102 | ListItem() { | 112 | ListItem() { |
| @@ -120,7 +130,7 @@ struct LiveMorePage { | @@ -120,7 +130,7 @@ struct LiveMorePage { | ||
| 120 | .height('calc(100% - 44vp)') | 130 | .height('calc(100% - 44vp)') |
| 121 | .onReachEnd(() => { | 131 | .onReachEnd(() => { |
| 122 | Logger.debug(TAG, "触底了"); | 132 | Logger.debug(TAG, "触底了"); |
| 123 | - if(!this.isLoading && this.hasMore){ | 133 | + if (!this.isLoading && this.hasMore) { |
| 124 | //加载分页数据 | 134 | //加载分页数据 |
| 125 | this.currentPage++; | 135 | this.currentPage++; |
| 126 | this.getData() | 136 | this.getData() |
| @@ -137,11 +147,12 @@ struct LiveMorePage { | @@ -137,11 +147,12 @@ struct LiveMorePage { | ||
| 137 | buildItem(item: ContentDTO) { | 147 | buildItem(item: ContentDTO) { |
| 138 | Column() { | 148 | Column() { |
| 139 | Text(item.newsTitle) | 149 | Text(item.newsTitle) |
| 140 | - .fontSize(17) | 150 | + .fontSize(18) |
| 141 | .maxLines(2) | 151 | .maxLines(2) |
| 142 | .textOverflow({ overflow: TextOverflow.Ellipsis }) | 152 | .textOverflow({ overflow: TextOverflow.Ellipsis }) |
| 143 | .margin({ top: 16, bottom: 8 }) | 153 | .margin({ top: 16, bottom: 8 }) |
| 144 | .alignSelf(ItemAlign.Start) | 154 | .alignSelf(ItemAlign.Start) |
| 155 | + .fontColor(this.isClicked(item.objectId) ? $r('app.color.color_848484') : $r('app.color.color_222222')) | ||
| 145 | Stack() { | 156 | Stack() { |
| 146 | if (item.fullColumnImgUrls && item.fullColumnImgUrls.length > 0) { | 157 | if (item.fullColumnImgUrls && item.fullColumnImgUrls.length > 0) { |
| 147 | Image(item.fullColumnImgUrls[0].url) | 158 | Image(item.fullColumnImgUrls[0].url) |
| @@ -191,6 +202,7 @@ struct LiveMorePage { | @@ -191,6 +202,7 @@ struct LiveMorePage { | ||
| 191 | } | 202 | } |
| 192 | .width('100%') | 203 | .width('100%') |
| 193 | .onClick(() => { | 204 | .onClick(() => { |
| 205 | + this.clickRowBuildItem(item) | ||
| 194 | ProcessUtils.processPage(item) | 206 | ProcessUtils.processPage(item) |
| 195 | }) | 207 | }) |
| 196 | } | 208 | } |
| @@ -292,14 +304,14 @@ struct LiveMorePage { | @@ -292,14 +304,14 @@ struct LiveMorePage { | ||
| 292 | } | 304 | } |
| 293 | this.data.push(...liveReviewDTO.list) | 305 | this.data.push(...liveReviewDTO.list) |
| 294 | this.getLiveRoomDataInfo(liveReviewDTO.list) | 306 | this.getLiveRoomDataInfo(liveReviewDTO.list) |
| 295 | - } else { | 307 | + } else { |
| 296 | this.hasMore = false; | 308 | this.hasMore = false; |
| 297 | } | 309 | } |
| 298 | this.resolveEnd(true, resolve) | 310 | this.resolveEnd(true, resolve) |
| 299 | if (liveReviewDTO.list.length == 0 && this.currentPage == 1) { | 311 | if (liveReviewDTO.list.length == 0 && this.currentPage == 1) { |
| 300 | this.viewType = ViewType.EMPTY | 312 | this.viewType = ViewType.EMPTY |
| 301 | } | 313 | } |
| 302 | - }catch (exception) { | 314 | + } catch (exception) { |
| 303 | this.resolveEnd(false, resolve) | 315 | this.resolveEnd(false, resolve) |
| 304 | } | 316 | } |
| 305 | // PageViewModel.getLiveMoreUrl(this.type, this.currentPage, this.pageSize).then(async (liveReviewDTO) => { | 317 | // PageViewModel.getLiveMoreUrl(this.type, this.currentPage, this.pageSize).then(async (liveReviewDTO) => { |
| @@ -315,7 +327,7 @@ struct LiveMorePage { | @@ -315,7 +327,7 @@ struct LiveMorePage { | ||
| 315 | if (resolve) { | 327 | if (resolve) { |
| 316 | if (this.currentPage == 1 && isTop) { | 328 | if (this.currentPage == 1 && isTop) { |
| 317 | resolve('已更新至最新') | 329 | resolve('已更新至最新') |
| 318 | - }else { | 330 | + } else { |
| 319 | resolve('') | 331 | resolve('') |
| 320 | } | 332 | } |
| 321 | } | 333 | } |
| @@ -334,23 +346,24 @@ struct LiveMorePage { | @@ -334,23 +346,24 @@ struct LiveMorePage { | ||
| 334 | }); | 346 | }); |
| 335 | return idList.join(',') | 347 | return idList.join(',') |
| 336 | } | 348 | } |
| 349 | + | ||
| 337 | // 获取评论数 | 350 | // 获取评论数 |
| 338 | async getLiveRoomDataInfo(list: ContentDTO[]) { | 351 | async getLiveRoomDataInfo(list: ContentDTO[]) { |
| 339 | const reserveIds = this.getLiveDetailIds(list) | 352 | const reserveIds = this.getLiveDetailIds(list) |
| 340 | - Logger.debug(TAG,'是否预约数据:' +` ${reserveIds}`) | 353 | + Logger.debug(TAG, '是否预约数据:' + ` ${reserveIds}`) |
| 341 | PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => { | 354 | PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => { |
| 342 | - Logger.debug(TAG,'是否预约数据:' +` ${JSON.stringify(result)}`) | 355 | + Logger.debug(TAG, '是否预约数据:' + ` ${JSON.stringify(result)}`) |
| 343 | if (result && result.length > 0) { | 356 | if (result && result.length > 0) { |
| 344 | this.liveRoomList.push(...result) | 357 | this.liveRoomList.push(...result) |
| 345 | this.data.reloadData() | 358 | this.data.reloadData() |
| 346 | } | 359 | } |
| 347 | - }).catch(() =>{ | 360 | + }).catch(() => { |
| 348 | // this.data.push(...list) | 361 | // this.data.push(...list) |
| 349 | }) | 362 | }) |
| 350 | } | 363 | } |
| 351 | 364 | ||
| 352 | // 判断是否预约 | 365 | // 判断是否预约 |
| 353 | - getLiveRoomNumber(item: ContentDTO): string { | 366 | + getLiveRoomNumber(item: ContentDTO): string { |
| 354 | const objc = this.liveRoomList.find((element: LiveRoomDataBean) => { | 367 | const objc = this.liveRoomList.find((element: LiveRoomDataBean) => { |
| 355 | return element.liveId.toString() == item.objectId | 368 | return element.liveId.toString() == item.objectId |
| 356 | }) | 369 | }) |
| @@ -362,14 +375,64 @@ struct LiveMorePage { | @@ -362,14 +375,64 @@ struct LiveMorePage { | ||
| 362 | 375 | ||
| 363 | private computeShowNum(count: number): string { | 376 | private computeShowNum(count: number): string { |
| 364 | if (count >= 10000) { | 377 | if (count >= 10000) { |
| 365 | - let num = ( count / 10000).toFixed(1) | ||
| 366 | - if (Number(num.substring(num.length-1)) == 0) { | ||
| 367 | - num = num.substring(0, num.length-2) | 378 | + let num = (count / 10000).toFixed(1) |
| 379 | + if (Number(num.substring(num.length - 1)) == 0) { | ||
| 380 | + num = num.substring(0, num.length - 2) | ||
| 368 | } | 381 | } |
| 369 | return num + '万人参加' | 382 | return num + '万人参加' |
| 370 | } | 383 | } |
| 371 | return `${count}人参加` | 384 | return `${count}人参加` |
| 372 | } | 385 | } |
| 373 | 386 | ||
| 387 | + isClicked(objectId: string) { | ||
| 388 | + return this.clickDatas.includes(objectId) | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + clickRowBuildItem(item: ContentDTO) { | ||
| 392 | + if (item.objectId && !this.clickDatas.includes(item.objectId)) { | ||
| 393 | + Logger.debug(TAG, '数据:' + JSON.stringify(this.clickDatas)) | ||
| 394 | + this.clickDatas.push(item.objectId.toString()) | ||
| 395 | + this.putLiveMoreClickPreference() | ||
| 396 | + } | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + async getPreferencesFromStorage() { | ||
| 400 | + let context = getContext(this) as Context | ||
| 401 | + preferenceTheme = await dataPreferences.getPreferences(context, PREFERENCES_NAME) | ||
| 402 | + } | ||
| 374 | 403 | ||
| 404 | + putLiveMoreClickPreference() { | ||
| 405 | + Logger.info(TAG, `Put begin` + JSON.stringify(this.clickDatas)) | ||
| 406 | + if (preferenceTheme !== null && this.clickDatas.length > 0) { | ||
| 407 | + // await | ||
| 408 | + const arr: Array<string> = [] | ||
| 409 | + arr.push(...this.clickDatas) | ||
| 410 | + preferenceTheme.put('liveMorePage', arr).then(() => { | ||
| 411 | + Logger.debug(TAG,"Succeeded in putting value of 'startup'."); | ||
| 412 | + }).catch((err: BusinessError) => { | ||
| 413 | + Logger.debug(TAG, "Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message); | ||
| 414 | + }) | ||
| 415 | + // await preferenceTheme.flush() | ||
| 416 | + preferenceTheme.flush((err: BusinessError) => { | ||
| 417 | + if (err) { | ||
| 418 | + Logger.debug(TAG, "Failed to flush. code =" + err.code + ", message =" + err.message); | ||
| 419 | + return; | ||
| 420 | + } | ||
| 421 | + }) | ||
| 422 | + | ||
| 423 | + } | ||
| 424 | + } | ||
| 425 | + | ||
| 426 | + getLivMoreClickPreference() { | ||
| 427 | + Logger.info(TAG, `Get begin`) | ||
| 428 | + if (preferenceTheme !== null) { | ||
| 429 | + preferenceTheme.get('liveMorePage', []).then((data: dataPreferences.ValueType) => { | ||
| 430 | + if (data instanceof Array) { | ||
| 431 | + this.clickDatas = data as Array<string> | ||
| 432 | + } | ||
| 433 | + }).catch((err: BusinessError) => { | ||
| 434 | + console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); | ||
| 435 | + }) | ||
| 436 | + } | ||
| 437 | + } | ||
| 375 | } | 438 | } |
-
Please register or login to post a comment