CommonUtils.ets
1.34 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
import { ALL, ImageKnifeOption } from '@ohos/imageknife';
import { TopNavDTO } from 'wdBean/Index';
/**
* 通用工具类,只记录处理build里面组件业务计算逻辑
*/
export class CommonUtils{
/**
* 获取顶部导航栏的频道option
* @param item
* @param isSelect
* @returns
*/
public static getTopImageKnifeOption(item: TopNavDTO, isSelect: boolean): ImageKnifeOption {
// let defaultIcon = this.getBottomLocalIcon(navItem, isSelect)
let url = isSelect ? item.iconCUrl:item.iconUrl // this.getBottomIcon(navItem, isSelect)
let imageKnifeOption: ImageKnifeOption = {
loadSrc: url,
// // 占位图使用本地资源
// placeholderSrc: defaultIcon,
// // 失败占位图使用本地资源
// errorholderSrc: defaultIcon,
// 是否开启一级内存缓存
isCacheable: true,
// 磁盘缓存
strategy: new ALL(),
gif: {
playTimes: 1
}
};
return imageKnifeOption
}
/**
* 计算 频道tab 宽度
* @param height 已知高度
* @returns
*/
public static calTopTabWidth(height:number,scale:string):number{
if(scale){
if(scale.includes('*')){
let scaleArray = scale.split('*');
return height*Number.parseInt(scaleArray[0])/parseInt(scaleArray[1])
}
}
return height*210/60
}
}