util.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const formatTime = date => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  9. }
  10. const formatNumber = n => {
  11. n = n.toString()
  12. return n[1] ? n : '0' + n
  13. }
  14. //年级显示方法
  15. let gradeArr = ["学前班", "一年级", "二年级", "三年级"]
  16. const gradeUpper = grade => {
  17. return gradeArr[grade];
  18. }
  19. //时间转换秒转天或小时或分
  20. const day = msd => {
  21. let time = Math.floor(msd) + "秒";
  22. if( Math.floor(msd )> 60){
  23. let min = Math.floor(msd / 60);
  24. time = min + "分";
  25. if( min > 60 ){
  26. min = Math.floor(msd / 60) % 60;
  27. let hour = Math.floor( msd / 3600 );
  28. time = hour + "小时" + min + "分";
  29. if( hour > 24 ){
  30. hour = Math.floor( msd / 3600 ) % 24;
  31. let day = Math.floor(msd / 3600 / 24 );
  32. time = day + "天" + hour + "小时";
  33. }
  34. }
  35. }
  36. return time;
  37. }
  38. //获取当前页面传的的值
  39. function getUrl() {
  40. var pages = getCurrentPages() //获取加载的页面
  41. var currentPage = pages[pages.length-1] //获取当前页面的对象
  42. var url = currentPage.route //当前页面url
  43. var options = currentPage.options //如果要获取url中所带的参数可以查看options
  44. return options
  45. }
  46. //判断科目唯一值columnId
  47. function column(columnNum) {
  48. let column = {};
  49. switch(columnNum) {
  50. case '1':
  51. column.columnId = '3564feb8-05ba-11e8-9771-080027fcfc4b'
  52. column.columnName = '语文'
  53. break;
  54. case '2':
  55. column.columnId = '2b52f52e-05ba-11e8-9771-080027fcfc4b'
  56. column.columnName = '数学'
  57. break;
  58. case '3':
  59. column.columnId = '3561f024-05ba-11e8-9771-080027fcfc4b'
  60. column.columnName = '中文'
  61. break;
  62. case '4':
  63. column.columnId = '2b5a24ca-05ba-11e8-9771-080027fcfc4b'
  64. column.columnName = '英语'
  65. break;
  66. case '5':
  67. column.columnId = '23598e64-05ba-11e8-9771-080027fcfc4b'
  68. column.columnName = '科学'
  69. break;
  70. case '6':
  71. column.columnId = '41209f14-05ba-11e8-9771-080027fcfc4b'
  72. column.columnName = '艺术'
  73. break;
  74. }
  75. return column;
  76. }
  77. //输入跳转URL链接
  78. function url(columnNum) {
  79. let url = '';
  80. switch(columnNum) {
  81. case '1':
  82. url = '../language/language?ind=2'
  83. break;
  84. case '2':
  85. url = '../mathematics/mathematics?ind=3'
  86. break;
  87. case '3':
  88. url = '../chinese/chinese?ind=4'
  89. break;
  90. case '4':
  91. url = '../english/english?ind=5'
  92. break;
  93. case '5':
  94. url = '../science/science?ind=6'
  95. break;
  96. case '6':
  97. url = '../art/art?ind=7'
  98. break;
  99. }
  100. return url;
  101. }
  102. //过滤返回回来的数组找出前三名重新排序
  103. function topThree (arr) {
  104. var arr1 = [];
  105. for(var item of arr.slice(0,3)){
  106. if(item.rank == 2){
  107. arr1.unshift(item)
  108. }
  109. if(item.rank == 1) {
  110. arr1.push(item)
  111. }
  112. if(item.rank == 3) {
  113. arr1.push(item)
  114. }
  115. }
  116. return arr1;
  117. }
  118. //获取回复条数
  119. function replyNo (arr) {
  120. let num = 0;
  121. for( let item of arr) {
  122. num += item.currentReplyCount
  123. }
  124. return num
  125. }
  126. module.exports = {
  127. formatTime: formatTime,
  128. gradeUpper,
  129. day,
  130. getUrl,
  131. column,
  132. url,
  133. topThree,
  134. replyNo
  135. }