wangyujian_wd

feat:1)添加直播详情页基本组件(直播预约信息tab页面)

1 import ArrayList from '@ohos.util.ArrayList'; 1 import ArrayList from '@ohos.util.ArrayList';
2 -import { Action } from 'wdBean'  
3 -import { WDRouterPage } from './WDRouterPage' 2 +import { Action } from 'wdBean';
  3 +import { WDRouterPage } from './WDRouterPage';
4 4
5 interface HandleObject { 5 interface HandleObject {
6 handle: (action: Action) => (WDRouterPage | undefined) 6 handle: (action: Action) => (WDRouterPage | undefined)
@@ -75,6 +75,8 @@ export function registerRouter() { @@ -75,6 +75,8 @@ export function registerRouter() {
75 return WDRouterPage.imageTextDetailPage 75 return WDRouterPage.imageTextDetailPage
76 } else if (action.params?.pageID == "BroadcastPage") { 76 } else if (action.params?.pageID == "BroadcastPage") {
77 return WDRouterPage.broadcastPage 77 return WDRouterPage.broadcastPage
  78 + } else if (action.params?.pageID == "LIVE_DETAILS_PAGER") {
  79 + return WDRouterPage.detailPlayLivePage
78 } 80 }
79 return undefined 81 return undefined
80 }) 82 })
@@ -134,6 +134,15 @@ export struct TopNavigationComponent { @@ -134,6 +134,15 @@ export struct TopNavigationComponent {
134 }; 134 };
135 WDRouterRule.jumpWithAction(taskAction) 135 WDRouterRule.jumpWithAction(taskAction)
136 } 136 }
  137 + jumpToLiveDetailsPaper() {
  138 + let taskAction: Action = {
  139 + type: 'JUMP_INNER_NEW_PAGE',
  140 + params: {
  141 + pageID: 'LIVE_DETAILS_PAGER'
  142 + } as Params,
  143 + };
  144 + WDRouterRule.jumpWithAction(taskAction)
  145 + }
