//获取年月日 const formatTime = (date) => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return { year:year, month:[year, month].map(formatNumber).join('-'), day:[year, month, day].map(formatNumber).join('-'), month_tow:month } } const formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } //删除数组的某一项 const arrRemoveObj = (array, obj) => { let length = array.length; for (let i = 0; i < length; i++) { if (array[i] === obj) { if (i === 0) { array.shift(); return array; } else if (i === length - 1) { array.pop(); return array; } else { array.splice(i, 1); return array; } } } } //获取对应积分类型 const getTypeItem=(arr,id)=>{ var item=arr.filter(element => { return typeof(id)=='string'?element.code==id:element.id==id }); return item[0] } module.exports = { formatTime: formatTime, arrRemoveObj:arrRemoveObj, getTypeItem:getTypeItem }