b531092f by 宋楠

readme

1 parent 7721bb62
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 [demo](https://solui.cn/vue-h5-template/#/)建议手机端查看 4 [demo](https://solui.cn/vue-h5-template/#/)建议手机端查看
5 5
6 #### 介绍 6 #### 介绍
7 [关于项目介绍](https://segmentfault.com/a/1190000019275330) 7 [关于项目介绍](https://juejin.im/post/5cfefc73f265da1bba58f9f7)
8 8
9 - Vue-cli4 9 - Vue-cli4
10 - VantUI组件按需加载 10 - VantUI组件按需加载
......
1 /** 1 /**
2 *格式化时间 2 *格式化时间
3 *yyyy-MM-dd hh:mm:ss 3 *yyyy-MM-dd hh:mm:ss
4 */ 4 */
5 export function formatDate(time, fmt) { 5 export function formatDate(time, fmt) {
6 if (time === undefined || '') { 6 if (time === undefined || '') {
7 return 7 return
8 } 8 }
9 const date = new Date(time) 9 const date = new Date(time)
10 if (/(y+)/.test(fmt)) { 10 if (/(y+)/.test(fmt)) {
11 fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) 11 fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
12 } 12 }
13 const o = { 13 const o = {
14 'M+': date.getMonth() + 1, 14 'M+': date.getMonth() + 1,
15 'd+': date.getDate(), 15 'd+': date.getDate(),
16 'h+': date.getHours(), 16 'h+': date.getHours(),
17 'm+': date.getMinutes(), 17 'm+': date.getMinutes(),
18 's+': date.getSeconds() 18 's+': date.getSeconds()
19 } 19 }
20 for (const k in o) { 20 for (const k in o) {
21 if (new RegExp(`(${k})`).test(fmt)) { 21 if (new RegExp(`(${k})`).test(fmt)) {
22 const str = o[k] + '' 22 const str = o[k] + ''
23 fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str)) 23 fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
24 } 24 }
25 } 25 }
26 return fmt 26 return fmt
27 } 27 }
28 28
29 function padLeftZero(str) { 29 function padLeftZero(str) {
30 return ('00' + str).substr(str.length) 30 return ('00' + str).substr(str.length)
31 } 31 }
32 /* 32 /*
33 * 隐藏用户手机号中间四位 33 * 隐藏用户手机号中间四位
34 */ 34 */
35 export function hidePhone(phone) { 35 export function hidePhone(phone) {
36 return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') 36 return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
37 } 37 }
......
1 import Vue from 'vue' 1 import Vue from 'vue'
2 import * as filter from './filter' 2 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.$formatDate = Vue.filter('formatDate')
7 Vue.prototype.$hidePhone = Vue.filter('hidePhone') 7 Vue.prototype.$hidePhone = Vue.filter('hidePhone')
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!