|
@@ -5,8 +5,8 @@
|
|
|
|
|
|
/*
|
|
|
* 时间格式化函数(将时间格式化为,2019年08月12日,2019-08-12,2019/08/12的形式)
|
|
|
- *
|
|
|
- *
|
|
|
+ *
|
|
|
+ *
|
|
|
* pattern参数(想要什么格式的数据就传入什么格式的数据)
|
|
|
* · 'yyyy-MM-dd' ---> 输出如2019-09-20
|
|
|
* · 'yyyy-MM-dd hh:mm' ---> 输出如2019-09-20 08:20
|
|
@@ -17,23 +17,23 @@
|
|
|
* · 'yyyy年MM月dd日 hh时mm分ss秒' ---> 输出如2019年09月20日 08时20分23秒
|
|
|
* · 'yyyy年MM月dd日 hh时mm分ss秒 EE' ---> 输出如2019年09月20日 08时20分23秒 周二
|
|
|
* · 'yyyy年MM月dd日 hh时mm分ss秒 EEE' ---> 输出如2019年09月20日 08时20分23秒 星期二
|
|
|
- *
|
|
|
+ *
|
|
|
* 参考: https://www.cnblogs.com/mr-wuxiansheng/p/6296646.html
|
|
|
*/
|
|
|
Date.prototype.pattern = function (fmt) {
|
|
|
if (!fmt) return ''
|
|
|
var o = {
|
|
|
'y+': this.getFullYear(),
|
|
|
- 'M+': this.getMonth() + 1, // 月份
|
|
|
+ 'M+': this.getMonth() + 1, // 月份
|
|
|
'd+': this.getDate(), // 日
|
|
|
- // 12小时制
|
|
|
- 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时
|
|
|
- // 24小时制
|
|
|
- 'H+': this.getHours(), // 小时
|
|
|
- 'm+': this.getMinutes(), // 分
|
|
|
- 's+': this.getSeconds(), // 秒
|
|
|
- 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
|
|
|
- 'S': this.getMilliseconds(), // 毫秒
|
|
|
+ // 12小时制
|
|
|
+ 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时
|
|
|
+ // 24小时制
|
|
|
+ 'H+': this.getHours(), // 小时
|
|
|
+ 'm+': this.getMinutes(), // 分
|
|
|
+ 's+': this.getSeconds(), // 秒
|
|
|
+ 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
|
|
|
+ 'S': this.getMilliseconds(), // 毫秒
|
|
|
'E+': this.getDay(), // 周
|
|
|
};
|
|
|
var week = {
|
|
@@ -132,7 +132,7 @@ var utils = {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // Compare primitives and functions.
|
|
|
+ // Compare primitives and functions.
|
|
|
// Check if both arguments link to the same object.
|
|
|
// Especially useful on the step where we compare prototypes
|
|
|
if (x === y) {
|
|
@@ -543,5 +543,33 @@ var utils = {
|
|
|
return value
|
|
|
}
|
|
|
return value
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 防抖
|
|
|
+ * @param {Function} func 函数
|
|
|
+ * @param {Number} delay 延时间隔 默认 200ms
|
|
|
+ * @param {Boolean} immediate 是否首次执行
|
|
|
+ */
|
|
|
+ debounce: function (func, delay, immediate){
|
|
|
+ var timer = null;
|
|
|
+ delay = delay || 200
|
|
|
+ return function() {
|
|
|
+ var context = this;
|
|
|
+ var args = arguments;
|
|
|
+ if(timer) clearTimeout(timer);
|
|
|
+ if(immediate){
|
|
|
+ var doNow = !timer;
|
|
|
+ timer = setTimeout(function(){
|
|
|
+ timer = null;
|
|
|
+ },delay);
|
|
|
+ if(doNow){
|
|
|
+ func.apply(context,args);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ timer = setTimeout(function(){
|
|
|
+ func.apply(context,args);
|
|
|
+ },delay);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|