fnUtils.ts
1.54 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
// 将后端返回的字段转换成树组件的ApiSelectTree的对应字段
export const copyTransFun = (arr: any[]) => {
arr.forEach((item) => {
if (item.name) {
item.label = item.name;
delete item.name;
}
if (item.id) {
item.value = item.id;
delete item.id;
}
if (item.children) {
if (item.children.length) {
copyTransFun(item.children);
}
}
});
};
// 将后端返回的字段转换成树组件的Tree的对应字段
export const copyTransTreeFun = (arr: any[]) => {
arr.forEach((item) => {
if (item.name) {
item.title = item.name;
delete item.name;
}
if (item.id) {
item.key = item.id;
delete item.id;
}
if (item.children) {
if (item.children.length) {
copyTransTreeFun(item.children);
}
}
});
};
// 百度地图url
const ak = '7uOPPyAHn2Y2ZryeQqHtcRqtIY374vKa';
const register_BAI_DU_MAP_URL = (ak: string) => {
return `https://api.map.baidu.com/getscript?v=3.0&ak=${ak}`;
};
const registerBaiDuMapGlLib = (ak: string) => {
return `//api.map.baidu.com/getscript?type=webgl&v=1.0&ak=${ak}&services=&t=${Date.now()}`;
};
export const BAI_DU_MAP_TRACK_ANIMATION =
'//mapopen.bj.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.js';
export const BAI_DU_MAP_GL_LIB = registerBaiDuMapGlLib(ak);
export const BAI_DU_MAP_URL = register_BAI_DU_MAP_URL(ak);
// 数字加上每三位加上逗号
export function toThousands(num) {
return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
}