FuncUtils.ets
1.73 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
/**
* 给函数的执行加上动画
* @param fn:要在动画内执行的回调函数,通常fn里面会改变状态变量
* @param duration:动画持续时长
* @param curve:动画区线
*/
import { ImageViewerConstants } from '../constants/ImageViewerConstants';
import measure from '@ohos.measure'
export function runWithAnimation(
fn: Function,
duration: number = ImageViewerConstants.ANIMATE_DURATION,
curve: Curve = Curve.Smooth): void {
animateTo({ duration: duration, curve: curve }, () => {
fn();
})
}
export function getNotesContentWidth(
newTags: string,
objectType: number | string,
objectLevel: number | string,
fontSize?: string | number | Resource
) {
let textContent: string = returnTypeTitleFn(newTags, objectType, objectLevel)
let px = 0
const paddingRightAndLeft = vp2px(8)
const marginRight = vp2px(6);
if(objectType == '5'){
textContent = returnTypeTitleFn('', objectType, objectLevel)
} else {
textContent = returnTypeTitleFn(newTags)
}
if (textContent) {
px = measure.measureText({
textContent: textContent,
fontSize: fontSize || $r('app.float.font_size_11')
})
}
if (px) {
px = px + paddingRightAndLeft + marginRight
}
return px2vp(px)
}
/**
* 根据接口返回字段显示不同的内容
* @param newTags
* @param objectType
* @param objectLevel
* @returns
*/
export function returnTypeTitleFn(
newTags?: string,
objectType?: number | string,
objectLevel?: number | string
): string {
if (newTags) {
return newTags
}
if (objectType == 5) {
if (objectLevel == 24) {
return '调查'
}
return '专题'
}
if (objectType == 10) {
return 'H5'
}
if (objectType == 8) {
return '文章'
}
return ''
}