common.js 849 B

123456789101112131415161718192021222324
  1. import Vue from 'vue'
  2. const common = {
  3. install(Vue) {
  4. // 手机号码格式成秘文形式 格式为137****3151
  5. String.prototype.$formatPhone = function () {
  6. return this.replace(/(\d{3})\d+(\d{4})/, '$1****$2')
  7. }
  8. // 格式化时间 格式为 2023-10-02 12:00:00
  9. Date.prototype.$formatTime = function () {
  10. var Y = this.getFullYear() + '-';
  11. var M = (this.getMonth() + 1 < 10 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1) + '-';
  12. var D = (this.getDate() < 10 ? '0' + this.getDate() : this.getDate()) + ' ';
  13. var h = (this.getHours() < 10 ? '0' + this.getHours() : this.getHours()) + ':';
  14. var m = (this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes()) + ':';
  15. var s = this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds();
  16. return Y + M + D + h + m + s;
  17. }
  18. }
  19. }
  20. Vue.use(common)