filter.wxs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var formatNumber = function (n) {
  2. n = n.toString()
  3. return n[1] ? n : '0' + n
  4. }
  5. /**
  6. * 将时间戳(1570550400)格式转为 yyyy-MM-dd格式
  7. */
  8. var formatDate = function (datetime) {
  9. var time = datetime * 1
  10. var date = getDate(time);
  11. var year = date.getFullYear();
  12. var month = date.getMonth() + 1;
  13. var day = date.getDate();
  14. return year + '年' + month + '月' + day + '日';
  15. }
  16. var formatDate2 = function (datetime) {
  17. var time = datetime * 1
  18. var date = getDate(time);
  19. var year = date.getFullYear();
  20. var month = date.getMonth() + 1;
  21. var day = date.getDate();
  22. var tf = function (i) {
  23. return (i < 10 ? '0' : '') + i
  24. };
  25. var hour = tf(date.getHours());
  26. var minute = tf(date.getMinutes());
  27. return year + '-' + month + '-' + day + '' + hour + ':' + minute;
  28. }
  29. function gradeFilter(grade) {
  30. if (!grade) {
  31. return '暂无'
  32. }
  33. var gradeObj = {
  34. "PRIMARY_FIRST_GRADE": "一年级",
  35. "PRIMARY_SECOND_GRADE": "二年级",
  36. "PRIMARY_THREE_GRADE": "三年级",
  37. "PRIMARY_SENIOR_GRADE": "四年级",
  38. "PRESCHOOL": "学前班",
  39. }
  40. return gradeObj[grade]
  41. }
  42. // 数字满万补w
  43. function numFilter(num) {
  44. if (!num || num < 10000) {
  45. return num
  46. }
  47. return Math.floor(num / 100) / 100 + 'w'
  48. }
  49. module.exports = {
  50. formatDate: formatDate,
  51. formatDate2: formatDate2,
  52. gradeFilter: gradeFilter,
  53. numFilter: numFilter
  54. }