VideoChannelPage.ets
5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* 视频频道,包含视频和直播
* 视频为沉浸式,直播同新闻页面
*/
import { BottomNavDTO, TopNavDTO } from 'wdBean/Index'
import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index';
import { PageComponent } from './PageComponent';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
const TAG = 'VideoChannelPage'
@Component
export struct VideoChannelPage {
readonly MAX_LINE: number = 1;
private groupId: number = 0
private swiperController: SwiperController = new SwiperController()
// 自动刷新触发(双击tab自动刷新)
@Prop autoRefresh: number = 0
@Prop topNavList: TopNavDTO[]
@Link _currentNavIndex?: number;
@Consume barBackgroundColor: Color
@Consume @Watch('setBarBackgroundColor') currentBottomNavInfo: BottomNavDTO // 当前底导信息
@State @Watch('setBarBackgroundColor') currentTopNavSelectedIndex: number = 0;
@State animationDuration: number = 0
@State indicatorLeftMargin: number = 0
@State indicatorWidth: number = 0
// 传递给page的自动刷新通知
@State autoRefresh2Page: number = 0
aboutToAppear(): void {
this.setBarBackgroundColor()
console.log(TAG, 'aboutToAppear')
}
/**
* 顶导、底导切换下标都到改变背景色,进入或退出沉浸式
*/
setBarBackgroundColor() {
if (this.currentTopNavSelectedIndex === 0 && this.currentBottomNavInfo?.name === '视频') {
console.error('setBarBackgroundColor', '黑色')
this.barBackgroundColor = Color.Black
} else {
this.barBackgroundColor = Color.White
console.error('setBarBackgroundColor', '白色')
}
}
/**
* TODO:根据顶导配置获取颜色展示效果不对,待确认
*/
getTopNavFontColor(item: TopNavDTO, index: number): Color | string {
if (item.name === '视频' && this.currentBottomNavInfo.name === '视频') {
return this.currentTopNavSelectedIndex === index ? Color.White : '#e5e0e0'
} else {
return this.currentTopNavSelectedIndex === index ? Color.Black : "#999999"
}
}
build() {
Stack({ alignContent: Alignment.Top }) {
this.pageSwiperView()
this.topNavView()
}
.width('100%')
.height('100%')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
}
@Builder
topNavView() {
Stack({alignContent: Alignment.TopEnd}) {
Row() {
ForEach(this.topNavList, (item: TopNavDTO, index: number) => {
Column() {
Text(item.name)
.fontSize($r('app.float.selected_text_size'))
.fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal)
.fontColor(this.getTopNavFontColor(item, index))
.padding({
top: $r('app.float.top_tab_item_padding_top'),
bottom: $r('app.float.top_tab_item_padding_bottom')
})
.maxLines(this.MAX_LINE)
Row()
.width(20)
.height(3)
.backgroundImage($r('app.media.icon_channel_active'), ImageRepeat.NoRepeat)
.backgroundImageSize(ImageSize.Contain)
.visibility(this.currentTopNavSelectedIndex === index ? Visibility.Visible : Visibility.Hidden)
}
.padding({
left: $r('app.float.top_tab_item_padding_horizontal'),
right: $r('app.float.top_tab_item_padding_horizontal'),
})
.onClick(() => {
if (this.currentTopNavSelectedIndex === index) {
this.autoRefresh++
}
this.currentTopNavSelectedIndex = index
this.swiperController.changeIndex(index, true)
})
}, (item: TopNavDTO) => item.channelId + '')
}
.width('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor(this.currentTopNavSelectedIndex === 0 ? Color.Transparent : Color.White)
// 搜索按钮
Row() {
Image($r('app.media.icon_search'))
.width('24vp')
.height('24vp')
}
.width('40vp')
.margin({
right: '10vp',
top: '3vp',
})
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.Center)
.onClick(() => {
WDRouterRule.jumpWithPage(WDRouterPage.searchPage)
})
.backgroundColor(Color.Transparent)
}
}
@Builder
pageSwiperView() {
Swiper(this.swiperController) {
ForEach(this.topNavList, (item: TopNavDTO, index: number) => {
if (index == 0) {
// 视频
VideoChannelDetail({
bottomNavIndex: $_currentNavIndex,
topNavIndex: $currentTopNavSelectedIndex,
groupId: this.groupId + '',
pageId: item.pageId + '',
channelId: item.channelId + '',
autoRefresh: this.autoRefresh,
})
} else {
// 直播
PageComponent({
currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
navIndex: index,
pageId: item.pageId + '',
channelId: item.channelId + '',
autoRefresh: this.autoRefresh
}).margin({ top: 40 })
}
}, (item: TopNavDTO) => item.channelId + '')
}
.indicator(false)
.loop(false)
.width('100%')
.height('100%')
.cachedCount(-1)
.displayCount(1, true)
.alignSelf(ItemAlign.Start)
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
.onChange((index: number) => {
this.currentTopNavSelectedIndex = index
})
}
}