index.js
1.84 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
// 代码生成器数据匹配
export function dynamicText(value, options) {
if (!value) return ''
if (Array.isArray(value)) {
if (!options || !Array.isArray(options)) return value.join()
let textList = []
for (let i = 0; i < value.length; i++) {
let item = options.filter(o => o.id == value[i])[0]
if (!item || !item.fullName) {
textList.push(value[i])
} else {
textList.push(item.fullName)
}
}
return textList.join()
}
if (!options || !Array.isArray(options)) return value
let item = options.filter(o => o.id == value)[0]
if (!item || !item.fullName) return value
return item.fullName
}
export function dynamicTreeText(value, options) {
if (!value) return ''
function transfer(data) {
let textList = []
function loop(data, id) {
for (let i = 0; i < data.length; i++) {
if (data[i].id === id) {
textList.push(data[i].fullName)
break
}
if (data[i].children) loop(data[i].children, id)
}
}
for (let i = 0; i < data.length; i++) {
loop(options, data[i])
}
return textList.join()
}
if (!options || !Array.isArray(options)) return value.join()
if (Array.isArray(value)) {
let text = transfer(value)
return text
} else {
if (!options || !Array.isArray(options)) return value
let list = value.split()
let text = transfer(list)
return text
}
}
export function toDate(data, options) {
if (!data) return ''
try{
data = String(data).length <= 10 ? data * 1000 : data;
const t = new Date(data);
const Y = t.getFullYear().toString().padStart(2,0);
const M = (t.getMonth()+1).toString().padStart(2,0);
const D = t.getDate().toString().padStart(2,0);
const h = t.getHours().toString().padStart(2,0);
const m = t.getMinutes().toString().padStart(2,0);
const s = t.getSeconds().toString().padStart(2,0);
return Y +'-'+ M +'-'+ D ;//+' '+h+':'+m
}catch(e){}
return '';
}