common.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. module.exports = {
  2. timefilter(type, value) {
  3. if (this.$isNull(value)) return
  4. var newDate = ""
  5. if (String(value).indexOf("-") != -1) {
  6. newDate = new Date(value.replace(/-/g, "/"))
  7. } else {
  8. newDate = new Date(Number(value))
  9. }
  10. var hours = newDate.getHours().toString()
  11. var minutes = newDate.getMinutes().toString()
  12. var seconds = newDate.getSeconds().toString()
  13. var year = newDate.getFullYear().toString();
  14. var month = (newDate.getMonth() + 1).toString();
  15. var day = (newDate.getDate()).toString();
  16. if (month.length == 1) {
  17. month = "0" + month;
  18. }
  19. if (day.length == 1) {
  20. day = "0" + day;
  21. }
  22. if (hours.length == 1) {
  23. hours = "0" + hours;
  24. }
  25. if (minutes.length == 1) {
  26. minutes = "0" + minutes;
  27. }
  28. if (seconds.length == 1) {
  29. seconds = "0" + seconds;
  30. }
  31. if (type == 'YY-MM-DD HH:MM:SS') {
  32. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
  33. } else if (type == 'HH:MM') {
  34. return hours + ':' + minutes
  35. } else if (type == 'HH:MM:SS') {
  36. return hours + ':' + minutes + ':' + seconds
  37. } else if (type == 'YY-MM-DD') {
  38. return year + '-' + month + '-' + day
  39. } else if (type == 'YY-MM-DD HH:MM') {
  40. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes
  41. } else if (type == '年月日 HH:MM:SS') {
  42. return year + '年' + month + '月' + day + '日 ' + hours + ':' + minutes + ':' + seconds
  43. }
  44. else if (type == '年月日') {
  45. return year + '年' + month + '月' + day + '日 '
  46. }
  47. },
  48. isNull(param) {
  49. if (typeof param == "boolean") {
  50. return false;
  51. }
  52. if (param == null || param == undefined || param == '') {
  53. return true;
  54. }
  55. return false;
  56. },
  57. formatPhone(e) {
  58. if (e == '') return
  59. var tel = e;
  60. tel = "" + tel;
  61. var newTel = tel.substr(0, 3) + "****" + tel.substr(7)
  62. return newTel
  63. },
  64. formatName(e) {
  65. if (e == '') return
  66. if (e != null || e != undefined) {
  67. var name = e;
  68. if (name.length > 1) {
  69. name = "" + name;
  70. var newName = name.substr(0, 1) + "*" + name.substr(2,name.length-1)
  71. return newName
  72. }
  73. else {
  74. return name
  75. }
  76. } else {
  77. return e
  78. }
  79. },
  80. }