import Vue from 'vue' import { config } from '@/config/config' //保留两位小数 Vue.filter('keepTwoNum',function(val){ let value = Number(val) return value.toFixed(2) }) //链接加时间戳 Vue.filter("timestamp", function(link) { return link + '?t=' + new Date().getTime(); }); //截取第一张照片且判断是否有图片,没有图片按照传递类型随机输出 Vue.filter("firstImg",function(arr,sizeType,imgType){ let img; //图片类型判断 if(arr){ if(arr instanceof Array){ img = arr[0] }else{ img = arr.split(',')[0] } }else if(!arr){ //如果没有图片则随机输出一张 // if(imgType === 'farmer'){ // const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png'] // img = farmerList[Math.floor(Math.random() * farmerList.length)]; // } img = '/static/img/inbuild.png' } // return config.imgUrl + img; return img; }); Vue.filter("miniImg",function(img,quality){ return img+'?imageMogr2/quality/'+quality }); import {formatDate} from '@/utils/date'; Vue.filter("formatDateTime",function(time){ if (time == null || time === '') { return 'N/A'; } //不足10 补0操作 var addZero=function (num) { return num < 10 ? '0' + num : num; }; let time1 = time.replace(/T/g, ' '); time1 = time1.replace(/\-/g, "/"); console.log(time1.substring(0,19)); var time2 = (new Date(time1)).getTime(); console.log('a',time2); var date = new Date(time2); console.log('date',date); var Year = date.getFullYear(); var Month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var Hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); var Minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); var Seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); var over_time = Year + "/" + Month + "/" + d + " " + Hours + ":" + Minutes + ":" + Seconds //***至此以上是将时间转为正常时间格式,以下为将时间进行增加8小时解决时区差异的操作*** var time3 = new Date(Date.parse(over_time)); // time3.setTime(time3.setHours(time3.getHours())); time3.setTime(time3.setHours(time3.getHours() + 8)); var Y = time3.getFullYear() + '/'; var M =addZero(time3.getMonth() + 1) + '/'; var D =addZero(time3.getDate()) + ' '; var h = addZero(time3.getHours()) + ':'; var m =addZero(time3.getMinutes()) + ':'; var s =addZero(time3.getSeconds()); return (Y + M + D + " " + h + m + s) // return formatDate(date, 'yyyy-MM-dd hh:mm:ss') });