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, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') } const formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } //年级显示方法 let gradeArr = ["学前班", "一年级", "二年级", "三年级"] const gradeUpper = grade => { return gradeArr[grade]; } //时间转换秒转天或小时或分 const day = msd => { let time = Math.floor(msd) + "秒"; if( Math.floor(msd )> 60){ let min = Math.floor(msd / 60); time = min + "分"; if( min > 60 ){ min = Math.floor(msd / 60) % 60; let hour = Math.floor( msd / 3600 ); time = hour + "小时" + min + "分"; if( hour > 24 ){ hour = Math.floor( msd / 3600 ) % 24; let day = Math.floor(msd / 3600 / 24 ); time = day + "天" + hour + "小时"; } } } return time; } //获取当前页面传的的值 function getUrl() { var pages = getCurrentPages() //获取加载的页面 var currentPage = pages[pages.length-1] //获取当前页面的对象 var url = currentPage.route //当前页面url var options = currentPage.options //如果要获取url中所带的参数可以查看options return options } //判断科目唯一值columnId function column(columnNum) { let column = {}; switch(columnNum) { case '1': column.columnId = '3564feb8-05ba-11e8-9771-080027fcfc4b' column.columnName = '语文' break; case '2': column.columnId = '2b52f52e-05ba-11e8-9771-080027fcfc4b' column.columnName = '数学' break; case '3': column.columnId = '3561f024-05ba-11e8-9771-080027fcfc4b' column.columnName = '中文' break; case '4': column.columnId = '2b5a24ca-05ba-11e8-9771-080027fcfc4b' column.columnName = '英语' break; case '5': column.columnId = '23598e64-05ba-11e8-9771-080027fcfc4b' column.columnName = '科学' break; case '6': column.columnId = '41209f14-05ba-11e8-9771-080027fcfc4b' column.columnName = '艺术' break; } return column; } //输入跳转URL链接 function url(columnNum) { let url = ''; switch(columnNum) { case '1': url = '../language/language?ind=2' break; case '2': url = '../mathematics/mathematics?ind=3' break; case '3': url = '../chinese/chinese?ind=4' break; case '4': url = '../english/english?ind=5' break; case '5': url = '../science/science?ind=6' break; case '6': url = '../art/art?ind=7' break; } return url; } //过滤返回回来的数组找出前三名重新排序 function topThree (arr) { var arr1 = []; for(var item of arr.slice(0,3)){ if(item.rank == 2){ arr1.unshift(item) } if(item.rank == 1) { arr1.push(item) } if(item.rank == 3) { arr1.push(item) } } return arr1; } //获取回复条数 function replyNo (arr) { let num = 0; for( let item of arr) { num += item.currentReplyCount } return num } module.exports = { formatTime: formatTime, gradeUpper, day, getUrl, column, url, topThree, replyNo }