feat:
1)搭建普通信息流模板组件,可支持不用业务接口实现通用组件和稿件展示业务数据; 2)直播列表页面改造成使用通用模板组件
Showing
14 changed files
with
728 additions
and
458 deletions
| @@ -84,4 +84,9 @@ export const enum CompStyle { | @@ -84,4 +84,9 @@ export const enum CompStyle { | ||
| 84 | Card_Comp_Adv = 'card_comp_adv', // 信息流广告稿件 | 84 | Card_Comp_Adv = 'card_comp_adv', // 信息流广告稿件 |
| 85 | 85 | ||
| 86 | Card_Comp_Zh_Grid_Layout_02 = 'Card_Comp_Zh_Grid_Layout-02', // 一行两列卡业务内容 | 86 | Card_Comp_Zh_Grid_Layout_02 = 'Card_Comp_Zh_Grid_Layout-02', // 一行两列卡业务内容 |
| 87 | + | ||
| 88 | + Card_Comp_Live_Big_Image_01 = 'card_comp_live_sub_big_image_01', // 直播预约大图卡 | ||
| 89 | + | ||
| 90 | + Card_Comp_Live_Big_Image_02 = 'card_comp_live_sub_big_image_02' // 直播大图卡 | ||
| 91 | + | ||
| 87 | } | 92 | } |
| @@ -18,6 +18,7 @@ import { Card21Component } from './cardview/Card21Component'; | @@ -18,6 +18,7 @@ import { Card21Component } from './cardview/Card21Component'; | ||
| 18 | import { SearchContentComponent } from './cardview/SearchContentComponent'; | 18 | import { SearchContentComponent } from './cardview/SearchContentComponent'; |
| 19 | import { DateTimeUtils } from 'wdKit/Index'; | 19 | import { DateTimeUtils } from 'wdKit/Index'; |
| 20 | import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index'; | 20 | import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index'; |
| 21 | +import { LiveBigImage02Component } from './cardview/LiveBigImage02Component'; | ||
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | * card适配器,卡片样式汇总,依据ContentDTO#appStyle | 24 | * card适配器,卡片样式汇总,依据ContentDTO#appStyle |
| @@ -89,7 +90,9 @@ export struct CardParser { | @@ -89,7 +90,9 @@ export struct CardParser { | ||
| 89 | Card20Component({ contentDTO, compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }) | 90 | Card20Component({ contentDTO, compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }) |
| 90 | } else if (contentDTO.appStyle === CompStyle.Card_21) { | 91 | } else if (contentDTO.appStyle === CompStyle.Card_21) { |
| 91 | Card21Component({ contentDTO, compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }) | 92 | Card21Component({ contentDTO, compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }) |
| 92 | - } else { | 93 | + } else if (contentDTO.appStyle === CompStyle.Card_Comp_Live_Big_Image_02) { |
| 94 | + LiveBigImage02Component({ contentDTO:contentDTO, compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }) | ||
| 95 | + }else { | ||
| 93 | // todo:组件未实现 / Component Not Implemented | 96 | // todo:组件未实现 / Component Not Implemented |
| 94 | // Text(contentDTO.appStyle) | 97 | // Text(contentDTO.appStyle) |
| 95 | // .width(CommonConstants.FULL_PARENT) | 98 | // .width(CommonConstants.FULL_PARENT) |
| @@ -79,8 +79,6 @@ export struct CompParser { | @@ -79,8 +79,6 @@ export struct CompParser { | ||
| 79 | @Builder | 79 | @Builder |
| 80 | componentBuilder() { | 80 | componentBuilder() { |
| 81 | 81 | ||
| 82 | - //CardParser({ contentDTO: this.compDTO.operDataList[0], compDTO:this.compDTO }) | ||
| 83 | - | ||
| 84 | if (this.compDTO.operDataList[0]?.objectType !== '3' && | 82 | if (this.compDTO.operDataList[0]?.objectType !== '3' && |
| 85 | this.compDTO.operDataList[0]?.objectType !== '13') { //暂时屏蔽活动和音频详情入口 | 83 | this.compDTO.operDataList[0]?.objectType !== '13') { //暂时屏蔽活动和音频详情入口 |
| 86 | if (this.compDTO.compStyle === CompStyle.Label_03) { | 84 | if (this.compDTO.compStyle === CompStyle.Label_03) { |
| @@ -171,7 +169,7 @@ export struct CompParser { | @@ -171,7 +169,7 @@ export struct CompParser { | ||
| 171 | AdvCardParser({ pageModel: this.pageModel, compDTO: this.compDTO }) | 169 | AdvCardParser({ pageModel: this.pageModel, compDTO: this.compDTO }) |
| 172 | //Text(`compIndex = ${compIndex}`).width('100%').fontSize('12fp').fontColor(Color.Red).padding({ left: 0, right: 0 }) | 170 | //Text(`compIndex = ${compIndex}`).width('100%').fontSize('12fp').fontColor(Color.Red).padding({ left: 0, right: 0 }) |
| 173 | Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 }) | 171 | Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 }) |
| 174 | - } else if (!Number.isNaN(Number(this.compDTO.compStyle))) { | 172 | + } else if (!Number.isNaN(Number(this.compDTO.compStyle)) || this.compDTO.compType === 'appStyle') { |
| 175 | CardParser({ contentDTO: this.compDTO.operDataList[0], compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }); | 173 | CardParser({ contentDTO: this.compDTO.operDataList[0], compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName }); |
| 176 | Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 }) | 174 | Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 }) |
| 177 | } else { | 175 | } else { |
sight_harmony/features/wdComponent/src/main/ets/components/cardview/LiveBigImage02Component.ets
0 → 100644
| 1 | +import { CompDTO, ContentDTO } from 'wdBean'; | ||
| 2 | +import { ProcessUtils } from 'wdRouter'; | ||
| 3 | +import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; | ||
| 4 | +import { hasClicked, persistentStorage } from '../../utils/persistentStorage'; | ||
| 5 | +import { SearchShowRed, textItem, titleInitRes } from '../../utils/searchShowRed'; | ||
| 6 | +import { DateTimeUtils } from 'wdKit/Index'; | ||
| 7 | +import { LottieView } from '../lottie/LottieView'; | ||
| 8 | +import { router } from '@kit.ArkUI'; | ||
| 9 | + | ||
| 10 | +const TAG: string = 'Card6Component-Card13Component'; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 本地样式卡:直播大图卡 | ||
| 14 | + */ | ||
| 15 | +@Component | ||
| 16 | +export struct LiveBigImage02Component { | ||
| 17 | + @ObjectLink compDTO: CompDTO | ||
| 18 | + @State pageId: string = ''; | ||
| 19 | + @State pageName: string = ''; | ||
| 20 | + @State contentDTO: ContentDTO = new ContentDTO(); | ||
| 21 | + @State loadImg: boolean = false; | ||
| 22 | + @State clicked: boolean = false; | ||
| 23 | + | ||
| 24 | + async aboutToAppear() { | ||
| 25 | + const curRouter = router.getState().name; | ||
| 26 | + this.clicked = hasClicked(this.contentDTO.objectId,curRouter) | ||
| 27 | + this.loadImg = await onlyWifiLoadImg(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + build() { | ||
| 32 | + Column() { | ||
| 33 | + Text(this.contentDTO.newsTitle) | ||
| 34 | + .fontSize(18) | ||
| 35 | + .maxLines(2) | ||
| 36 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 37 | + .margin({ top: 16, bottom: 8 }) | ||
| 38 | + .alignSelf(ItemAlign.Start) | ||
| 39 | + .fontColor(this.clicked ? 0x848484 : $r('app.color.color_222222')) | ||
| 40 | + | ||
| 41 | + Stack() { | ||
| 42 | + if (this.contentDTO.fullColumnImgUrls && this.contentDTO.fullColumnImgUrls.length > 0) { | ||
| 43 | + Image(this.contentDTO.fullColumnImgUrls[0].url)// | ||
| 44 | + .backgroundColor(this.loadImg ? $r('app.color.color_B0B0B0') : 0xf5f5f5) | ||
| 45 | + .width('100%') | ||
| 46 | + .aspectRatio(16 / 9) | ||
| 47 | + .borderRadius(4) | ||
| 48 | + .borderWidth(0.5) | ||
| 49 | + .borderColor($r('app.color.color_0D000000')) | ||
| 50 | + } | ||
| 51 | + this.LiveImage(this.contentDTO) | ||
| 52 | + } | ||
| 53 | + .alignContent(Alignment.BottomEnd) | ||
| 54 | + | ||
| 55 | + Row() { | ||
| 56 | + if (this.contentDTO.rmhInfo && this.contentDTO.rmhInfo.rmhName) { | ||
| 57 | + Text(this.contentDTO.rmhInfo.rmhName) | ||
| 58 | + .fontSize(12) | ||
| 59 | + .fontWeight(400) | ||
| 60 | + .fontColor($r('app.color.color_B0B0B0')) | ||
| 61 | + .fontFamily('PingFang SC-Medium') | ||
| 62 | + .maxLines(1) | ||
| 63 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 64 | + .align(Alignment.Start) | ||
| 65 | + | ||
| 66 | + Image($r('app.media.point_live_icon')) | ||
| 67 | + .objectFit(ImageFit.Auto) | ||
| 68 | + .interpolation(ImageInterpolation.High) | ||
| 69 | + .width(16) | ||
| 70 | + .height(16) | ||
| 71 | + .margin(2) | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTimestamp))) | ||
| 75 | + .fontSize(12) | ||
| 76 | + .maxLines(1) | ||
| 77 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 78 | + .align(Alignment.Start) | ||
| 79 | + .width('100%') | ||
| 80 | + .fontColor($r('app.color.color_B0B0B0')) | ||
| 81 | + } | ||
| 82 | + .margin({ top: 8, bottom: 8 }) | ||
| 83 | + | ||
| 84 | + } | ||
| 85 | + .width('100%') | ||
| 86 | + .padding({ | ||
| 87 | + left: $r('app.float.card_comp_pagePadding_lf'), | ||
| 88 | + right: $r('app.float.card_comp_pagePadding_lf'), | ||
| 89 | + }) | ||
| 90 | + .onClick(() => { | ||
| 91 | + this.clicked = true; | ||
| 92 | + persistentStorage(this.contentDTO.objectId); | ||
| 93 | + ProcessUtils.processPage(this.contentDTO) | ||
| 94 | + }) | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Builder | ||
| 98 | + LiveImage(item: ContentDTO) { | ||
| 99 | + Row() { | ||
| 100 | + LottieView({ | ||
| 101 | + name: 'live_status_wait', | ||
| 102 | + path: "lottie/live_detail_living.json", | ||
| 103 | + lottieWidth: 14, | ||
| 104 | + lottieHeight: 14, | ||
| 105 | + autoplay: true, | ||
| 106 | + loop: true, | ||
| 107 | + title: item.newsTitle | ||
| 108 | + }) | ||
| 109 | + .margin({ | ||
| 110 | + right: '2vp' | ||
| 111 | + }) | ||
| 112 | + | ||
| 113 | + Text('直播中') | ||
| 114 | + .fontSize('12vp') | ||
| 115 | + .fontWeight(400) | ||
| 116 | + .fontColor(Color.White) | ||
| 117 | + .textShadow({ | ||
| 118 | + radius: 2, | ||
| 119 | + color: 'rgba(0,0,0,0.3)', | ||
| 120 | + offsetX: 0, | ||
| 121 | + offsetY: 2 | ||
| 122 | + }) | ||
| 123 | + .margin({ | ||
| 124 | + right: '5vp' | ||
| 125 | + }) | ||
| 126 | + | ||
| 127 | + Image($r('app.media.icon_comp_line_live')).height('11vp').width('1.5vp') | ||
| 128 | + | ||
| 129 | + if (this.getLiveRoomNumber(this.compDTO.operDataList[0]).length > 0) { | ||
| 130 | + Text(this.getLiveRoomNumber(this.compDTO.operDataList[0])) | ||
| 131 | + .fontSize('12vp') | ||
| 132 | + .fontWeight(400) | ||
| 133 | + .textShadow({ | ||
| 134 | + radius: 2, | ||
| 135 | + color: 'rgba(0,0,0,0.3)', | ||
| 136 | + offsetX: 0, | ||
| 137 | + offsetY: 2 | ||
| 138 | + }) | ||
| 139 | + .fontColor(Color.White) | ||
| 140 | + .margin({ | ||
| 141 | + left: '5vp' | ||
| 142 | + }) | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + } | ||
| 146 | + .justifyContent(FlexAlign.End) | ||
| 147 | + .margin({ right: 8, bottom: 8 }) | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + // 判断是否预约 | ||
| 151 | + getLiveRoomNumber(item: ContentDTO): string { | ||
| 152 | + const objc = item.liveRoomDataBean | ||
| 153 | + if (objc && objc.pv && objc.pv > 0) { | ||
| 154 | + return this.computeShowNum(objc.pv) | ||
| 155 | + } | ||
| 156 | + return '' | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + private computeShowNum(count: number): string { | ||
| 160 | + if (count >= 10000) { | ||
| 161 | + let num = (count / 10000).toFixed(1) | ||
| 162 | + if (Number(num.substring(num.length - 1)) == 0) { | ||
| 163 | + num = num.substring(0, num.length - 2) | ||
| 164 | + } | ||
| 165 | + return num + '万人参加' | ||
| 166 | + } | ||
| 167 | + return `${count}人参加` | ||
| 168 | + } | ||
| 169 | +} |
| 1 | +import { router } from '@kit.ArkUI' | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 常见的标题 | ||
| 5 | + */ | ||
| 6 | +@Component | ||
| 7 | +export default struct CommonPageTitle { | ||
| 8 | + | ||
| 9 | + // 标题名称 | ||
| 10 | + @State title:string = '' | ||
| 11 | + | ||
| 12 | + build() { | ||
| 13 | + | ||
| 14 | + RelativeContainer() { | ||
| 15 | + //标题栏目 | ||
| 16 | + Image($r('app.media.icon_arrow_left')) | ||
| 17 | + .width(24) | ||
| 18 | + .height(24) | ||
| 19 | + .objectFit(ImageFit.Auto) | ||
| 20 | + .id("back_icon") | ||
| 21 | + .alignRules({ | ||
| 22 | + center: { anchor: "__container__", align: VerticalAlign.Center }, | ||
| 23 | + left: { anchor: "__container__", align: HorizontalAlign.Start } | ||
| 24 | + }) | ||
| 25 | + .onClick(() => { | ||
| 26 | + router.back() | ||
| 27 | + }) | ||
| 28 | + | ||
| 29 | + Text(this.title) | ||
| 30 | + .maxLines(1) | ||
| 31 | + .id("title") | ||
| 32 | + .fontSize('18vp') | ||
| 33 | + .fontWeight(400) | ||
| 34 | + .fontColor($r('app.color.color_222222')) | ||
| 35 | + .lineHeight('22vp') | ||
| 36 | + .alignRules({ | ||
| 37 | + center: { anchor: "__container__", align: VerticalAlign.Center }, | ||
| 38 | + middle: { anchor: "__container__", align: HorizontalAlign.Center } | ||
| 39 | + }) | ||
| 40 | + } | ||
| 41 | + .height(44) | ||
| 42 | + .padding({ | ||
| 43 | + left: $r('app.float.card_comp_pagePadding_lf'), | ||
| 44 | + right: $r('app.float.card_comp_pagePadding_lf'), | ||
| 45 | + }) | ||
| 46 | + .width('100%') | ||
| 47 | + } | ||
| 48 | +} |
| 1 | -import { ContentDTO, LiveRoomDataBean } from 'wdBean'; | ||
| 2 | -import { ProcessUtils } from 'wdRouter'; | ||
| 3 | -import PageViewModel from '../../viewmodel/PageViewModel'; | ||
| 4 | -import { DateTimeUtils, LazyDataSource, Logger, NetworkUtil } from 'wdKit/Index'; | ||
| 5 | -import { router } from '@kit.ArkUI'; | ||
| 6 | -import { ViewType } from 'wdConstant/src/main/ets/enum/ViewType'; | ||
| 7 | -import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh'; | ||
| 8 | -import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData'; | ||
| 9 | -import { EmptyComponent, WDViewDefaultType } from '../view/EmptyComponent'; | ||
| 10 | -import { ErrorComponent } from '../view/ErrorComponent'; | ||
| 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'; | ||
| 15 | -import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; | ||
| 16 | -import { channelSkeleton } from '../skeleton/channelSkeleton'; | 1 | +import CommonPageTitle from './CommonPageTitle'; |
| 2 | +import TemplatePageComponent from './template/TemplatePageComponent'; | ||
| 3 | +import { TemplatePageConstant } from './template/TemplatePageConstant'; | ||
| 17 | 4 | ||
| 18 | -const TAG: string = 'LiveMorePage'; | ||
| 19 | - | ||
| 20 | -const PREFERENCES_NAME = 'rmrLiveMorePage.db' | ||
| 21 | -let preferenceTheme: dataPreferences.Preferences | null = null | ||
| 22 | 5 | ||
| 23 | /** | 6 | /** |
| 24 | - * 直播更多: | ||
| 25 | - * type=1 直播 | ||
| 26 | - * type=2 预约 | ||
| 27 | - * 卡片结构:上下结构 | ||
| 28 | - * 卡片宽度:充满父窗口 | ||
| 29 | - * 卡片高度,仅包含横板图片:图片高度由图片的宽度及宽高比决定,图片宽度占父窗口'100%',宽高比为16:9: | 7 | + * 直播列表 |
| 30 | */ | 8 | */ |
| 31 | @Entry | 9 | @Entry |
| 32 | @Component | 10 | @Component |
| 33 | struct LiveMorePage { | 11 | struct LiveMorePage { |
| 34 | - @State data: LazyDataSource<ContentDTO> = new LazyDataSource(); | 12 | + |
| 35 | @State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number; | 13 | @State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number; |
| 14 | + | ||
| 36 | @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 | 15 | @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 |
| 37 | - type: number = 1; | ||
| 38 | - pageSize: number = 20; | ||
| 39 | - operDataList: ContentDTO[] = []; | ||
| 40 | - title: string = '直播列表' | ||
| 41 | - @State contentDTO: ContentDTO = new ContentDTO(); | ||
| 42 | - @State private hasMore: boolean = true | ||
| 43 | - @State private currentPage: number = 1 | ||
| 44 | - @State private isLoading: boolean = false | ||
| 45 | - private scroller: Scroller = new Scroller() | ||
| 46 | - @State liveRoomList: LiveRoomDataBean[] = [] | ||
| 47 | - // 点击过的数据 | ||
| 48 | - @State clickDatas: Array<string> = [] | ||
| 49 | - @State loadImg: boolean = false; | ||
| 50 | - @State viewType: ViewType = ViewType.LOADING | ||
| 51 | - emptyType: WDViewDefaultType = WDViewDefaultType.WDViewDefaultType_Default | ||
| 52 | 16 | ||
| 53 | - async aboutToAppear(): Promise<void> { | ||
| 54 | - await this.getPreferencesFromStorage() | ||
| 55 | - this.loadImg = await onlyWifiLoadImg(); | ||
| 56 | - this.getLivMoreClickPreference() | ||
| 57 | - Logger.debug(TAG, '数据:' + JSON.stringify(this.clickDatas)) | ||
| 58 | - this.currentPage = 1 | ||
| 59 | - this.getData() | ||
| 60 | - } | 17 | + title: string = '直播列表' |
| 61 | 18 | ||
| 62 | build() { | 19 | build() { |
| 63 | 20 | ||
| 64 | Column() { | 21 | Column() { |
| 65 | - this.TabbarNormal() | ||
| 66 | - if (this.viewType == ViewType.LOADING) { | ||
| 67 | - this.LoadingLayout() | ||
| 68 | - } else if (this.viewType == ViewType.EMPTY || this.viewType == ViewType.ERROR) { | ||
| 69 | - EmptyComponent({ | ||
| 70 | - emptyType: this.emptyType, | ||
| 71 | - emptyButton: true, | ||
| 72 | - retry: () => { | ||
| 73 | - this.getData() | ||
| 74 | - } | ||
| 75 | - }) | ||
| 76 | - } else { | ||
| 77 | - CustomPullToRefresh({ | ||
| 78 | - alldata: this.data, | ||
| 79 | - scroller: this.scroller, | ||
| 80 | - hasMore: false, | ||
| 81 | - customList: () => { | ||
| 82 | - this.ListLayout() | ||
| 83 | - }, | ||
| 84 | - onRefresh: (resolve) => { | ||
| 85 | - this.currentPage = 1 | ||
| 86 | - this.getData(resolve) | ||
| 87 | - }, | ||
| 88 | - }) | ||
| 89 | - } | 22 | + |
| 23 | + //常见标题 | ||
| 24 | + CommonPageTitle({ title: this.title }) | ||
| 25 | + // 通用模板组件 | ||
| 26 | + TemplatePageComponent({ pageDataSourceType: TemplatePageConstant.LIVE_HORIZONTAL_CARD }) | ||
| 27 | + | ||
| 90 | } | 28 | } |
| 91 | .height('100%') | 29 | .height('100%') |
| 30 | + .backgroundColor(Color.White) | ||
| 92 | .padding({ | 31 | .padding({ |
| 93 | - left: $r('app.float.card_comp_pagePadding_lf'), | ||
| 94 | - right: $r('app.float.card_comp_pagePadding_lf'), | ||
| 95 | top: px2vp(this.topSafeHeight), | 32 | top: px2vp(this.topSafeHeight), |
| 96 | bottom: px2vp(this.bottomSafeHeight) | 33 | bottom: px2vp(this.bottomSafeHeight) |
| 97 | }) | 34 | }) |
| 98 | 35 | ||
| 99 | } | 36 | } |
| 100 | - | ||
| 101 | - @Builder | ||
| 102 | - LoadingLayout() { | ||
| 103 | - channelSkeleton() | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - @Builder | ||
| 107 | - ListLayout() { | ||
| 108 | - List({ scroller: this.scroller }) { | ||
| 109 | - // 下拉刷新 | ||
| 110 | - LazyForEach(this.data, (contentDTO: ContentDTO) => { | ||
| 111 | - ListItem() { | ||
| 112 | - this.buildItem(contentDTO) | ||
| 113 | - } | ||
| 114 | - }, | ||
| 115 | - (contentDTO: ContentDTO, contentIndex: number) => contentDTO.pageId + contentIndex.toString() | ||
| 116 | - ) | ||
| 117 | - // 加载更多 | ||
| 118 | - ListItem() { | ||
| 119 | - if (this.hasMore && this.data && this.data.totalCount() > 0) { | ||
| 120 | - LoadMoreLayout({ isVisible: this.hasMore }) | ||
| 121 | - } else if (!this.hasMore && !this.isLoading) { | ||
| 122 | - PeopleShipNoMoreData() | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - .scrollBar(BarState.Off) | ||
| 127 | - .edgeEffect(EdgeEffect.None) | ||
| 128 | - .cachedCount(3) | ||
| 129 | - .height('calc(100% - 44vp)') | ||
| 130 | - .onReachEnd(() => { | ||
| 131 | - Logger.debug(TAG, "触底了"); | ||
| 132 | - if (!this.isLoading && this.hasMore) { | ||
| 133 | - //加载分页数据 | ||
| 134 | - this.currentPage++; | ||
| 135 | - this.getData() | ||
| 136 | - } | ||
| 137 | - }) | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - /** | ||
| 141 | - * 组件项 | ||
| 142 | - * | ||
| 143 | - * @param programmeBean item 组件项, 上面icon,下面标题 | ||
| 144 | - */ | ||
| 145 | - @Builder | ||
| 146 | - buildItem(item: ContentDTO) { | ||
| 147 | - Column() { | ||
| 148 | - Text(item.newsTitle) | ||
| 149 | - .fontSize(18) | ||
| 150 | - .maxLines(2) | ||
| 151 | - .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 152 | - .margin({ top: 16, bottom: 8 }) | ||
| 153 | - .alignSelf(ItemAlign.Start) | ||
| 154 | - .fontColor(this.isClicked(item.objectId) ? $r('app.color.color_848484') : $r('app.color.color_222222')) | ||
| 155 | - | ||
| 156 | - Stack() { | ||
| 157 | - if (item.fullColumnImgUrls && item.fullColumnImgUrls.length > 0) { | ||
| 158 | - Image(this.loadImg ? item.fullColumnImgUrls[0].url : '') | ||
| 159 | - .backgroundColor(this.loadImg ? $r('app.color.color_B0B0B0') : 0xf5f5f5) | ||
| 160 | - .width('100%') | ||
| 161 | - .aspectRatio(16 / 9) | ||
| 162 | - .borderRadius(4) | ||
| 163 | - } | ||
| 164 | - this.LiveImage(item) | ||
| 165 | - } | ||
| 166 | - .alignContent(Alignment.BottomEnd) | ||
| 167 | - | ||
| 168 | - Row() { | ||
| 169 | - if (item.rmhInfo && item.rmhInfo.rmhName) { | ||
| 170 | - Text(item.rmhInfo.rmhName) | ||
| 171 | - .fontSize(12) | ||
| 172 | - .fontWeight(400) | ||
| 173 | - .fontColor($r('app.color.color_B0B0B0')) | ||
| 174 | - .fontFamily('PingFang SC-Medium') | ||
| 175 | - .maxLines(1) | ||
| 176 | - .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 177 | - .align(Alignment.Start) | ||
| 178 | - | ||
| 179 | - Image($r('app.media.point_live_icon')) | ||
| 180 | - .objectFit(ImageFit.Auto) | ||
| 181 | - .interpolation(ImageInterpolation.High) | ||
| 182 | - .width(16) | ||
| 183 | - .height(16) | ||
| 184 | - .margin(2) | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - Text(DateTimeUtils.getCommentTime(Number.parseFloat(item.publishTimestamp))) | ||
| 188 | - .fontSize(12) | ||
| 189 | - .maxLines(1) | ||
| 190 | - .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 191 | - .align(Alignment.Start) | ||
| 192 | - .width('100%') | ||
| 193 | - .fontColor($r('app.color.color_B0B0B0')) | ||
| 194 | - } | ||
| 195 | - .margin({ top: 8, bottom: 8 }) | ||
| 196 | - | ||
| 197 | - | ||
| 198 | - Divider() | ||
| 199 | - .strokeWidth(1) | ||
| 200 | - .margin({ top: 6 }) | ||
| 201 | - .width('100%') | ||
| 202 | - .color('#f5f5f5') | ||
| 203 | - } | ||
| 204 | - .width('100%') | ||
| 205 | - .onClick(() => { | ||
| 206 | - this.clickRowBuildItem(item) | ||
| 207 | - ProcessUtils.processPage(item) | ||
| 208 | - }) | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - /*导航栏*/ | ||
| 212 | - @Builder | ||
| 213 | - TabbarNormal() { | ||
| 214 | - | ||
| 215 | - RelativeContainer() { | ||
| 216 | - //标题栏目 | ||
| 217 | - Image($r('app.media.icon_arrow_left')) | ||
| 218 | - .width(24) | ||
| 219 | - .height(24) | ||
| 220 | - .objectFit(ImageFit.Auto) | ||
| 221 | - .id("back_icon") | ||
| 222 | - .alignRules({ | ||
| 223 | - center: { anchor: "__container__", align: VerticalAlign.Center }, | ||
| 224 | - left: { anchor: "__container__", align: HorizontalAlign.Start } | ||
| 225 | - }) | ||
| 226 | - .onClick(() => { | ||
| 227 | - router.back() | ||
| 228 | - }) | ||
| 229 | - | ||
| 230 | - Text(this.title) | ||
| 231 | - .maxLines(1) | ||
| 232 | - .id("title") | ||
| 233 | - .fontSize('18vp') | ||
| 234 | - .fontWeight(400) | ||
| 235 | - .fontColor($r('app.color.color_222222')) | ||
| 236 | - .lineHeight('22vp') | ||
| 237 | - .alignRules({ | ||
| 238 | - center: { anchor: "__container__", align: VerticalAlign.Center }, | ||
| 239 | - middle: { anchor: "__container__", align: HorizontalAlign.Center } | ||
| 240 | - }) | ||
| 241 | - } | ||
| 242 | - .height(44) | ||
| 243 | - .width('100%') | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - @Builder | ||
| 247 | - LiveImage(item: ContentDTO) { | ||
| 248 | - Row() { | ||
| 249 | - LottieView({ | ||
| 250 | - name: 'live_status_wait', | ||
| 251 | - path: "lottie/live_detail_living.json", | ||
| 252 | - lottieWidth: 14, | ||
| 253 | - lottieHeight: 14, | ||
| 254 | - autoplay: true, | ||
| 255 | - loop: true, | ||
| 256 | - title: item.newsTitle | ||
| 257 | - }) | ||
| 258 | - .margin({ | ||
| 259 | - right: '2vp' | ||
| 260 | - }) | ||
| 261 | - | ||
| 262 | - Text('直播中') | ||
| 263 | - .fontSize('12vp') | ||
| 264 | - .fontWeight(400) | ||
| 265 | - .fontColor(Color.White) | ||
| 266 | - .textShadow({ | ||
| 267 | - radius: 2, | ||
| 268 | - color: 'rgba(0,0,0,0.3)', | ||
| 269 | - offsetX: 0, | ||
| 270 | - offsetY: 2 | ||
| 271 | - }) | ||
| 272 | - .margin({ | ||
| 273 | - right: '5vp' | ||
| 274 | - }) | ||
| 275 | - | ||
| 276 | - Image($r('app.media.icon_comp_line_live')).height('11vp').width('1.5vp') | ||
| 277 | - | ||
| 278 | - if (this.getLiveRoomNumber(item).length > 0) { | ||
| 279 | - Text(this.getLiveRoomNumber(item)) | ||
| 280 | - .fontSize('12vp') | ||
| 281 | - .fontWeight(400) | ||
| 282 | - .textShadow({ | ||
| 283 | - radius: 2, | ||
| 284 | - color: 'rgba(0,0,0,0.3)', | ||
| 285 | - offsetX: 0, | ||
| 286 | - offsetY: 2 | ||
| 287 | - }) | ||
| 288 | - .fontColor(Color.White) | ||
| 289 | - .margin({ | ||
| 290 | - left: '5vp' | ||
| 291 | - }) | ||
| 292 | - } | ||
| 293 | - } | ||
| 294 | - .justifyContent(FlexAlign.End) | ||
| 295 | - .margin({ right: 8, bottom: 8 }) | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - private async getData(resolve?: (value: string | PromiseLike<string>) => void) { | ||
| 299 | - if (this.isLoading) { | ||
| 300 | - if (resolve) { | ||
| 301 | - resolve('已更新至最新') | ||
| 302 | - } | ||
| 303 | - return | ||
| 304 | - } | ||
| 305 | - | ||
| 306 | - // 检测网络 | ||
| 307 | - let netStatus = NetworkUtil.isNetConnected() | ||
| 308 | - if (!netStatus) { | ||
| 309 | - | ||
| 310 | - this.emptyType = WDViewDefaultType.WDViewDefaultType_NoNetwork | ||
| 311 | - this.viewType = ViewType.ERROR | ||
| 312 | - | ||
| 313 | - return | ||
| 314 | - } | ||
| 315 | - | ||
| 316 | - | ||
| 317 | - this.isLoading = true | ||
| 318 | - try { | ||
| 319 | - const liveReviewDTO = await PageViewModel.getLiveMoreUrl(this.type, this.currentPage, this.pageSize) | ||
| 320 | - | ||
| 321 | - if (liveReviewDTO && liveReviewDTO.list && liveReviewDTO.list.length > 0) { | ||
| 322 | - if (liveReviewDTO.list.length === this.pageSize) { | ||
| 323 | - this.hasMore = true; | ||
| 324 | - } else { | ||
| 325 | - this.hasMore = false; | ||
| 326 | - } | ||
| 327 | - if (this.currentPage == 1) { | ||
| 328 | - this.data.clear() | ||
| 329 | - } | ||
| 330 | - this.data.push(...liveReviewDTO.list) | ||
| 331 | - this.getLiveRoomDataInfo(liveReviewDTO.list) | ||
| 332 | - } else { | ||
| 333 | - this.hasMore = false; | ||
| 334 | - } | ||
| 335 | - this.resolveEnd(true, resolve) | ||
| 336 | - if (liveReviewDTO.list.length == 0 && this.currentPage == 1) { | ||
| 337 | - this.viewType = ViewType.EMPTY | ||
| 338 | - this.emptyType = WDViewDefaultType.WDViewDefaultType_NoListContent | ||
| 339 | - } | ||
| 340 | - } catch (exception) { | ||
| 341 | - this.resolveEnd(false, resolve) | ||
| 342 | - } | ||
| 343 | - | ||
| 344 | - } | ||
| 345 | - | ||
| 346 | - private resolveEnd(isTop: boolean, resolve?: (value: string | PromiseLike<string>) => void) { | ||
| 347 | - if (resolve) { | ||
| 348 | - if (this.currentPage == 1 && isTop) { | ||
| 349 | - resolve('已更新至最新') | ||
| 350 | - } else { | ||
| 351 | - resolve('') | ||
| 352 | - } | ||
| 353 | - } | ||
| 354 | - if (this.currentPage == 1 && !isTop) { | ||
| 355 | - | ||
| 356 | - this.viewType = ViewType.ERROR | ||
| 357 | - this.emptyType = WDViewDefaultType.WDViewDefaultType_NoListContent | ||
| 358 | - } else { | ||
| 359 | - this.viewType = ViewType.LOADED | ||
| 360 | - } | ||
| 361 | - this.isLoading = false | ||
| 362 | - } | ||
| 363 | - | ||
| 364 | - private getLiveDetailIds(list: ContentDTO[]): string { | ||
| 365 | - let idList: string[] = [] | ||
| 366 | - list.forEach(item => { | ||
| 367 | - idList.push(item.objectId) | ||
| 368 | - }); | ||
| 369 | - return idList.join(',') | ||
| 370 | - } | ||
| 371 | - | ||
| 372 | - // 获取评论数 | ||
| 373 | - async getLiveRoomDataInfo(list: ContentDTO[]) { | ||
| 374 | - const reserveIds = this.getLiveDetailIds(list) | ||
| 375 | - Logger.debug(TAG, '是否预约数据:' + ` ${reserveIds}`) | ||
| 376 | - PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => { | ||
| 377 | - Logger.debug(TAG, '是否预约数据:' + ` ${JSON.stringify(result)}`) | ||
| 378 | - if (result && result.length > 0) { | ||
| 379 | - this.liveRoomList.push(...result) | ||
| 380 | - this.data.reloadData() | ||
| 381 | - } | ||
| 382 | - }).catch(() => { | ||
| 383 | - // this.data.push(...list) | ||
| 384 | - }) | ||
| 385 | - } | ||
| 386 | - | ||
| 387 | - // 判断是否预约 | ||
| 388 | - getLiveRoomNumber(item: ContentDTO): string { | ||
| 389 | - const objc = this.liveRoomList.find((element: LiveRoomDataBean) => { | ||
| 390 | - return element.liveId.toString() == item.objectId | ||
| 391 | - }) | ||
| 392 | - if (objc && objc.pv && objc.pv > 0) { | ||
| 393 | - return this.computeShowNum(objc.pv) | ||
| 394 | - } | ||
| 395 | - return '' | ||
| 396 | - } | ||
| 397 | - | ||
| 398 | - private computeShowNum(count: number): string { | ||
| 399 | - if (count >= 10000) { | ||
| 400 | - let num = (count / 10000).toFixed(1) | ||
| 401 | - if (Number(num.substring(num.length - 1)) == 0) { | ||
| 402 | - num = num.substring(0, num.length - 2) | ||
| 403 | - } | ||
| 404 | - return num + '万人参加' | ||
| 405 | - } | ||
| 406 | - return `${count}人参加` | ||
| 407 | - } | ||
| 408 | - | ||
| 409 | - isClicked(objectId: string) { | ||
| 410 | - return this.clickDatas.includes(objectId) | ||
| 411 | - } | ||
| 412 | - | ||
| 413 | - clickRowBuildItem(item: ContentDTO) { | ||
| 414 | - if (item.objectId && !this.clickDatas.includes(item.objectId)) { | ||
| 415 | - Logger.debug(TAG, '数据:' + JSON.stringify(this.clickDatas)) | ||
| 416 | - this.clickDatas.push(item.objectId.toString()) | ||
| 417 | - this.putLiveMoreClickPreference() | ||
| 418 | - } | ||
| 419 | - } | ||
| 420 | - | ||
| 421 | - async getPreferencesFromStorage() { | ||
| 422 | - let context = getContext(this) as Context | ||
| 423 | - preferenceTheme = await dataPreferences.getPreferences(context, PREFERENCES_NAME) | ||
| 424 | - } | ||
| 425 | - | ||
| 426 | - putLiveMoreClickPreference() { | ||
| 427 | - Logger.info(TAG, `Put begin` + JSON.stringify(this.clickDatas)) | ||
| 428 | - if (preferenceTheme !== null && this.clickDatas.length > 0) { | ||
| 429 | - // await | ||
| 430 | - const arr: Array<string> = [] | ||
| 431 | - arr.push(...this.clickDatas) | ||
| 432 | - preferenceTheme.put('liveMorePage', arr).then(() => { | ||
| 433 | - Logger.debug(TAG, "Succeeded in putting value of 'startup'."); | ||
| 434 | - }).catch((err: BusinessError) => { | ||
| 435 | - Logger.debug(TAG, "Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message); | ||
| 436 | - }) | ||
| 437 | - // await preferenceTheme.flush() | ||
| 438 | - preferenceTheme.flush((err: BusinessError) => { | ||
| 439 | - if (err) { | ||
| 440 | - Logger.debug(TAG, "Failed to flush. code =" + err.code + ", message =" + err.message); | ||
| 441 | - return; | ||
| 442 | - } | ||
| 443 | - }) | ||
| 444 | - | ||
| 445 | - } | ||
| 446 | - } | ||
| 447 | - | ||
| 448 | - getLivMoreClickPreference() { | ||
| 449 | - Logger.info(TAG, `Get begin`) | ||
| 450 | - if (preferenceTheme !== null) { | ||
| 451 | - preferenceTheme.get('liveMorePage', []).then((data: dataPreferences.ValueType) => { | ||
| 452 | - if (data instanceof Array) { | ||
| 453 | - this.clickDatas = data as Array<string> | ||
| 454 | - } | ||
| 455 | - }).catch((err: BusinessError) => { | ||
| 456 | - console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); | ||
| 457 | - }) | ||
| 458 | - } | ||
| 459 | - } | ||
| 460 | } | 37 | } |
| 1 | -import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean'; | 1 | +import { BottomNavDTO, TopNavDTO } from 'wdBean'; |
| 2 | import { SpConstants } from 'wdConstant'; | 2 | import { SpConstants } from 'wdConstant'; |
| 3 | -import { DisplayUtils, LazyDataSource, Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; | 3 | +import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; |
| 4 | import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; | 4 | import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 5 | import { PageComponent } from './PageComponent'; | 5 | import { PageComponent } from './PageComponent'; |
| 6 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; | 6 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; |
| @@ -8,9 +8,8 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent | @@ -8,9 +8,8 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent | ||
| 8 | import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; | 8 | import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; |
| 9 | import { PeopleShipMainComponent } from '../peopleShip/PeopleShipMainComponent'; | 9 | import { PeopleShipMainComponent } from '../peopleShip/PeopleShipMainComponent'; |
| 10 | import { channelSkeleton } from '../skeleton/channelSkeleton'; | 10 | import { channelSkeleton } from '../skeleton/channelSkeleton'; |
| 11 | -import { TrackConstants, TrackingButton } from 'wdTracking/Index'; | ||
| 12 | -import DailyPaperTopicModel from '../../model/DailyPaperTopicModel' | ||
| 13 | -import { ParamType, Tracking } from 'wdTracking/Index'; | 11 | +import { ParamType, TrackConstants, Tracking, TrackingButton } from 'wdTracking/Index'; |
| 12 | +import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'; | ||
| 14 | import { CompUtils } from '../../utils/CompUtils'; | 13 | import { CompUtils } from '../../utils/CompUtils'; |
| 15 | 14 | ||
| 16 | const TAG = 'TopNavigationComponent'; | 15 | const TAG = 'TopNavigationComponent'; |
sight_harmony/features/wdComponent/src/main/ets/components/page/template/BasePageHelp.ets
0 → 100644
| 1 | +import { ArrayList } from '@kit.ArkTS' | ||
| 2 | +import { CompDTO, ContentDTO, LiveRoomDataBean } from 'wdBean/Index' | ||
| 3 | +import { DateTimeUtils, Logger } from 'wdKit/Index' | ||
| 4 | +import PageViewModel from '../../../viewmodel/PageViewModel' | ||
| 5 | +const TAG: string = 'BaseTemplateHelp' | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +export class BasePageHelp { | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * 请求获取直播房间的动态数据 | ||
| 12 | + * @param list | ||
| 13 | + */ | ||
| 14 | + /** | ||
| 15 | + * 直播回看的批查数据 | ||
| 16 | + * @param list | ||
| 17 | + * @param compList | ||
| 18 | + */ | ||
| 19 | + getLiveRoomDataInfo(compList: CompDTO[]) { | ||
| 20 | + | ||
| 21 | + let list: ContentDTO[] = [] | ||
| 22 | + compList.forEach((comp: CompDTO) => { | ||
| 23 | + list.push(...comp.operDataList) | ||
| 24 | + }) | ||
| 25 | + let time = DateTimeUtils.getTimeStamp().toString() | ||
| 26 | + | ||
| 27 | + let reserveIds = this.getLiveDetailIds(list) | ||
| 28 | + | ||
| 29 | + PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => { | ||
| 30 | + if (result && result.length > 0) { | ||
| 31 | + result.forEach((bean: LiveRoomDataBean) => { | ||
| 32 | + for (let item of list) { | ||
| 33 | + if (item.objectId == bean.liveId.toString()) { | ||
| 34 | + item.liveRoomDataBean = bean | ||
| 35 | + outer: for (let compBean of compList) { | ||
| 36 | + for (let contentBean of compBean.operDataList) { | ||
| 37 | + if (contentBean === item) { | ||
| 38 | + compBean.timestamp = time | ||
| 39 | + break outer | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + break | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + }) | ||
| 47 | + } | ||
| 48 | + }).catch(() => { | ||
| 49 | + }) | ||
| 50 | + } | ||
| 51 | + /** | ||
| 52 | + * 获取业务内容 objectId 集合穿 如1,2,3 | ||
| 53 | + * @param pageContentList | ||
| 54 | + * @returns | ||
| 55 | + */ | ||
| 56 | + private getLiveDetailIds(pageContentList: ContentDTO[]): string { | ||
| 57 | + let idList: string[] = [] | ||
| 58 | + pageContentList.forEach(item => { | ||
| 59 | + idList.push(item.objectId) | ||
| 60 | + }); | ||
| 61 | + return idList.join(',') | ||
| 62 | + } | ||
| 63 | +} |
sight_harmony/features/wdComponent/src/main/ets/components/page/template/TemplatePageComponent.ets
0 → 100644
| 1 | +import { CompDTO, ContentDTO } from 'wdBean/Index' | ||
| 2 | +import { LazyDataSource, Logger } from 'wdKit/Index' | ||
| 3 | +import { CompParser } from '../../CompParser' | ||
| 4 | +import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh' | ||
| 5 | +import { PeopleShipNoMoreData } from '../../reusable/PeopleShipNoMoreData' | ||
| 6 | +import { channelSkeleton } from '../../skeleton/channelSkeleton' | ||
| 7 | +import { EmptyComponent } from '../../view/EmptyComponent' | ||
| 8 | +import LoadMoreLayout from '../LoadMoreLayout' | ||
| 9 | +import TemplatePageHelp from './TemplatePageHelp' | ||
| 10 | +import TemplatePageModel from './TemplatePageModel' | ||
| 11 | +import { TemplatePageStateType } from './TemplatePageStateType' | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +const TAG: string = 'TemplatePageComponent'; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * @Description: 处理通用信息展示页面,1)业务数据加载;2)异常状况处理;3)展位信息处理 | ||
| 18 | + * @Author: | ||
| 19 | + * @Email: liyubing@wondertek.com.cn | ||
| 20 | + * @CreateDate: | ||
| 21 | + * @UpdateRemark: 更新说明 | ||
| 22 | + * @Version: 1.0 | ||
| 23 | + */ | ||
| 24 | +@Component | ||
| 25 | +export default struct TemplatePageComponent { | ||
| 26 | + | ||
| 27 | + // 模板页面的数据驱动对象 | ||
| 28 | + @State private templatePage: TemplatePageModel = new TemplatePageModel | ||
| 29 | + // 此内容主要因CustomPullToRefresh需要,目前没任何业务意义要求 | ||
| 30 | + @State pageData: LazyDataSource<ContentDTO> = new LazyDataSource(); | ||
| 31 | + // 滚动 | ||
| 32 | + private templateScroller: Scroller = new Scroller() | ||
| 33 | + //识别不同页面的业务类型 | ||
| 34 | + pageDataSourceType: string = '' | ||
| 35 | + | ||
| 36 | + // 埋点字段 | ||
| 37 | + pageId: string = '' | ||
| 38 | + pageName: string = '' | ||
| 39 | + | ||
| 40 | + async aboutToAppear() { | ||
| 41 | + Logger.debug(TAG, 'aboutToAppear') | ||
| 42 | + this.requestPageData() | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + aboutToDisappear(): void { | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + build() { | ||
| 50 | + if (this.templatePage.pageCompType === TemplatePageStateType.LOADING) { | ||
| 51 | + this.LoadingLayout() | ||
| 52 | + } else if (this.templatePage.pageCompType === TemplatePageStateType.LOADED) { | ||
| 53 | + | ||
| 54 | + CustomPullToRefresh({ | ||
| 55 | + alldata: this.pageData, | ||
| 56 | + scroller: this.templateScroller, | ||
| 57 | + hasMore: false, | ||
| 58 | + customList: () => { | ||
| 59 | + this.ListLayout() | ||
| 60 | + }, | ||
| 61 | + onRefresh: (resolve) => { | ||
| 62 | + this.templatePage.currentPage = 1 | ||
| 63 | + this.templatePage.resolve = resolve | ||
| 64 | + this.requestPageData(resolve) | ||
| 65 | + }, | ||
| 66 | + }) | ||
| 67 | + | ||
| 68 | + } else { | ||
| 69 | + EmptyComponent({ | ||
| 70 | + emptyType: this.templatePage.noNormalState, | ||
| 71 | + emptyButton: true, | ||
| 72 | + retry: () => { | ||
| 73 | + this.requestPageData() | ||
| 74 | + } | ||
| 75 | + }) | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Builder | ||
| 80 | + LoadingLayout() { | ||
| 81 | + channelSkeleton() | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Builder | ||
| 85 | + ListLayout() { | ||
| 86 | + List({ scroller: this.templateScroller }) { | ||
| 87 | + // 下拉刷新 | ||
| 88 | + LazyForEach(this.templatePage.compList, (compDTO: CompDTO, index: number) => { | ||
| 89 | + ListItem() { | ||
| 90 | + Column() { | ||
| 91 | + | ||
| 92 | + CompParser({ | ||
| 93 | + compDTO: compDTO, | ||
| 94 | + compIndex: index, | ||
| 95 | + pageId: this.pageId, | ||
| 96 | + pageName: this.pageName | ||
| 97 | + }); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + }, | ||
| 101 | + (contentDTO: CompDTO, contentIndex: number) => JSON.stringify(contentDTO)) | ||
| 102 | + // 加载更多 | ||
| 103 | + ListItem() { | ||
| 104 | + if (this.templatePage.hasMore && this.templatePage.compList && this.templatePage.compList.totalCount() > 0) { | ||
| 105 | + LoadMoreLayout({ isVisible: this.templatePage.hasMore }) | ||
| 106 | + } else if (!this.templatePage.hasMore && !this.templatePage.isLoading) { | ||
| 107 | + PeopleShipNoMoreData() | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + .scrollBar(BarState.Off) | ||
| 112 | + .edgeEffect(EdgeEffect.None) | ||
| 113 | + .cachedCount(3) | ||
| 114 | + .height('calc(100% - 44vp)') | ||
| 115 | + .onReachEnd(() => { | ||
| 116 | + Logger.debug(TAG, "触底了"); | ||
| 117 | + if (!this.templatePage.isLoading && this.templatePage.hasMore) { | ||
| 118 | + //加载分页数据 | ||
| 119 | + this.templatePage.currentPage++; | ||
| 120 | + this.requestPageData() | ||
| 121 | + } | ||
| 122 | + }) | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * 请求业务数据 | ||
| 127 | + */ | ||
| 128 | + async requestPageData(resolve?: (value: string | PromiseLike<string>) => void) { | ||
| 129 | + | ||
| 130 | + if (this.templatePage.isLoading) { | ||
| 131 | + if (resolve) { | ||
| 132 | + resolve('已更新至最新') | ||
| 133 | + } | ||
| 134 | + return | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + this.templatePage.pageDataSourceType = this.pageDataSourceType | ||
| 138 | + | ||
| 139 | + TemplatePageHelp.requestPageData(this.templatePage) | ||
| 140 | + } | ||
| 141 | +} |
sight_harmony/features/wdComponent/src/main/ets/components/page/template/TemplatePageConstant.ets
0 → 100644
| 1 | +/** | ||
| 2 | + * @Description: 模板页面的常量 | ||
| 3 | + * @Author: | ||
| 4 | + * @Email: liyubing@wondertek.com.cn | ||
| 5 | + * @CreateDate: | ||
| 6 | + * @UpdateRemark: 更新说明 | ||
| 7 | + * @Version: 1.0 | ||
| 8 | + */ | ||
| 9 | +export class TemplatePageConstant { | ||
| 10 | + /** | ||
| 11 | + * 直播中 | ||
| 12 | + */ | ||
| 13 | + public static LIVE_HORIZONTAL_CARD: string = "LIVE_HORIZONTAL_CARD" | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +} |
sight_harmony/features/wdComponent/src/main/ets/components/page/template/TemplatePageHelp.ets
0 → 100644
| 1 | +import { CompDTO } from 'wdBean/Index'; | ||
| 2 | +import { CompStyle } from 'wdConstant/Index'; | ||
| 3 | +import { NetworkUtil } from 'wdKit/Index'; | ||
| 4 | +import PageViewModel from '../../../viewmodel/PageViewModel'; | ||
| 5 | +import { WDViewDefaultType } from '../../view/EmptyComponent'; | ||
| 6 | +import { BasePageHelp } from './BasePageHelp'; | ||
| 7 | +import { TemplatePageConstant } from './TemplatePageConstant'; | ||
| 8 | +import TemplatePageModel from './TemplatePageModel'; | ||
| 9 | +import { TemplatePageStateType } from './TemplatePageStateType'; | ||
| 10 | + | ||
| 11 | +const TAG: string = 'TemplatePageHelp'; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * @Description: 完成不同页面业务数据获取并加工 | ||
| 15 | + * @Author: | ||
| 16 | + * @Email: liyubing@wondertek.com.cn | ||
| 17 | + * @CreateDate: | ||
| 18 | + * @UpdateRemark: 更新说明 | ||
| 19 | + * @Version: 1.0 | ||
| 20 | + */ | ||
| 21 | +export class TemplatePageHelp extends BasePageHelp { | ||
| 22 | + private pageModel: TemplatePageModel = new TemplatePageModel | ||
| 23 | + | ||
| 24 | + constructor() { | ||
| 25 | + super(); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 请求业务数据 | ||
| 30 | + * @param pageModel | ||
| 31 | + */ | ||
| 32 | + async requestPageData(pageModel: TemplatePageModel) { | ||
| 33 | + | ||
| 34 | + this.pageModel = pageModel | ||
| 35 | + // 检测网络 | ||
| 36 | + let netStatus = NetworkUtil.isNetConnected() | ||
| 37 | + if (netStatus) { | ||
| 38 | + this.treatDiffBusinessDataSource() | ||
| 39 | + } else if (pageModel.compList.size() > 0) { | ||
| 40 | + // 加载缓存数据了,不用无网络提示 | ||
| 41 | + } else { | ||
| 42 | + // 无网情况 | ||
| 43 | + pageModel.pageCompType = TemplatePageStateType.OTHER; | ||
| 44 | + pageModel.noNormalState = WDViewDefaultType.WDViewDefaultType_NoNetwork | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 区分不同业务数据源 | ||
| 51 | + */ | ||
| 52 | + private treatDiffBusinessDataSource() { | ||
| 53 | + | ||
| 54 | + if (this.pageModel.pageDataSourceType === TemplatePageConstant.LIVE_HORIZONTAL_CARD) { | ||
| 55 | + // 直播列表 | ||
| 56 | + this.requestLiveListData(this.pageModel.resolve) | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 请求直播列表数据 | ||
| 64 | + */ | ||
| 65 | + private async requestLiveListData(resolve?: (value: string | PromiseLike<string>) => void) { | ||
| 66 | + | ||
| 67 | + this.pageModel.isLoading = true | ||
| 68 | + | ||
| 69 | + const liveReviewDTO = await PageViewModel.getLiveMoreUrl(1, this.pageModel.currentPage, this.pageModel.pageSize) | ||
| 70 | + | ||
| 71 | + if (liveReviewDTO && liveReviewDTO.list && liveReviewDTO.list.length > 0) { | ||
| 72 | + | ||
| 73 | + if (liveReviewDTO.list.length === this.pageModel.pageSize) { | ||
| 74 | + this.pageModel.hasMore = true | ||
| 75 | + } else { | ||
| 76 | + this.pageModel.hasMore = false | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + // 依据业务请求获取的数据,转换成compDTO数据 | ||
| 81 | + let pageContentList: CompDTO[] = [] // 收集页面组件、稿件和本地组件容器 | ||
| 82 | + for (let contentDto of liveReviewDTO.list) { | ||
| 83 | + let compDTO: CompDTO = new CompDTO() | ||
| 84 | + compDTO.compType = 'appStyle' | ||
| 85 | + contentDto.appStyle = CompStyle.Card_Comp_Live_Big_Image_02 | ||
| 86 | + compDTO.operDataList.push(contentDto) | ||
| 87 | + pageContentList.push(compDTO) | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + // 推送数据到懒加载机制 | ||
| 91 | + this.pushDataToPage(pageContentList) | ||
| 92 | + // 完成业务请求加载 | ||
| 93 | + this.pageModel.isLoading = false | ||
| 94 | + // 批查 | ||
| 95 | + this.allCompBatchRequest(pageContentList) | ||
| 96 | + | ||
| 97 | + } else { | ||
| 98 | + | ||
| 99 | + this.pageModel.hasMore = false | ||
| 100 | + if (this.pageModel.currentPage === 1) { | ||
| 101 | + // 无业务数据 | ||
| 102 | + this.pageNoHaveData() | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + this.resolveEnd(resolve) | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 处理页面批查业务方法 | ||
| 112 | + * @param list | ||
| 113 | + */ | ||
| 114 | + private allCompBatchRequest(compList: CompDTO[]) { | ||
| 115 | + | ||
| 116 | + // 获取直播房间的动态数据 | ||
| 117 | + this.getLiveRoomDataInfo(compList) | ||
| 118 | + | ||
| 119 | + // 测试数据 | ||
| 120 | + // setTimeout(() => { | ||
| 121 | + // let time = DateTimeUtils.getTimeStamp().toString() | ||
| 122 | + // let index = 1 | ||
| 123 | + // let compBean = compList[index] as CompDTO | ||
| 124 | + // let contentBean = compBean.operDataList[0] | ||
| 125 | + // contentBean.newsTitle = '熬阿斯蒂芬' | ||
| 126 | + // //comp.operDataList[0].newsTitle = '测试111' | ||
| 127 | + // let liveRoomBean: LiveRoomDataBean = {} as LiveRoomDataBean; | ||
| 128 | + // liveRoomBean.pv = 6555 | ||
| 129 | + // contentBean.liveRoomDataBean = liveRoomBean | ||
| 130 | + // compBean.timestamp = time | ||
| 131 | + // Logger.debug("ZZZXXXXX", | ||
| 132 | + // "-----setTimeout--------->" + time) | ||
| 133 | + // }, 4 * 1000) | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * 推数据到页面 | ||
| 139 | + * @param list | ||
| 140 | + */ | ||
| 141 | + private pushDataToPage(pageContentList: CompDTO[]) { | ||
| 142 | + | ||
| 143 | + // 请求第一页数据,需要清理pageData数据 | ||
| 144 | + if (this.pageModel.currentPage == 1) { | ||
| 145 | + this.pageModel.compList.clear() | ||
| 146 | + } | ||
| 147 | + // 懒加载,推送数据 | ||
| 148 | + for (let contentDto of pageContentList) { | ||
| 149 | + this.pageModel.compList.push(contentDto) | ||
| 150 | + } | ||
| 151 | + //完成业务数据请求 | ||
| 152 | + this.pageModel.pageCompType = TemplatePageStateType.LOADED | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 页面没有数据 | ||
| 158 | + */ | ||
| 159 | + private pageNoHaveData() { | ||
| 160 | + this.pageModel.pageCompType = TemplatePageStateType.OTHER | ||
| 161 | + this.pageModel.noNormalState = WDViewDefaultType.WDViewDefaultType_NoNetwork | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 解析结束 | ||
| 166 | + * @param resolve | ||
| 167 | + */ | ||
| 168 | + private resolveEnd(resolve?: (value: string | PromiseLike<string>) => void) { | ||
| 169 | + if (resolve) { | ||
| 170 | + if (this.pageModel.currentPage == 1) { | ||
| 171 | + resolve('已更新至最新') | ||
| 172 | + } else { | ||
| 173 | + resolve('') | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + } | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | + | ||
| 181 | +let templatePageHelp = new TemplatePageHelp(); | ||
| 182 | + | ||
| 183 | +export default templatePageHelp as TemplatePageHelp; |
sight_harmony/features/wdComponent/src/main/ets/components/page/template/TemplatePageModel.ets
0 → 100644
| 1 | +import { ContentDTO } from 'wdBean/Index'; | ||
| 2 | +import { BaseDTO } from 'wdBean/src/main/ets/bean/component/BaseDTO'; | ||
| 3 | +import { LazyDataSource } from 'wdKit/Index'; | ||
| 4 | +import { WDViewDefaultType } from '../../view/EmptyComponent'; | ||
| 5 | +import { TemplatePageStateType } from './TemplatePageStateType'; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @Description: 与TemplatePageCompent结合使用,处理业务、异常等数据 | ||
| 9 | + * @Author: | ||
| 10 | + * @Email: liyubing@wondertek.com.cn | ||
| 11 | + * @CreateDate: | ||
| 12 | + * @UpdateRemark: 更新说明 | ||
| 13 | + * @Version: 1.0 | ||
| 14 | + */ | ||
| 15 | +export default class TemplatePageModel { | ||
| 16 | + /** | ||
| 17 | + * 不用的页面所展示的业务数据都转换CompDTO对象 | ||
| 18 | + */ | ||
| 19 | + compList: LazyDataSource<BaseDTO> = new LazyDataSource(); | ||
| 20 | + /** | ||
| 21 | + * 识别不同页面的业务类型 | ||
| 22 | + */ | ||
| 23 | + pageDataSourceType: string = '' | ||
| 24 | + | ||
| 25 | + // 页码 | ||
| 26 | + currentPage: number = 1 | ||
| 27 | + // 一页最多信息量 | ||
| 28 | + pageSize: number = 20 | ||
| 29 | + // 是否支持加载更多数据 | ||
| 30 | + hasMore:boolean = false | ||
| 31 | + // 是否正在请求数据 | ||
| 32 | + isLoading: boolean = false | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 此字段可驱动组件展示不同业务的组件, | ||
| 36 | + */ | ||
| 37 | + pageCompType: number = TemplatePageStateType.LOADING | ||
| 38 | + /** | ||
| 39 | + * 异常状态 ——> 记录在获取数据中的不同状态,如无数据、无网络等情况 | ||
| 40 | + */ | ||
| 41 | + noNormalState: WDViewDefaultType = WDViewDefaultType.WDViewDefaultType_Default | ||
| 42 | + | ||
| 43 | + resolve?: (value: string | PromiseLike<string>) => void | ||
| 44 | +} |
| @@ -263,6 +263,13 @@ export class PageViewModel extends BaseViewModel { | @@ -263,6 +263,13 @@ export class PageViewModel extends BaseViewModel { | ||
| 263 | }) | 263 | }) |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | + /** | ||
| 267 | + * | ||
| 268 | + * @param type 1:正在直播,2:预告 | ||
| 269 | + * @param pageNum | ||
| 270 | + * @param pageSize | ||
| 271 | + * @returns | ||
| 272 | + */ | ||
| 266 | async getLiveMoreUrl(type: number, pageNum: number, pageSize: number): Promise<LiveReviewDTO> { | 273 | async getLiveMoreUrl(type: number, pageNum: number, pageSize: number): Promise<LiveReviewDTO> { |
| 267 | return new Promise<LiveReviewDTO>((success, error) => { | 274 | return new Promise<LiveReviewDTO>((success, error) => { |
| 268 | Logger.info(TAG, `getLiveMoreUrl pageInfo start`); | 275 | Logger.info(TAG, `getLiveMoreUrl pageInfo start`); |
| @@ -363,21 +370,22 @@ export class PageViewModel extends BaseViewModel { | @@ -363,21 +370,22 @@ export class PageViewModel extends BaseViewModel { | ||
| 363 | async getPageGroupCacheData(pageModel: PageUIReqBean): Promise<PageDTO | null> { | 370 | async getPageGroupCacheData(pageModel: PageUIReqBean): Promise<PageDTO | null> { |
| 364 | Logger.debug(TAG, 'getPageData pageId: ' + pageModel.pageId); | 371 | Logger.debug(TAG, 'getPageData pageId: ' + pageModel.pageId); |
| 365 | return new Promise<PageDTO | null>((success) => { | 372 | return new Promise<PageDTO | null>((success) => { |
| 366 | - CacheData.getLocalCacheData(CacheData.compGroupInfoDataCacheKey + pageModel.pageId + pageModel.groupId).then((data) => { | ||
| 367 | - // Logger.debug(TAG, 'getPageGroupCacheData 333 ' + JSON.stringify(data)); | ||
| 368 | - if (data) { | ||
| 369 | - let navBean = JSON.parse(CacheData.getNetworkData(data)) as PageDTO | ||
| 370 | - success(navBean) | ||
| 371 | - } else { | 373 | + CacheData.getLocalCacheData(CacheData.compGroupInfoDataCacheKey + pageModel.pageId + pageModel.groupId) |
| 374 | + .then((data) => { | ||
| 375 | + // Logger.debug(TAG, 'getPageGroupCacheData 333 ' + JSON.stringify(data)); | ||
| 376 | + if (data) { | ||
| 377 | + let navBean = JSON.parse(CacheData.getNetworkData(data)) as PageDTO | ||
| 378 | + success(navBean) | ||
| 379 | + } else { | ||
| 380 | + success(null) | ||
| 381 | + } | ||
| 382 | + }) | ||
| 383 | + .catch((err: object) => { | ||
| 384 | + Logger.error(TAG, 'getPageGroupCacheData catch err: ' + JSON.stringify(err)); | ||
| 372 | success(null) | 385 | success(null) |
| 373 | - } | ||
| 374 | - }).catch((err: object) => { | ||
| 375 | - Logger.error(TAG, 'getPageGroupCacheData catch err: ' + JSON.stringify(err)); | ||
| 376 | - success(null) | ||
| 377 | - }) | 386 | + }) |
| 378 | }); | 387 | }); |
| 379 | } | 388 | } |
| 380 | - | ||
| 381 | } | 389 | } |
| 382 | 390 | ||
| 383 | 391 |
-
Please register or login to post a comment