zhenghy

视频频道页改成沉浸式

@@ -7,6 +7,7 @@ import { CompUtils } from '../../utils/CompUtils'; @@ -7,6 +7,7 @@ import { CompUtils } from '../../utils/CompUtils';
7 import PageViewModel from '../../viewmodel/PageViewModel'; 7 import PageViewModel from '../../viewmodel/PageViewModel';
8 import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; 8 import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils';
9 import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; 9 import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
  10 +import { VideoChannelPage } from './VideoChannelPage';
10 11
11 const TAG = 'BottomNavigationComponent'; 12 const TAG = 'BottomNavigationComponent';
12 let storage = LocalStorage.getShared(); 13 let storage = LocalStorage.getShared();
@@ -80,6 +81,12 @@ export struct BottomNavigationComponent { @@ -80,6 +81,12 @@ export struct BottomNavigationComponent {
80 if (CompUtils.isMine(navItem)) { 81 if (CompUtils.isMine(navItem)) {
81 // 我的页面组件数据列表 82 // 我的页面组件数据列表
82 MinePageComponent() 83 MinePageComponent()
  84 + } else if (navItem.name === '视频') {
  85 + // 视频频道,包含视频和直播
  86 + VideoChannelPage({
  87 + topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073),
  88 + _currentNavIndex: $currentNavIndex,
  89 + })
83 } else { 90 } else {
84 TopNavigationComponent({ 91 TopNavigationComponent({
85 groupId: navItem.id, 92 groupId: navItem.id,
@@ -95,9 +102,11 @@ export struct BottomNavigationComponent { @@ -95,9 +102,11 @@ export struct BottomNavigationComponent {
95 } 102 }
96 } 103 }
97 .tabBar(this.tabBarBuilder(navItem, index)) 104 .tabBar(this.tabBarBuilder(navItem, index))
  105 + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
98 }); 106 });
99 107
100 } 108 }
  109 + .scrollable(false)
