12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import moment from 'moment'
- import Vue from 'vue'
- Vue.filter('moment', (date, type = 1) => {
- if(!date) {
- return ''
- }
- if (type === 1) {
- return moment(date).format('HH:mm')
- } else if (type === 2) {
- return moment(date).format('YYYY-MM-DD HH:mm')
- } else if (type === 3) {
- return moment(date).format('YYYY-MM-DD')
- } else if (type === 4) {
- return moment(date).format('HH:mm:ss')
- } else if (type === 5) {
- return moment(date).format('YYYY-MM-DD HH:mm:ss')
- } else if (type === 6) {
- const result = moment(date).format('M月DD日 Ah:mm')
- return result.includes('PM') ? result.replace('PM', '下午') : result.replace('AM', '上午')
- } else if (type === 7) {
- return moment(date).format('MM-DD HH:mm')
- } else if (type === 8) {
- return moment(date).format('MM-DD')
- }
- })
- Vue.filter('3days', function (dataStr, pattern = 'YYYY.MM.DD') {
- const current = moment()
- const time = moment(dataStr, 'YYYY-MM-DD HH:mm:ss')
- const diff = current.diff(time) / 1000
- if (diff >= (3 * 24 * 60 * 60)) {
- // 大于3天
- return time.format(pattern)
- } else if (diff < (3 * 24 * 60 * 60) && diff >= (24 * 60 * 60)) {
- return current.diff(time, 'days') + ' 天前'
- } else if (diff < (24 * 60 * 60) && diff >= (60 * 60)) {
- return current.diff(time, 'hours') + ' 小时前'
- } else if (diff < (60 * 60) && diff >= (60)) {
- return current.diff(time, 'minutes') + ' 分钟前'
- } else if (diff < (60) && diff >= (0)) {
- return current.diff(time, 'seconds') + ' 秒前'
- } else {
- return time.format(pattern)
- }
- })
|