vueInit.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //先加载时间过滤器
  2. Vue.filter('dateTimeFormat', function(value, key) {
  3. if (String(value).length !== 13) {
  4. value *= 1000;
  5. }
  6. let date = new Date(value);
  7. let Y = date.getFullYear();
  8. let m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  9. let d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  10. let H = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
  11. let i = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  12. let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  13. if (!value) return '--'
  14. switch (key) {
  15. case 'Y-m-d H:i:s':
  16. return `${Y}-${m}-${d} ${H}:${i}:${s}`;
  17. case 'Y-m-d H:i':
  18. return `${Y}-${m}-${d} ${H}:${i}`;
  19. case 'Y-m-d':
  20. return `${Y}-${m}-${d}`;
  21. case 'Y-m':
  22. return `${Y}-${m}`;
  23. case 'm-d':
  24. return `${m}-${d}`;
  25. case 'Y':
  26. return `${Y}`;
  27. case 'm':
  28. return `${m}`;
  29. case 'd':
  30. return `${d}`;
  31. case 'H:i:s':
  32. return `${H}:${i}:${s}`;
  33. case 'H:i':
  34. return `${H}:${i}`;
  35. case 'i:s':
  36. return `${i}:${s}`;
  37. case 'H':
  38. return `${H}`;
  39. case 'i':
  40. return `${i}`;
  41. case 's':
  42. return `${s}`;
  43. default:
  44. return "格式错误";
  45. }
  46. });
  47. Vue.filter('emptyFilled', function(value, defalt='--', is_contain_string_data_type=false) {
  48. if (isEmpty(value)) return defalt;
  49. if(is_contain_string_data_type){
  50. if(inArray(value,['null','false','undefined'])){
  51. return defalt;
  52. }
  53. }
  54. return value;
  55. });
  56. Vue.filter('hiddenMobile', function(value, defalt='--', character='*') {
  57. value = String(value)
  58. if (isEmpty(value)) return defalt;
  59. return value.substr(0,3)+character.repeat(4)+value.substr(7);
  60. });
  61. Vue.filter('parseAmount', function (val) {
  62. if (!val) val = 0
  63. return parseFloat(val / 100).toFixed(2)
  64. })