var formatNumber = function (n) { n = n.toString() return n[1] ? n : '0' + n } /** * 将时间戳(1570550400)格式转为 yyyy-MM-dd格式 */ //时间戳转时间 function formatDate(time, flag) { if (!time) { return } if (time == '1') { return "终身使用" } var time = time * 1 var t = getDate(time); var tf = function (i) { return (i < 10 ? '0' : '') + i }; var year = t.getFullYear(); var month = tf(t.getMonth() + 1); var day = tf(t.getDate()); var hour = tf(t.getHours()); var minute = tf(t.getMinutes()); if (flag == 1) { return year + '-' + month + '-' + day + '' + ' ' + hour + ':' + minute; } else if (flag == 2) { return year + '.' + month + '.' + day } else if (flag == 3) { return month + '-' + day + ' ' + hour + ':' + minute; } else if (flag == 4) { return year + '年' + month + '月' + day + '日'; } else if (flag == 5) { return year + '-' + month + '-' + day; } else if (flag == 6) { return day; } } function gradeFilter(grade) { if (!grade) { return '暂无' } var gradeObj = { "PRESCHOOL": "学前班", "PRIMARY_FIRST_GRADE": "一年级", "PRIMARY_SECOND_GRADE": "二年级", "PRIMARY_THREE_GRADE": "三年级", "PRIMARY_SENIOR_GRADE": "四年级", "PRIMARY_FIVE_GRADE": "五年级", "PRIMARY_SIX_GRADE": "六年级", } return gradeObj[grade] } // 数字满万补w function numFilter(num) { if (!num) { return 0 } if (num < 10000) { return num } return Math.floor(num / 100) / 100 + 'w' } // 四舍五入保留两位小数 function twoDecimal(num) { return (num / 100).toFixed(2) } // 切换旗帜图片 function showPennant(count, num) { if (count >= num) { if (num <= 2) { return '/static/2q.png' } else if (num <= 5) { return '/static/5q.png' } else if (num <= 10) { return '/static/10q.png' } else if (num <= 15) { return '/static/15q.png' } else if (num <= 30) { return '/static/30q.png' } else if (num <= 60) { return '/static/60q.png' } } else { return '/static/pennant.png' } } function textSlice(text) { return text.slice(5) } module.exports = { formatDate: formatDate, gradeFilter: gradeFilter, numFilter: numFilter, twoDecimal: twoDecimal, textSlice: textSlice, showPennant: showPennant }