filter.wxs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. //时间戳转时间
  9. function formatDate(time, flag) {
  10. if (!time) {
  11. return
  12. }
  13. var time = time * 1
  14. var t = getDate(time);
  15. var tf = function (i) {
  16. return (i < 10 ? '0' : '') + i
  17. };
  18. var year = t.getFullYear();
  19. var month = tf(t.getMonth() + 1);
  20. var day = tf(t.getDate());
  21. var hour = tf(t.getHours());
  22. var minute = tf(t.getMinutes());
  23. if (flag == 1) {
  24. return month + '月' + day + '日' + ' ' + hour + ':' + minute;
  25. } else if (flag == 2) {
  26. return year + '-' + month + '-' + day
  27. } else if (flag == 3) {
  28. return month + '-' + day + ' ' + hour + ':' + minute;
  29. } else if (flag == 4) {
  30. return year + '年' + month + '月' + day + '日';
  31. } else if (flag == 5) {
  32. return day.toString().substring(1, 2)
  33. } else if (flag == 6) {
  34. return month + '.' + day;
  35. }
  36. }
  37. function gradeFilter(grade) {
  38. if (!grade) {
  39. return '暂无'
  40. }
  41. var gradeObj = {
  42. "PRIMARY_FIRST_GRADE": "一年级",
  43. "PRIMARY_SECOND_GRADE": "二年级",
  44. "PRIMARY_THREE_GRADE": "三年级",
  45. "PRIMARY_SENIOR_GRADE": "四年级",
  46. "PRIMARY_FIVE_GRADE":"五年级",
  47. "PRIMARY_SIX_GRADE":"六年级",
  48. "PRESCHOOL": "学前班",
  49. }
  50. return gradeObj[grade]
  51. }
  52. // 数字满万补w
  53. function numFilter(num) {
  54. if (!num || num < 10000) {
  55. return num
  56. }
  57. return Math.floor(num / 100) / 100 + 'w'
  58. }
  59. module.exports = {
  60. formatDate: formatDate,
  61. gradeFilter: gradeFilter,
  62. numFilter: numFilter
  63. }