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]; } //将秒转化为 X/XX 比如四小时三十六分 为4/36 const day = msd => { //不到一分钟的情况; let time = Math.floor(msd) + '秒';//整数秒 //time = "0/00"; //超过一分钟的情况 if( Math.floor(msd) > 60){ let min = Math.floor(msd / 60); time = min + "分"; // let hour = Math.floor(min / 60); // let minShow = min % 60; // time = hour + "/" + minShow ; if( min > 60 ){ min = Math.floor(msd / 60) % 60; let hour = Math.floor( msd / 3600 ); time = hour + "小时" + min + "分"; // time = hour + "时"; if( hour > 24 ){ hour = Math.floor( msd / 3600 ) % 24; let day = Math.floor(msd / 3600 / 24); time = day + "天" + hour + "小时"; // time = day + "天"; } } } return time; } //计算首页学过了多长时间 function studyTime (arr) { const studyLog = []; const time = new Date(); for(let item of arr) { if(!item.lessonTitle) { break; } let msd = (time - item.gmtCreated*1) / 1000; studyLog.push( { lessonTitle: item.lessonTitle, lessonId: item.lessonId, gmtCreated:day(msd) + '之前' } ) } return studyLog } //计算各个页面学了多长时间 function studyPageTime (arr) { const studyLog = []; const time = new Date(); for(let item of arr) { if(!item.title) { break; } let msd = (time - item.studyDate*1) / 1000; studyLog.push( { title: item.title, lessonId: item.lessonId, isStudy: item.isStudy, studyDate: day(msd) + '之前' } ) } return studyLog; } //本周推荐勋章攻略 取消
function strategy (str) { return str.split('
'); } //判断能不能预览 function preview (arr) { const studyLog = []; for(let item of arr) { if(item.warePath){ studyLog.push( { title: item.title, lessonId: item.lessonId, warePath: item.warePath } ) } } return studyLog; } //获取当前页面传的的值 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 = '1' column.columnName = '语文' break; case '2': column.columnId = '2' column.columnName = '数学' break; case '3': column.columnId = '3' column.columnName = '中文' break; case '4': column.columnId = '4' column.columnName = '英语' break; case '5': column.columnId = '5' column.columnName = '科学' break; case '6': column.columnId = '6' 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, studyTime, studyPageTime, strategy, gradeUpper, day, preview, getUrl, column, url, topThree, replyNo }