filters
Showing
2 changed files
with
35 additions
and
3 deletions
1 | /** | ||
2 | *格式化时间 | ||
3 | *yyyy-MM-dd hh:mm:ss | ||
4 | */ | ||
5 | export function formatDate(time, fmt) { | ||
6 | if (time === undefined || '') { | ||
7 | return | ||
8 | } | ||
9 | const date = new Date(time) | ||
10 | if (/(y+)/.test(fmt)) { | ||
11 | fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) | ||
12 | } | ||
13 | const o = { | ||
14 | 'M+': date.getMonth() + 1, | ||
15 | 'd+': date.getDate(), | ||
16 | 'h+': date.getHours(), | ||
17 | 'm+': date.getMinutes(), | ||
18 | 's+': date.getSeconds() | ||
19 | } | ||
20 | for (const k in o) { | ||
21 | if (new RegExp(`(${k})`).test(fmt)) { | ||
22 | const str = o[k] + '' | ||
23 | fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str)) | ||
24 | } | ||
25 | } | ||
26 | return fmt | ||
27 | } | ||
28 | |||
29 | function padLeftZero(str) { | ||
30 | return ('00' + str).substr(str.length) | ||
31 | } | ||
1 | /* | 32 | /* |
2 | * 隐藏用户手机号中间四位 | 33 | * 隐藏用户手机号中间四位 |
3 | */ | 34 | */ |
4 | export const hidePhone = phone => { | 35 | export function hidePhone(phone) { |
5 | return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') | 36 | return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') |
6 | } | 37 | } | ... | ... |
... | @@ -3,4 +3,5 @@ import * as filter from './filter' | ... | @@ -3,4 +3,5 @@ import * as filter from './filter' |
3 | 3 | ||
4 | Object.keys(filter).forEach(k => Vue.filter(k, filter[k])) | 4 | Object.keys(filter).forEach(k => Vue.filter(k, filter[k])) |
5 | 5 | ||
6 | Vue.prototype.$formatDate = Vue.filter('formatDate') | ||
6 | Vue.prototype.$hidePhone = Vue.filter('hidePhone') | 7 | Vue.prototype.$hidePhone = Vue.filter('hidePhone') | ... | ... |
-
Please register or sign in to post a comment