1
+ // set function parseTime,formatTime to filter
2
+ export { parseTime , formatTime } from '@/utils'
3
+
1
4
function pluralize ( time , label ) {
2
5
if ( time === 1 ) {
3
6
return time + label
@@ -16,67 +19,8 @@ export function timeAgo(time) {
16
19
}
17
20
}
18
21
19
- export function parseTime ( time , cFormat ) {
20
- if ( arguments . length === 0 ) {
21
- return null
22
- }
23
-
24
- if ( ( time + '' ) . length === 10 ) {
25
- time = + time * 1000
26
- }
27
-
28
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
29
- let date
30
- if ( typeof time === 'object' ) {
31
- date = time
32
- } else {
33
- date = new Date ( parseInt ( time ) )
34
- }
35
- const formatObj = {
36
- y : date . getFullYear ( ) ,
37
- m : date . getMonth ( ) + 1 ,
38
- d : date . getDate ( ) ,
39
- h : date . getHours ( ) ,
40
- i : date . getMinutes ( ) ,
41
- s : date . getSeconds ( ) ,
42
- a : date . getDay ( )
43
- }
44
- const time_str = format . replace ( / { ( y | m | d | h | i | s | a ) + } / g, ( result , key ) => {
45
- let value = formatObj [ key ]
46
- if ( key === 'a' ) return [ '一' , '二' , '三' , '四' , '五' , '六' , '日' ] [ value - 1 ]
47
- if ( result . length > 0 && value < 10 ) {
48
- value = '0' + value
49
- }
50
- return value || 0
51
- } )
52
- return time_str
53
- }
54
-
55
- export function formatTime ( time , option ) {
56
- time = + time * 1000
57
- const d = new Date ( time )
58
- const now = Date . now ( )
59
-
60
- const diff = ( now - d ) / 1000
61
-
62
- if ( diff < 30 ) {
63
- return '刚刚'
64
- } else if ( diff < 3600 ) { // less 1 hour
65
- return Math . ceil ( diff / 60 ) + '分钟前'
66
- } else if ( diff < 3600 * 24 ) {
67
- return Math . ceil ( diff / 3600 ) + '小时前'
68
- } else if ( diff < 3600 * 24 * 2 ) {
69
- return '1天前'
70
- }
71
- if ( option ) {
72
- return parseTime ( time , option )
73
- } else {
74
- return d . getMonth ( ) + 1 + '月' + d . getDate ( ) + '日' + d . getHours ( ) + '时' + d . getMinutes ( ) + '分'
75
- }
76
- }
77
-
78
22
/* 数字 格式化*/
79
- export function nFormatter ( num , digits ) {
23
+ export function numberFormatter ( num , digits ) {
80
24
const si = [
81
25
{ value : 1E18 , symbol : 'E' } ,
82
26
{ value : 1E15 , symbol : 'P' } ,
@@ -93,12 +37,6 @@ export function nFormatter(num, digits) {
93
37
return num . toString ( )
94
38
}
95
39
96
- export function html2Text ( val ) {
97
- const div = document . createElement ( 'div' )
98
- div . innerHTML = val
99
- return div . textContent || div . innerText
100
- }
101
-
102
40
export function toThousandslsFilter ( num ) {
103
41
return ( + num || 0 ) . toString ( ) . replace ( / ^ - ? \d + / g, m => m . replace ( / (? = (? ! \b ) ( \d { 3 } ) + $ ) / g, ',' ) )
104
42
}
0 commit comments