LiveEmptyComponent.ets
3.14 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
import { CommonConstants } from 'wdConstant';
import { Logger } from 'wdKit';
const TAG = 'LiveEmptyComponent';
/**
* WDViewDefaultType 缺省页
*/
export const enum WDLiveViewDefaultType {
/// 1.默认
WDViewDefaultType_Default,
/// 16.直播结束
WDViewDefaultType_NoLiveEnd,
/// 17.直播暂停
WDViewDefaultType_NoLiveSuspend,
}
/**
* 空数据/无数据
*/
@Preview
@Component
export struct LiveEmptyComponent {
// private emptySize: SizeOptions = {};
@State emptyWidth: string | number = CommonConstants.FULL_PARENT;
@State emptyHeight: string | number = CommonConstants.FULL_PARENT;
@State emptyType: number = WDLiveViewDefaultType.WDViewDefaultType_Default; // 缺省图类型,传枚举
@State emptyButton: boolean = false
@State timeNum: number = 10
/**
* The empty image width percentage setting.
*/
readonly EMPTY_IMAGE_WIDTH: string = '15%';
/**
* The empty image height percentage setting.
*/
readonly EMPTY_IMAGE_HEIGHT: string = '15%';
/**
* The empty data text component margin top.
*/
readonly EMPTY_TIP_TEXT_MARGIN_TOP: string = '10';
/**
* The empty data text opacity.
*/
readonly TEXT_OPACITY: number = 0.4;
private timer: number = -1
retry: () => void = () => {
}
onPageHide(): void {
}
aboutToDisappear() {
}
build() {
this.noProgrammeData();
}
/**
* 无数据,空白view组件
*/
@Builder
noProgrammeData() {
Column() {
Image(this.buildNoDataTipImage())
.width(160)
.height(112)
.objectFit(ImageFit.Contain)
// .border({ width: 1, color: Color.Red, radius: 6 })
// .width('this.EMPTY_IMAGE_WIDTH')
// .height(this.EMPTY_IMAGE_HEIGHT)
Text(this.buildNoDataTip())
.fontSize($r('app.float.font_size_14'))
.fontColor('#FF999999')
.fontWeight(FontWeight.Normal)
.opacity(this.TEXT_OPACITY)
.margin({ top: this.EMPTY_TIP_TEXT_MARGIN_TOP })
.onClick((event: ClickEvent) => {
Logger.info(TAG, `noProgrammeData onClick event?.source: ${event.source}`);
})
}
.justifyContent(FlexAlign.Center)
.width(this.emptyWidth)
.height(this.emptyHeight)
// .backgroundColor(Color.Black)
}
buildNoDataTip(): string {
Logger.info(TAG, "buildNoDataTip");
let contentString: string = '暂无内容'
if (this.emptyType === WDLiveViewDefaultType.WDViewDefaultType_NoLiveEnd) {
contentString = '直播已结束' // 前方拥堵,请耐心等待
} else if (this.emptyType === WDLiveViewDefaultType.WDViewDefaultType_NoLiveSuspend) {
contentString = '主播暂时离开,马上回来' // 前方拥堵,请耐心等待
}
return contentString
}
buildNoDataTipImage(): Resource | string {
Logger.info(TAG, "buildNoDataTip");
let imageString: Resource | string = $r('app.media.icon_no_content')
if (this.emptyType === WDLiveViewDefaultType.WDViewDefaultType_NoLiveEnd) {
imageString = $r('app.media.icon_no_end')
} else if (this.emptyType === WDLiveViewDefaultType.WDViewDefaultType_NoLiveSuspend) {
imageString = $r('app.media.icon_no_liver')
}
return imageString
}
}