101 .animationDuration(0) 110 .animationDuration(0)
102 .barHeight($r('app.float.bottom_navigation_barHeight')) 111 .barHeight($r('app.float.bottom_navigation_barHeight'))
103 .barMode(BarMode.Fixed) 112 .barMode(BarMode.Fixed)
@@ -115,7 +124,12 @@ export struct BottomNavigationComponent { @@ -115,7 +124,12 @@ export struct BottomNavigationComponent {
115 Stack({ alignContent: Alignment.Bottom }) { 124 Stack({ alignContent: Alignment.Bottom }) {
116 Image(this.currentNavIndex === index ? navItem.iconC : navItem.icon) 125 Image(this.currentNavIndex === index ? navItem.iconC : navItem.icon)
117 .height(CommonConstants.FULL_PARENT) 126 .height(CommonConstants.FULL_PARENT)
118 - .padding({ bottom: 15, left: 10, right: 10, top: 2 }) 127 + .padding({
  128 + bottom: 15,
  129 + left: 10,
  130 + right: 10,
  131 + top: 2
  132 + })
119 .aspectRatio(this.ASPECT_RATIO_1_1) 133 .aspectRatio(this.ASPECT_RATIO_1_1)
120 134
121 Text(navItem.name) 135 Text(navItem.name)
@@ -130,13 +144,13 @@ export struct BottomNavigationComponent { @@ -130,13 +144,13 @@ export struct BottomNavigationComponent {
130 .hoverEffect(HoverEffect.Highlight) 144 .hoverEffect(HoverEffect.Highlight)
131 .onClick(() => { 145 .onClick(() => {
132 Logger.info(TAG, `onChange, index: ${index}`); 146 Logger.info(TAG, `onChange, index: ${index}`);
133 - this.onBottomNavigationIndexChange(navItem,index) 147 + this.onBottomNavigationIndexChange(navItem, index)
134 }) 148 })
135 149
136 } 150 }
137 151
138 // 底导切换函数 152 // 底导切换函数
139 - async onBottomNavigationIndexChange(navItem:BottomNavDTO,index:number) { 153 + async onBottomNavigationIndexChange(navItem: BottomNavDTO, index: number) {
140 Logger.info(TAG, `onBottomNavigationIndexChange this.currentNavIndex: ${this.currentNavIndex}`); 154 Logger.info(TAG, `onBottomNavigationIndexChange this.currentNavIndex: ${this.currentNavIndex}`);
141 if (navItem.name === '我的') { 155 if (navItem.name === '我的') {
142 this.barBackgroundColor = Color.White 156 this.barBackgroundColor = Color.White
@@ -154,8 +168,9 @@ export struct BottomNavigationComponent { @@ -154,8 +168,9 @@ export struct BottomNavigationComponent {
154 168
155 // 请求顶导数据(参数): 169 // 请求顶导数据(参数):
156 } 170 }
  171 +
157 //请求顶导数据 172 //请求顶导数据
158 - async getTopNavList(id:number){ 173 + async getTopNavList(id: number) {
159 let bottomNavDetail = await PageViewModel.getBottomNavDetailData(id) 174 let bottomNavDetail = await PageViewModel.getBottomNavDetailData(id)
160 this.topNavList = bottomNavDetail?.topNavChannelList || [] 175 this.topNavList = bottomNavDetail?.topNavChannelList || []
161 } 176 }
1 import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean'; 1 import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean';
2 -import { LazyDataSource, Logger,SPHelper } from 'wdKit'; 2 +import { LazyDataSource, Logger, SPHelper } from 'wdKit';
3 import { SpConstants } from 'wdConstant'; 3 import { SpConstants } from 'wdConstant';
4 import { ProcessUtils } from 'wdRouter'; 4 import { ProcessUtils } from 'wdRouter';
5 import { PageComponent } from './PageComponent'; 5 import { PageComponent } from './PageComponent';
@@ -31,13 +31,13 @@ export struct TopNavigationComponent { @@ -31,13 +31,13 @@ export struct TopNavigationComponent {
31 @Consume isLayoutFullScreen: boolean 31 @Consume isLayoutFullScreen: boolean
32 @Consume bottomRectHeight: number 32 @Consume bottomRectHeight: number
33 @Consume topRectHeight: number 33 @Consume topRectHeight: number
34 - @Consume @Watch('topOrBottomNavChange') currentBottomNavInfo: BottomNavDTO // 当前底导信息 34 + @Consume currentBottomNavInfo: BottomNavDTO // 当前底导信息
35 @Consume barBackgroundColor: Color 35 @Consume barBackgroundColor: Color
36 @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 36 @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
37 @State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 37 @State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
38 @Link _currentNavIndex?: number; 38 @Link _currentNavIndex?: number;
39 // 顶导当前选中/焦点下标 39 // 顶导当前选中/焦点下标
40 - @State @Watch('topOrBottomNavChange') currentTopNavSelectedIndex: number = 0; 40 + @State currentTopNavSelectedIndex: number = 0;
41 @State currentTopNavName: string = ''; 41 @State currentTopNavName: string = '';
42 // 顶导数据 42 // 顶导数据
43 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] 43 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = []
@@ -68,20 +68,6 @@ export struct TopNavigationComponent { @@ -68,20 +68,6 @@ export struct TopNavigationComponent {
68 private tabsWidth: number = 0 68 private tabsWidth: number = 0
69 //定时器延时处理切换至版面、播报tab时 返回上一个tab 69 //定时器延时处理切换至版面、播报tab时 返回上一个tab
70 @State tabTimmer: number = 0 70 @State tabTimmer: number = 0
71 - topOrBottomNavChange() {  
72 - if (this.currentBottomNavName === this.currentBottomNavInfo?.name) {  
73 - this.setBarBackgroundColor()  
74 - }  
75 - }  
76 -  
77 - setBarBackgroundColor() {  
78 - console.error('setBarBackgroundColor', this.currentTopNavName, this.currentBottomNavInfo?.name)  
79 - if (this.currentTopNavName === '视频' && this.currentBottomNavInfo?.name === '视频') {  
80 - this.barBackgroundColor = Color.Black  
81 - } else {  
82 - this.barBackgroundColor = Color.White  
83 - }  
84 - }  
85 71
86 //处理新闻tab顶导频道数据 72 //处理新闻tab顶导频道数据
87 topNavListHandle() { 73 topNavListHandle() {
@@ -129,7 +115,7 @@ export struct TopNavigationComponent { @@ -129,7 +115,7 @@ export struct TopNavigationComponent {
129 item.myChannel = '1' 115 item.myChannel = '1'
130 } 116 }
131 if (item.channelType === 2) { 117 if (item.channelType === 2) {
132 - if(cityName.includes(item.name)){ 118 + if (cityName.includes(item.name)) {
133 item.myChannel = '1' 119 item.myChannel = '1'
134 } 120 }
135 item.localChannel = '1' 121 item.localChannel = '1'
@@ -158,8 +144,8 @@ export struct TopNavigationComponent { @@ -158,8 +144,8 @@ export struct TopNavigationComponent {
158 144
159 }) 145 })
160 146
161 - if(cityName){  
162 - let index = _myChannelList.findIndex(ele=> cityName.includes(ele.name)) 147 + if (cityName) {
  148 + let index = _myChannelList.findIndex(ele => cityName.includes(ele.name))
163 const localChannelitem = _myChannelList.splice(index, 1)[0]; 149 const localChannelitem = _myChannelList.splice(index, 1)[0];
164 // 将当前地区频道插入到第四个 150 // 将当前地区频道插入到第四个
165 _myChannelList.splice(3, 0, localChannelitem); 151 _myChannelList.splice(3, 0, localChannelitem);
@@ -170,9 +156,10 @@ export struct TopNavigationComponent { @@ -170,9 +156,10 @@ export struct TopNavigationComponent {
170 156
171 // 崩溃 157 // 崩溃
172 // this.currentTopNavName = this._currentNavIndex === 0 ? this.myChannelList[0].name : this.topNavList[0].name 158 // this.currentTopNavName = this._currentNavIndex === 0 ? this.myChannelList[0].name : this.topNavList[0].name
173 - if (this._currentNavIndex === 0 && this.myChannelList && this.myChannelList.length > 0 && this.myChannelList[0].name) {  
174 - this.currentTopNavName = this.myChannelList[0].name  
175 - }else if(this._currentNavIndex != 0 && this.topNavList && this.topNavList.length > 0 && this.topNavList[0].name){ 159 + if (this._currentNavIndex === 0 && this.myChannelList && this.myChannelList.length > 0 &&
  160 + this.myChannelList[0].name) {
  161 + this.currentTopNavName = this.myChannelList[0].name
  162 + } else if (this._currentNavIndex != 0 && this.topNavList && this.topNavList.length > 0 && this.topNavList[0].name) {
176 this.currentTopNavName = this.topNavList[0].name 163 this.currentTopNavName = this.topNavList[0].name
177 } 164 }
178 165
@@ -241,15 +228,7 @@ export struct TopNavigationComponent { @@ -241,15 +228,7 @@ export struct TopNavigationComponent {
241 ForEach(this.currentBottomNavName === '新闻' ? this.myChannelList : this.topNavList, 228 ForEach(this.currentBottomNavName === '新闻' ? this.myChannelList : this.topNavList,
242 (navItem: TopNavDTO, index: number) => { 229 (navItem: TopNavDTO, index: number) => {
243 TabContent() { 230 TabContent() {
244 - if (this.currentBottomNavName === '视频' && navItem.name === '视频') {  
245 - VideoChannelDetail({  
246 - bottomNavIndex: $_currentNavIndex,  
247 - topNavIndex: $currentTopNavSelectedIndex,  
248 - groupId: this.groupId + '',  
249 - pageId: navItem.pageId + '',  
250 - channelId: navItem.channelId + '',  
251 - })  
252 - } else if (this.currentBottomNavName === '人民号' && navItem.name === '关注') { 231 + if (this.currentBottomNavName === '人民号' && navItem.name === '关注') {
253 PeopleShipMainComponent({ 232 PeopleShipMainComponent({
254 currentTopNavSelectedIndex: $currentTopNavSelectedIndex, 233 currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
255 navIndex: index, 234 navIndex: index,
@@ -265,7 +244,7 @@ export struct TopNavigationComponent { @@ -265,7 +244,7 @@ export struct TopNavigationComponent {
265 channelId: navItem.channelId + '', 244 channelId: navItem.channelId + '',
266 autoRefresh: this.autoRefresh2Page 245 autoRefresh: this.autoRefresh2Page
267 }) 246 })
268 - }else{ 247 + } else {
269 channelSkeleton() 248 channelSkeleton()
270 } 249 }
271 } 250 }
@@ -283,7 +262,7 @@ export struct TopNavigationComponent { @@ -283,7 +262,7 @@ export struct TopNavigationComponent {
283 }) 262 })
284 .animationDuration(this.animationDuration) 263 .animationDuration(this.animationDuration)
285 .onChange((index: number) => { 264 .onChange((index: number) => {
286 - if(this.tabTimmer){ 265 + if (this.tabTimmer) {
287 clearTimeout(this.tabTimmer) 266 clearTimeout(this.tabTimmer)
288 } 267 }
289 this.currentTopNavName = 268 this.currentTopNavName =
@@ -356,7 +335,7 @@ export struct TopNavigationComponent { @@ -356,7 +335,7 @@ export struct TopNavigationComponent {
356 this.tabsController.changeIndex(index) 335 this.tabsController.changeIndex(index)
357 } 336 }
358 }) 337 })
359 - }else { 338 + } else {
360 Row() { 339 Row() {
361 Image($r('app.media.icon_search')) 340 Image($r('app.media.icon_search'))
362 .width('24vp') 341 .width('24vp')
@@ -375,24 +354,13 @@ export struct TopNavigationComponent { @@ -375,24 +354,13 @@ export struct TopNavigationComponent {
375 } 354 }
376 } 355 }
377 356
378 - /**  
379 - * TODO:根据顶导配置获取颜色展示效果不对,待确认  
380 - */  
381 - getTopNavFontColor(item: TopNavDTO, index: number): Color | string {  
382 - if (item.name === '视频' && this.currentBottomNavInfo.name === '视频') {  
383 - return this.currentTopNavSelectedIndex === index ? Color.White : '#e5e0e0'  
384 - } else {  
385 - return this.currentTopNavSelectedIndex === index ? Color.Black : "#999999"  
386 - }  
387 - }  
388 -  
389 @Builder 357 @Builder
390 tabBarBuilder(item: TopNavDTO, index: number) { 358 tabBarBuilder(item: TopNavDTO, index: number) {
391 Column() { 359 Column() {
392 Text(item.name) 360 Text(item.name)
393 .fontSize($r('app.float.selected_text_size')) 361 .fontSize($r('app.float.selected_text_size'))
394 .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal) 362 .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal)
395 - .fontColor(this.getTopNavFontColor(item, index)) 363 + .fontColor(this.currentTopNavSelectedIndex === index ? Color.Black : "#999999")
396 .padding({ top: $r('app.float.top_tab_item_padding_top'), bottom: $r('app.float.top_tab_item_padding_bottom') }) 364 .padding({ top: $r('app.float.top_tab_item_padding_top'), bottom: $r('app.float.top_tab_item_padding_bottom') })
397 .maxLines(this.MAX_LINE) 365 .maxLines(this.MAX_LINE)
398 .id(index.toString()) 366 .id(index.toString())
@@ -434,7 +402,6 @@ export struct TopNavigationComponent { @@ -434,7 +402,6 @@ export struct TopNavigationComponent {
434 aboutToAppear() { 402 aboutToAppear() {
435 //处理新闻tab顶导频道数据 403 //处理新闻tab顶导频道数据
436 this.topNavListHandle() 404 this.topNavListHandle()
437 - this.setBarBackgroundColor()  
438 } 405 }
439 406
440 aboutToDisappear() { 407 aboutToDisappear() {
  1 +/**
  2 + * 视频频道,包含视频和直播
  3 + * 视频为沉浸式,直播同新闻页面
  4 + */
  5 +import { BottomNavDTO, TopNavDTO } from 'wdBean/Index'
  6 +import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index';
  7 +import { PageComponent } from './PageComponent';
  8 +
  9 +const TAG = 'VideoChannelPage'
  10 +
  11 +@Component
  12 +export struct VideoChannelPage {
  13 + readonly MAX_LINE: number = 1;
  14 + private groupId: number = 0
  15 + private swiperController: SwiperController = new SwiperController()
  16 + @Prop topNavList: TopNavDTO[]
  17 + @Link _currentNavIndex?: number;
  18 + @Consume barBackgroundColor: Color
  19 + @Consume @Watch('setBarBackgroundColor') currentBottomNavInfo: BottomNavDTO // 当前底导信息
  20 + @State @Watch('setBarBackgroundColor') currentTopNavSelectedIndex: number = 0;
  21 + @State animationDuration: number = 0
  22 + @State indicatorLeftMargin: number = 0
  23 + @State indicatorWidth: number = 0
  24 + // 传递给page的自动刷新通知
  25 + @State autoRefresh2Page: number = 0
  26 +
  27 + aboutToAppear(): void {
  28 + this.setBarBackgroundColor()
  29 + console.log(TAG, 'aboutToAppear')
  30 + }
  31 +
  32 + /**
  33 + * 顶导、底导切换下标都到改变背景色,进入或退出沉浸式
  34 + */
  35 + setBarBackgroundColor() {
  36 + if (this.currentTopNavSelectedIndex === 0 && this.currentBottomNavInfo?.name === '视频') {
  37 + console.error('setBarBackgroundColor', '黑色')
  38 + this.barBackgroundColor = Color.Black
  39 + } else {
  40 + this.barBackgroundColor = Color.White
  41 + console.error('setBarBackgroundColor', '白色')
  42 + }
  43 + }
  44 +
  45 + /**
  46 + * TODO:根据顶导配置获取颜色展示效果不对,待确认
  47 + */
  48 + getTopNavFontColor(item: TopNavDTO, index: number): Color | string {
  49 + if (item.name === '视频' && this.currentBottomNavInfo.name === '视频') {
  50 + return this.currentTopNavSelectedIndex === index ? Color.White : '#e5e0e0'
  51 + } else {
  52 + return this.currentTopNavSelectedIndex === index ? Color.Black : "#999999"
  53 + }
  54 + }
  55 +
  56 + build() {
  57 + Stack() {
  58 + this.pageSwiperView()
  59 + this.topNavView()
  60 + }
  61 + .width('100%')
  62 + .height('100%')
  63 + .align(Alignment.Top)
  64 + }
  65 +
  66 + @Builder
  67 + topNavView() {
  68 + Row() {
  69 + ForEach(this.topNavList, (item: TopNavDTO, index: number) => {
  70 + Column() {
  71 + Text(item.name)
  72 + .fontSize($r('app.float.selected_text_size'))
  73 + .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal)
  74 + .fontColor(this.getTopNavFontColor(item, index))
  75 + .padding({
  76 + top: $r('app.float.top_tab_item_padding_top'),
  77 + bottom: $r('app.float.top_tab_item_padding_bottom')
  78 + })
  79 + .maxLines(this.MAX_LINE)
  80 +
  81 + Row()
  82 + .width(20)
  83 + .height(3)
  84 + .backgroundImage($r('app.media.icon_channel_active'), ImageRepeat.NoRepeat)
  85 + .backgroundImageSize(ImageSize.Contain)
  86 + .visibility(this.currentTopNavSelectedIndex === index ? Visibility.Visible : Visibility.Hidden)
  87 +
  88 + }
  89 + .padding({
  90 + left: $r('app.float.top_tab_item_padding_horizontal'),
  91 + right: $r('app.float.top_tab_item_padding_horizontal'),
  92 + })
  93 + .onClick(() => {
  94 + this.currentTopNavSelectedIndex = index
  95 + this.swiperController.changeIndex(index, true)
  96 + })
  97 + }, (item: TopNavDTO) => item.channelId + '')
  98 + }
  99 + .width('100%')
  100 + .justifyContent(FlexAlign.Center)
  101 + .backgroundColor(this.currentTopNavSelectedIndex === 0 ? Color.Transparent : Color.White)
  102 + }
  103 +
  104 + @Builder
  105 + pageSwiperView() {
  106 + Swiper(this.swiperController) {
  107 + ForEach(this.topNavList, (item: TopNavDTO, index: number) => {
  108 + if (index == 0) {
  109 + // 视频
  110 + VideoChannelDetail({
  111 + bottomNavIndex: $_currentNavIndex,
  112 + topNavIndex: $currentTopNavSelectedIndex,
  113 + groupId: this.groupId + '',
  114 + pageId: item.pageId + '',
  115 + channelId: item.channelId + '',
  116 + })
  117 + } else {
  118 + // 直播
  119 + PageComponent({
  120 + currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
  121 + navIndex: index,
  122 + pageId: item.pageId + '',
  123 + channelId: item.channelId + '',
  124 + autoRefresh: this.autoRefresh2Page
  125 + }).margin({ top: 40 })
  126 + }
  127 + }, (item: TopNavDTO) => item.channelId + '')
  128 + }
  129 + .indicator(false)
  130 + .loop(false)
  131 + .width('100%')
  132 + .height('100%')
  133 + .cachedCount(3)
  134 + .displayCount(1, true)
  135 + .alignSelf(ItemAlign.Start)
  136 + .onChange((index: number) => {
  137 + this.currentTopNavSelectedIndex = index
  138 + })
  139 + }
  140 +}