filter.wxs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "PRESCHOOL": "学前班",
  47. }
  48. return gradeObj[grade]
  49. }
  50. // 数字满万补w
  51. function numFilter(num) {
  52. if (!num || num < 10000) {
  53. return num
  54. }
  55. return Math.floor(num / 100) / 100 + 'w'
  56. }
  57. module.exports = {
  58. formatDate: formatDate,
  59. gradeFilter: gradeFilter,
  60. numFilter: numFilter
  61. }