filters.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {
  2. numberToChinese,
  3. formatTimestamp
  4. } from './utils.js'
  5. export const deg = (value, stauts) => { //deg 转 学位过滤器
  6. switch (+value) {
  7. case 0: {
  8. switch (+stauts) {
  9. case 0:
  10. return "未获得学位资格";
  11. case 1:
  12. return "初中资格";
  13. case 2:
  14. return "高中资格";
  15. case 3:
  16. return "大学资格";
  17. case 4:
  18. return "大学资格";
  19. }
  20. }
  21. case 1:
  22. return "大学毕业";
  23. case 2:
  24. return "学士学位";
  25. case 3:
  26. return "硕士学位";
  27. case 4:
  28. return "博士学位";
  29. case 5:
  30. return "学霸";
  31. case 6:
  32. return "结业";
  33. }
  34. }
  35. export const numToZh = value => { //数字转汉字过滤器
  36. return value ? numberToChinese(value) : ''
  37. }
  38. export const getYear = value => { //时间戳转年份过滤器
  39. return formatTimestamp(+value)[0]
  40. }
  41. export const getMonth = value => { //时间戳转月份过滤器
  42. const month = formatTimestamp(+value)[1] + ''
  43. return month.length === 1 ? '0' + month : month //月份只有一位数字时补零
  44. }
  45. export const getDay = value => { //时间戳转周过滤器
  46. return formatTimestamp(+value)[2]
  47. }
  48. export const getDate = value => { //时间戳转 日 过滤器
  49. const date = formatTimestamp(+value)[3] + ''
  50. return date.length === 1 ? '0' + date : date //日期份只有一位数字时补零
  51. }
  52. export const getHousr = value => { //时间戳转 时 过滤器
  53. return formatTimestamp(+value)[4]
  54. }
  55. export const getMinute = value => { //时间戳转 分 过滤器
  56. return formatTimestamp(+value)[5]
  57. }
  58. export const getSecond = value => { //时间戳转 秒 过滤器
  59. return formatTimestamp(+value)[6]
  60. }
  61. export const willDeg = (value, max) => {
  62. if (value < 200) {
  63. return '大学毕业'
  64. }
  65. if (value >= 200 && value < 600) {
  66. return '学士毕业'
  67. } else if (value >= 600 && value < 1000) {
  68. return '硕士毕业'
  69. } else if (value >= 1000 && value < 1300) {
  70. return '博士毕业'
  71. } else if (value >= 1300 && value < max) {
  72. return '成为学霸'
  73. }
  74. return ''
  75. }
  76. export const lessScore = (value, max) => {
  77. if (value < 200) {
  78. return 200 - value
  79. } else if (value >= 200 && value < 600) {
  80. return 600 - value
  81. } else if (value >= 600 && value < 1000) {
  82. return 1000 - value
  83. } else if (value >= 1000 && value < 1300) {
  84. return 1300 - value
  85. } else if (value >= 1300 && value < max) {
  86. return max - value
  87. }
  88. return ''
  89. }
  90. export function userXueWei(score) {
  91. score = Number(score)
  92. let out
  93. switch (true) {
  94. case score < 200:
  95. out = '未获得证书'
  96. break
  97. case (score >= 200 && score < 500):
  98. out = '大学毕业'
  99. break
  100. case (score >= 500 && score < 1000):
  101. out = '学士学位'
  102. break
  103. case (score >= 1000 && score < 1500):
  104. out = '硕士学位'
  105. break
  106. case score >= 1500:
  107. out = '博士学位'
  108. break
  109. }
  110. return out
  111. }
  112. export function dateFormatter(timestamp, fmt) {
  113. fmt = fmt || "yyyy-MM-dd";
  114. if (typeof timestamp === "string") {
  115. timestamp = timestamp.replace(/-/g, '/')
  116. }
  117. const $this = new Date(timestamp);
  118. const o = {
  119. "M+": $this.getMonth() + 1,
  120. "d+": $this.getDate(),
  121. "h+": $this.getHours(),
  122. "m+": $this.getMinutes(),
  123. "s+": $this.getSeconds(),
  124. "q+": Math.floor(($this.getMonth() + 3) / 3),
  125. S: $this.getMilliseconds()
  126. };
  127. if (/(y+)/.test(fmt)) {
  128. fmt = fmt.replace(
  129. RegExp.$1,
  130. ($this.getFullYear() + "").substr(4 - RegExp.$1.length)
  131. );
  132. }
  133. for (var k in o) {
  134. if (new RegExp("(" + k + ")").test(fmt)) {
  135. fmt = fmt.replace(
  136. RegExp.$1,
  137. RegExp.$1.length === 1 ?
  138. o[k] :
  139. ("00" + o[k]).substr(("" + o[k]).length)
  140. );
  141. }
  142. }
  143. return fmt;
  144. }