DetailPlayLivePage.ets
3.89 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
import { Action, LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import { TabComponent } from '../widgets/details/TabComponent';
import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
import router from '@ohos.router';
import { DisplayDirection } from 'wdConstant/Index';
import mediaquery from '@ohos.mediaquery';
import { Logger, WindowModel } from 'wdKit/Index';
import { window } from '@kit.ArkUI';
import { devicePLSensorManager } from 'wdDetailPlayApi/Index';
import { LiveCommentComponent } from 'wdComponent/Index';
@Entry
@Component
export struct DetailPlayLivePage {
//横竖屏,默认竖屏
@Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL
TAG: string = 'DetailPlayLivePage';
liveViewModel: LiveViewModel = new LiveViewModel()
@State relId: string = ''
@State contentId: string = ''
@State relType: string = ''
@Provide liveDetailsBean: LiveDetailsBean = {} as LiveDetailsBean
@Provide liveRoomDataBean: LiveRoomDataBean = {} as LiveRoomDataBean
@State tabs: string[] = []
aboutToAppear(): void {
//监听屏幕横竖屏变化
let listener = mediaquery.matchMediaSync('(orientation: landscape)');
listener.on("change", (mediaQueryResult) => {
Logger.info(this.TAG, `change;${mediaQueryResult.matches}`)
if (mediaQueryResult.matches) {
this.displayDirection = DisplayDirection.VIDEO_HORIZONTAL
} else {
this.displayDirection = DisplayDirection.VERTICAL
}
// WindowModel.shared.setMainWindowFullScreen(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL)
})
let par: Action = router.getParams() as Action;
let params = par?.params;
this.relId = params?.extra?.relId || '';
this.relType = params?.extra?.relType || '';
this.contentId = params?.contentID || '';
this.getLiveDetails()
this.getLiveRoomData()
}
build() {
Column() {
TopPlayComponent()
.layoutWeight(211)
TabComponent({ tabs: this.tabs })
.layoutWeight(503)
.visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
LiveCommentComponent({ heartNum: this.liveRoomDataBean.likeNum })
.visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
}
.height('100%')
.width('100%')
}
onPageShow(): void {
WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
}
onPageHide(): void {
devicePLSensorManager.devicePLSensorOff();
WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
}
getLiveDetails() {
this.liveViewModel.getLiveDetails(this.contentId, this.relId, this.relType)
.then(
(data) => {
if (data.length > 0) {
if (data[0].liveInfo?.liveState == 'wait') {
this.tabs = ['简介', '直播间', '大家聊']
} else {
this.tabs = ['直播间', '大家聊']
}
this.liveDetailsBean = data[0]
}
},
() => {
})
}
getLiveRoomData() {
this.liveViewModel.getLiveRoomData(this.contentId)
.then(
(data) => {
this.liveRoomDataBean = data
},
() => {
})
}
aboutToDisappear(): void {
}
onBackPress(): boolean | void {
if (this.displayDirection == DisplayDirection.VERTICAL) {
router.back()
} else {
this.displayDirection = DisplayDirection.VERTICAL
}
WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
window.Orientation.PORTRAIT :
window.Orientation.LANDSCAPE)
devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
window.Orientation.PORTRAIT :
window.Orientation.LANDSCAPE);
return true
}
}