From f7aa204aa8d20b090d7943969ddeb9871a1fad76 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期四, 12 九月 2024 17:28:06 +0800
Subject: [PATCH] -
---
src/common/utils/util.js | 73 ++++++++++++++++++++++++++++++++++--
1 files changed, 68 insertions(+), 5 deletions(-)
diff --git a/src/common/utils/util.js b/src/common/utils/util.js
index db1eae5..c728e60 100644
--- a/src/common/utils/util.js
+++ b/src/common/utils/util.js
@@ -133,20 +133,23 @@
parseInt(t[2], 10) || null
)).getTime() / 1000;
},
- formatDate(dat, type) {
+ formatDate(dat, type, addNum) {
if(!dat){
return '-'
}
let date = new Date(dat)
+ if(addNum){
+ date = new Date(date.setDate(date.getDate() + addNum));
+ }
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
if (type) {
- return `${year}/${month}/${day} ${hours}:${minutes}`;
+ return `${year}-${month}-${day} ${hours}:${minutes}`;
}
- return `${year}/${month}/${day}`;
+ return `${year}-${month}-${day}`;
},
/**
* 鍊掕鏃�
@@ -767,7 +770,67 @@
}, reject)
// #endif
})
- }
-
+ },
+ roundToTwo(num){
+ if(isNaN(num)){
+ return 0
+ }
+ return Math.round((num + Number.EPSILON) * 100) / 100;
+ },
+ /**
+ * @method 鍑芥暟闃叉姈
+ * @desc 鐭椂闂村唴澶氭瑙﹀彂鍚屼竴浜嬩欢锛屽彧鎵ц鏈�鍚庝竴娆★紝鎴栬�呭彧鎵ц鏈�寮�濮嬬殑涓�娆★紝涓棿鐨勪笉鎵ц銆�
+ * @param func 鐩爣鍑芥暟
+ * @param wait 寤惰繜鎵ц姣鏁�
+ * @param immediate true - 绔嬪嵆鎵ц锛� false - 寤惰繜鎵ц
+ */
+ debounce(func, wait = 1000, immediate = true) {
+ let timer;
+ return function() {
+ let context = this,
+ args = arguments;
+ if (timer) clearTimeout(timer);
+ if (immediate) {
+ let callNow = !timer;
+ timer = setTimeout(() => {
+ timer = null;
+ }, wait);
+ if (callNow) func.apply(context, args);
+ } else {
+ timer = setTimeout(() => {
+ func.apply(context, args);
+ }, wait)
+ }
+ }
+ },
+ /**
+ * @method 鍑芥暟鑺傛祦
+ * @desc 鎸囪繛缁Е鍙戜簨浠讹紝浣嗘槸鍦� n 绉掑唴鍙墽琛屼竴娆″嚱鏁般�傚嵆 2n 绉掑唴鎵ц 2 娆�... 銆備細绋�閲婂嚱鏁扮殑鎵ц棰戠巼銆�
+ * @param func 鍑芥暟
+ * @param wait 寤惰繜鎵ц姣鏁�
+ * @param type 1 鍦ㄦ椂闂存寮�濮嬬殑鏃跺�欒Е鍙� 2 鍦ㄦ椂闂存缁撴潫鐨勬椂鍊欒Е鍙�
+ */
+ throttle(func, wait = 1000, type = 1) {
+ let previous = 0;
+ let timeout;
+ return function() {
+ let context = this;
+ let args = arguments;
+ if (type === 1) {
+ let now = Date.now();
+ if (now - previous > wait) {
+ func.apply(context, args);
+ previous = now;
+ }
+ } else if (type === 2) {
+ if (!timeout) {
+ timeout = setTimeout(() => {
+ timeout = null;
+ func.apply(context, args)
+ }, wait)
+ }
+ }
+ }
+ },
}
--
Gitblit v1.9.1