import httpConfig from "@/common/http/config" export default { //时间格式化 formatDate (formats, timestamp) { var formats = formats || 'Y.M.D'; var myDate = timestamp ? new Date(timestamp) : new Date(); var year = myDate.getFullYear(); var month = formatDigit(myDate.getMonth() + 1); var day = formatDigit(myDate.getDate()); var hour = formatDigit(myDate.getHours()); var minute = formatDigit(myDate.getMinutes()); var second = formatDigit(myDate.getSeconds()); return formats.replace(/Y|M|D|h|m|s/g, function(matches) { return ({ Y: year, M: month, D: day, h: hour, m: minute, s: second })[matches]; }); // 小于10补0 function formatDigit (n) { return n.toString().replace(/^(\d)$/, '0$1'); } }, // 标准日期转换年月日 transformTimestamp(timestamp){ let a = new Date(timestamp).getTime(); const date = new Date(a); const Y = date.getFullYear() + '年'; const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月'; const D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + '日'; const dateString = Y + M + D; return dateString; }, // 截取年月日 splitDate (str) { let newstr = str.substr(0, 10); let arr = newstr.split('-'); return arr[0] + '年' + arr[1] + '月' + arr[2] + '日'; }, // 图片地址拼接 getJointImg(image) { return image ? (httpConfig.url + image) : '' }, }