137 146
138 build() { 147 build() {
139 Column() { 148 Column() {
  1 +import { BottomComponent } from '../widgets/details/BottomComponent';
  2 +import { TabComponent } from '../widgets/details/TabComponent';
  3 +import { TopPlayComponent } from '../widgets/details/TopPlayComponet';
  4 +
1 @Entry 5 @Entry
2 @Component 6 @Component
3 export struct DetailPlayLivePage { 7 export struct DetailPlayLivePage {
4 - @State message: string = 'Detail Play Live Page'; 8 + TAG: string = 'DetailPlayLivePage';
  9 +
  10 + aboutToAppear(): void {
  11 +
  12 + }
5 13
6 build() { 14 build() {
7 - Row() {  
8 - Column() {  
9 - Text(this.message)  
10 - .fontSize(50)  
11 - .fontWeight(FontWeight.Bold)  
12 - }  
13 - .width('100%') 15 + Column() {
  16 + TopPlayComponent()
  17 + TabComponent()
  18 + BottomComponent()
14 } 19 }
15 .height('100%') 20 .height('100%')
  21 + .width('100%')
  22 + }
  23 +
  24 + aboutToDisappear(): void {
16 } 25 }
17 } 26 }
  1 +@Component
  2 +export struct BottomComponent {
  3 + aboutToAppear(): void {
  4 + }
  5 +
  6 + build() {
  7 + Row() {
  8 +
  9 + }.backgroundColor(Color.Red)
  10 + .height('50vp')
  11 + .width('100%')
  12 + }
  13 +
  14 + aboutToDisappear(): void {
  15 + }
  16 +}
  1 +import font from '@ohos.font'
  2 +
  3 +@Component
  4 +export struct LiveCountdownComponent {
  5 + textTimerController: TextTimerController = new TextTimerController()
  6 + @State format: string = 'HH:mm:ss'
  7 +
  8 + aboutToAppear(): void {
  9 + //注册字体
  10 + font.registerFont({
  11 + familyName: 'BebasNeue_Regular',
  12 + familySrc: $rawfile('font/BebasNeue_Regular.otf')
  13 + })
  14 + setTimeout(() => {
  15 + this.textTimerController.start()
  16 + }, 2000)
  17 + }
  18 +
  19 + build() {
  20 + Column() {
  21 + this.showTitle()
  22 + this.showCountDown()
  23 + this.showAppointment()
  24 + }.padding({
  25 + top: 20,
  26 + left: 20,
  27 + right: 20,
  28 + bottom: 24
  29 + })
  30 + .backgroundColor(Color.White)
  31 + .border({ radius: 6 })
  32 + .margin({ top: 16 })
  33 + }
  34 +
  35 + aboutToDisappear(): void {
  36 + this.textTimerController.pause()
  37 + }
  38 +
  39 + @Builder
  40 + showTitle() {
  41 + Text('距离直播开始还有')
  42 + .maxLines(2)
  43 + .textOverflow({ overflow: TextOverflow.Ellipsis })
  44 + .fontSize('14fp')
  45 + .fontWeight(400)
  46 + .fontColor('#222222')
  47 + }
  48 +
  49 + @Builder
  50 + showCountDown() {
  51 + Row() {
  52 + this.showTimeStyle('10', true, 0)
  53 + this.showTimeStyle('月', false, 3)
  54 + this.showTimeStyle('8', true, 3)
  55 + this.showTimeStyle('日', false, 3)
  56 + this.showTimeStyle('16', true, 10)
  57 + this.showTimeStyle(':', true, 0)
  58 + this.showTimeStyle('05', true, 0)
  59 + }
  60 + .margin({ top: 10 })
  61 + .visibility(Visibility.None)
  62 +
  63 + TextTimer({ isCountDown: true, count: 24 * 60 * 60 * 1000 - 1000, controller: this.textTimerController })
  64 + .format(this.format)
  65 + .fontSize('40fp')
  66 + .fontWeight(FontWeight.Bold)
  67 + .fontColor('#222222')
  68 + .fontFamily('BebasNeue_Regular')
  69 + .onTimer((utc: number, elapsedTime: number) => {
  70 + console.info('textTimer notCountDown utc is:' + utc + ', elapsedTime: ' + elapsedTime)
  71 + })
  72 + .margin({ top: 10 })
  73 + }
  74 +
  75 + @Builder
  76 + showAppointment() {
  77 + Text('我要预约')
  78 + .width('100%')
  79 + .height(42)
  80 + .textAlign(TextAlign.Center)
  81 + .fontSize('16fp')
  82 + .fontWeight(400)
  83 + .fontColor(Color.White)
  84 + .margin({
  85 + top: 16
  86 + })
  87 + .border({ radius: 4 })
  88 + .backgroundColor('#ED2800')
  89 + // .backgroundColor('#CCCCCC')
  90 + }
  91 +
  92 + @Builder
  93 + showTimeStyle(value: string, isBold: boolean, left: number) {
  94 + Text(value)
  95 + .fontSize(isBold ? '40fp' : '16fp')
  96 + .fontFamily(isBold ? 'BebasNeue_Regular' : '')
  97 + .fontWeight(isBold ? FontWeight.Bold : 500)
  98 + .fontColor('#222222')
  99 + .margin({ left: left })
  100 + }
  101 +}
  1 +@Component
  2 +export struct TabChatComponent {
  3 + arr: string[] = []
  4 + aboutToAppear(): void {
  5 + for (let index = 0; index < 80; index++) {
  6 + this.arr.push(index + '')
  7 + }
  8 + }
  9 +
  10 + build() {
  11 + List() {
  12 + ForEach(this.arr, (item: string) => {
  13 + ListItem() {
  14 + Column() {
  15 + Text(item)
  16 + Divider().height(10).width('100%')
  17 + }
  18 + .backgroundColor(Color.Gray)
  19 + }
  20 + })
  21 + }
  22 + }
  23 +
  24 + aboutToDisappear(): void {
  25 + }
  26 +}
  1 +import { TabChatComponent } from './TabChatComponent'
  2 +import { TabInfoComponent } from './TabInfoComponent'
  3 +import { TabLiveComponent } from './TabLiveComponent'
  4 +
  5 +@Component
  6 +export struct TabComponent {
  7 + @State fontColor: string = '#999999'
  8 + @State selectedFontColor: string = '#222222'
  9 + @State currentIndex: number = 0
  10 + private controller: TabsController = new TabsController()
  11 + tabs: string[] = ['简介', '直播间', '大家聊']
  12 +
  13 + aboutToAppear(): void {
  14 +
  15 + }
  16 +
  17 + build() {
  18 + Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
  19 + ForEach(this.tabs, (item: string, index: number) => {
  20 + TabContent() {
  21 + if (0 == index) {
  22 + TabInfoComponent()
  23 + } else if (1 == index) {
  24 + TabLiveComponent()
  25 + } else {
  26 + TabChatComponent()
  27 + }
  28 + }.tabBar(this.tabBuilder(index, item))
  29 + .backgroundColor('#F5F5F5')
  30 + }, (item: string, index: number) => {
  31 + return item + index
  32 + })
  33 + }
  34 + .layoutWeight(1)
  35 + .vertical(false)
  36 + .barMode(BarMode.Fixed)
  37 + .barWidth(200)
  38 + .barHeight(48)
  39 + .animationDuration(100)
  40 + .onChange((index: number) => {
  41 + this.currentIndex = index
  42 + })
  43 + .backgroundColor(Color.White)
  44 + }
  45 +
  46 + @Builder
  47 + tabBuilder(index: number, name: string) {
  48 + Column() {
  49 + Text(name)
  50 + .margin({ top: 6 })
  51 + .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
  52 + .fontSize('18fp')
  53 + .fontWeight(this.currentIndex === index ? 600 : 400)
  54 + Divider()
  55 + .strokeWidth(2)
  56 + .margin({ top: 6 })
  57 + .width(15)
  58 + .color('#CB0000')
  59 + .visibility(this.currentIndex === index ? Visibility.Visible : Visibility.Hidden)
  60 + }.width('100%')
  61 + }
  62 +
  63 + aboutToDisappear(): void {
  64 + }
  65 +}
  1 +import { LiveCountdownComponent } from './LiveCountdownComponent'
  2 +
  3 +@Entry
  4 +@Component
  5 +export struct TabInfoComponent {
  6 + aboutToAppear(): void {
  7 + }
  8 +
  9 + build() {
  10 + Column() {
  11 + this.showLiveTitle()
  12 + this.showLiveDetails()
  13 + LiveCountdownComponent()
  14 + }.padding({
  15 + top: 13,
  16 + left: 16,
  17 + right: 16
  18 + })
  19 + .height('100%')
  20 + }
  21 +
  22 + aboutToDisappear(): void {
  23 + }
  24 +
  25 + @Builder
  26 + showLiveTitle() {
  27 + Text('国新办发布会丨介绍防汛抗旱工国新办发布会丨介绍防汛抗旱工作情况国新办发布会丨介绍防汛抗旱工作情况作情况国新办发布会丨介绍防汛抗旱工作情况')
  28 + .maxLines(2)
  29 + .textOverflow({ overflow: TextOverflow.Ellipsis })
  30 + .fontSize('18fp')
  31 + .fontWeight(500)
  32 + .fontColor('#222222')
  33 + }
  34 +
  35 + @Builder
  36 + showLiveDetails() {
  37 + Text('国务院新闻办公室将于7月25日上午10时举行国务院政策例行吹风会,请应急管理部副部长、水利部副部长王道席和自然资源部、水利部、应急管理部、中国气象局、国家消防救援局有关负责人介绍防汛抗旱工作情况,并答记者问。')
  38 + .maxLines(5)
  39 + .textOverflow({ overflow: TextOverflow.Ellipsis })
  40 + .fontSize('14fp')
  41 + .fontWeight(400)
  42 + .fontColor('#666666')
  43 + .margin({ top: 8 })
  44 + }
  45 +}
  1 +@Component
  2 +export struct TabLiveComponent {
  3 + aboutToAppear(): void {
  4 + }
  5 +
  6 + build() {
  7 + }
  8 +
  9 + aboutToDisappear(): void {
  10 + }
  11 +}
  1 +@Component
  2 +export struct TopPlayComponent {
  3 + aspectRatioPlayer: number = 375 / 211
  4 +
  5 + aboutToAppear(): void {
  6 +
  7 + }
  8 +
  9 + build() {
  10 + Stack()
  11 + .height(211)
  12 + .aspectRatio(this.aspectRatioPlayer)
  13 + .backgroundColor(Color.Black)
  14 + }
  15 +
  16 + aboutToDisappear(): void {
  17 + }
  18 +}