PageUtils.ets
5.2 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { ArrayUtils, Logger } from 'wdKit';
import { CompDTO } from '../bean/CompDTO';
import { ExtraDTO } from '../bean/ExtraDTO';
import { LabelDTO } from '../bean/LabelDTO';
import { Pic } from '../bean/Pic';
import { ProgrammeBean } from '../bean/ProgrammeBean';
const TAG = "PageUtils";
export class PageUtils {
/**
* 选择图片
* @param data
* @param isUseVerticalImage 是否竖图;true是竖图,否则是横图
* @param isUseHighImage,是否高清,true是高清,否则不是高清
* @returns
*/
static imgUrlChoose(pics: Pic | undefined, isUseVerticalImage: boolean, isUseHighImage: boolean): string {
if (!pics) {
return "";
}
if (isUseVerticalImage) {
if (isUseHighImage) {
if (pics.highResolutionV) {
return pics.highResolutionV;
} else if (pics.lowResolutionV) {
return pics.lowResolutionV;
}
} else {
if (pics.lowResolutionV) {
return pics.lowResolutionV;
} else if (pics.highResolutionV) {
return pics.highResolutionV;
}
}
} else {
if (isUseHighImage) {
if (pics.highResolutionH) {
return pics.highResolutionH;
} else if (pics.lowResolutionH) {
return pics.lowResolutionH;
}
} else {
if (pics.lowResolutionH) {
return pics.lowResolutionH;
} else if (pics.highResolutionH) {
return pics.highResolutionH;
}
}
}
return pics.gkResolution1 ?? "";
}
/**
* 获取Label标题
*
* @param component 组件bean
* @return Label标题
*/
static getLabelTitle(componentBean: CompDTO): string {
if (!componentBean) {
return ""
}
let extraData: ExtraDTO | undefined = componentBean.extraData;
if (!extraData) {
return ""
}
if (!extraData.labels) {
Logger.info(TAG, 'getLabelTitle, labels is null');
return ""
}
for (let index = 0; index < extraData.labels?.length; index++) {
let label: LabelDTO = ArrayUtils.getListElement(extraData.labels, index)
if (!label) {
// Logger.info(TAG, 'getLabelTitle, labels is null');
continue;
}
if (label.isShow != undefined && label.isShow == false) {
// Logger.info(TAG, 'getLabelTitle, isShow is false');
continue;
}
if (label.label == '主标题') {
return label.title ?? ""
}
}
return "";
}
/**
* 选择图片
* @param data
* @param isUseVerticalImage 是否竖图;true是竖图,否则是横图
* @param isUseHighImage,是否高清,true是高清,否则不是高清
* @returns
*/
static chooseImgUrl(item: ProgrammeBean, isUseVerticalImage: boolean, isUseHighImage: boolean): string {
if (!item) {
return "";
}
if (item.programs && item.programs.length > 0) {
return PageUtils.imgUrlChoose(item.programs[0].pics, isUseVerticalImage, isUseHighImage)
} else {
return PageUtils.imgUrlChoose(item.pics, isUseVerticalImage, isUseHighImage)
}
}
static getProgramName(item: ProgrammeBean): string {
if (!item) {
return "";
}
if (item.programs && item.programs.length > 0 && item.programs[0].name) {
return item.programs[0].name
}
return item.name ?? "";
}
static getProgramTitle(item: ProgrammeBean): string {
if (!item) {
return "";
}
if (item.programs && item.programs.length > 0 && item.programs[0].title) {
return item.programs[0].title
}
return item.title ?? "";
}
private static readonly TIP_LIVE: string = "LIVE"; // 直播
// 获取右上角角标
static getTopRightTipImgUrl(bean: ProgrammeBean): string | undefined {
if (!bean) {
return undefined;
}
let tipCode: string | undefined = undefined
if (bean.programTypeV2 == PageUtils.TIP_LIVE) {
if (bean.strategyTipMap?.CHARGE?.code) {
tipCode = bean.strategyTipMap?.CHARGE?.code
} else if (bean.startTime == '0' || bean.endTime == '0') {
tipCode = bean.showTip?.code ? bean.showTip?.code : bean.tip?.code
} else {
// todo:
}
} else if (bean.tip?.code || bean.showTip?.code) {
tipCode = bean.showTip?.code ? bean.showTip?.code : bean.tip?.code
} else {
}
return PageUtils.getTipImgUrl(tipCode)
}
// 获取左上角角标
static getTopLeftTipImgUrl(bean: ProgrammeBean): string | undefined {
return PageUtils.getTipImgUrl(bean?.tip2?.code)
}
static getTipImgUrl(tipCode: string | undefined, isSetBStyle?: boolean): string | undefined {
// todo
return undefined
}
/**
* 获取评分的整数部分
* @param score
* @returns 整数部分
*/
static getScoreInteger(score: string): string {
if (!score) {
return '';
}
let dotIndex: number = score.indexOf(".");
dotIndex = dotIndex > 0 ? dotIndex : 0;
return score.substring(0, dotIndex)
}
/**
* 获取评分的小数部分
* @param score
* @returns 小数部分
*/
static getScoreDecimal(score: string): string {
if (!score) {
return '';
}
let dotIndex: number = score.indexOf(".");
dotIndex = dotIndex > 0 ? dotIndex : 0;
return score.substring(dotIndex, score.length)
}
}