-
Notifications
You must be signed in to change notification settings - Fork 655
/
Copy pathindex.js
100 lines (86 loc) · 2.7 KB
/
index.js
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
import Utils from '../util/util'
/*
* 全局的过滤函数
* */
export function checkAddZone(num) {
return num < 10 ? `0${num.toString()}` : num
}
export const filters = {
filterAddress(value) {
// 过滤地址
if (!value) return value
const obj = value
return `${obj.provinceName}${obj.cityName}${obj.countyName} ${obj.detailInfo}`
},
filterTime(value) {
// 过滤时间戳,返回值yyyy-mm-dd
if (!value) {
return value
}
const date = new Date(value * 1000)
const y = 1900 + date.getYear()
const m = `0${date.getMonth() + 1}`
const d = `0${date.getDate()}`
const val = `${y}-${m.substring(m.length - 2, m.length)}-${d.substring(d.length - 2, d.length)}`
return val
},
filterTimeYmdHms(value) {
// 过滤时间戳,返回值yyyy-mm-dd ss
if (!value) {
return value
}
const date = new Date(value * 1000)
const y = 1900 + date.getYear()
const m = `0${date.getMonth() + 1}`
const d = `0${date.getDate()}`
const hh = date.getHours()
const mm = `${date.getMinutes()}`
const ss = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds()
const val = `${y}-${m.substring(m.length - 2, m.length)}-${d.substring(d.length - 2, d.length)} ${hh}:${mm}:${ss}`
return val
},
filterTimeYear(value) {
// 过滤时间戳, 返回值 今年:mm-dd 往年:yyyy-mm-dd
const jy = 1900 + new Date().getYear()
const date = new Date(value * 1000)
const y = 1900 + date.getYear()
const m = `0${date.getMonth() + 1}`
const d = `0${date.getDate()}`
const val = `${y}-${m.substring(m.length - 2, m.length)}-${d.substring(d.length - 2, d.length)}`
const thisYear = `${m.substring(m.length - 2, m.length)}-${d.substring(d.length - 2, d.length)}`
if (jy === y) {
return thisYear
}
return val
},
dateFormatter(nows) {
if (!nows) return ''
const now = new Date(nows)
const year = now.getFullYear()
let month = now.getMonth() + 1
month = checkAddZone(month)
let date = now.getDate()
date = checkAddZone(date)
return `${year}-${month}-${date}`
},
dateTimeFormatter(t) {
if (!t) return ''
t = new Date(t).getTime() // eslint-disable-line
t = new Date(t) // eslint-disable-line
const year = t.getFullYear()
let month = t.getMonth() + 1
month = checkAddZone(month)
let date = t.getDate()
date = checkAddZone(date)
let hour = t.getHours()
hour = checkAddZone(hour)
let min = t.getMinutes()
min = checkAddZone(min)
let se = t.getSeconds()
se = checkAddZone(se)
return `${year}-${month}-${date} ${hour}:${min}:${se}`
},
filterTitle(value, len = 9) {
return Utils.cutString(value, len)
},
}