|
|
@@ -4,20 +4,19 @@ const common = {
|
|
|
install(Vue) {
|
|
|
|
|
|
// 手机号码格式成秘文形式 格式为137****3151
|
|
|
- String.prototype.$formatPhone = function() {
|
|
|
+ String.prototype.$formatPhone = function () {
|
|
|
return this.replace(/(\d{3})\d+(\d{4})/, '$1****$2')
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 格式化时间 格式为 2023-10-02 12:00:00
|
|
|
- Date.prototype.$formatTime = function() {
|
|
|
- let date = this.toLocaleDateString()
|
|
|
- let time = this.toLocaleTimeString()
|
|
|
- let dateArr = date.split('/')
|
|
|
- let month = `${+dateArr[1] >= 10 ? dateArr[1] : `0${dateArr[1]}`}`
|
|
|
- let day = `${+dateArr[2] >= 10 ? dateArr[2] : `0${dateArr[2]}`}`
|
|
|
- // 小程序this.toLocaleTimeString(),会显示上午、下午,为兼容h5、小程序 先统一去除中文和空格
|
|
|
- time = time.replace(/[\u4e00-\u9fa5\s]/g, '');
|
|
|
- return `${dateArr[0]}-${month}-${day} ${time}`
|
|
|
+ Date.prototype.$formatTime = function () {
|
|
|
+ var Y = this.getFullYear() + '-';
|
|
|
+ var M = (this.getMonth() + 1 < 10 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1) + '-';
|
|
|
+ var D = (this.getDate() < 10 ? '0' + this.getDate() : this.getDate()) + ' ';
|
|
|
+ var h = (this.getHours() < 10 ? '0' + this.getHours() : this.getHours()) + ':';
|
|
|
+ var m = (this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes()) + ':';
|
|
|
+ var s = this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds();
|
|
|
+ return Y + M + D + h + m + s;
|
|
|
}
|
|
|
}
|
|
|
}
|