From ae5ea1a3d06324d85f4b04f17bac0dc5572a5a8f Mon Sep 17 00:00:00 2001 From: long <515897141@qq.com> Date: 星期日, 04 二月 2024 18:53:00 +0800 Subject: [PATCH] 时间锁改为15秒 --- src/utils/fn.js | 69 +++++++++++++++++++++++++++++++--- 1 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/utils/fn.js b/src/utils/fn.js index ed71bde..15fa356 100644 --- a/src/utils/fn.js +++ b/src/utils/fn.js @@ -6,6 +6,8 @@ */ // 閫氱敤function锛岄�氳繃鍏ㄥ眬瀹夎锛屾垨import寮曠敤璋冪敤 +var fn_obj = {}// fn.js瀵硅薄 + let scrollBarWidth // 婊氬姩鏉″搴� // 鑾峰彇娴忚鍣ㄦ粴鍔ㄦ潯瀹藉害 function getScrollBarWidth() { @@ -276,10 +278,11 @@ * 鑾峰彇褰撳墠鏃堕棿鐨勫搴旂殑鏃堕棿瀵硅薄锛堝骞存湀鏃ワ紝鏃跺垎绉掞紝鏄熸湡鍑狅紝鏃堕棿鎴筹級 * @param {Object} page 椤甸潰瀵硅薄 * @param {String} key 鏃堕棿瀵硅薄鐨勫瓧娈靛悕 + * @param {String} pageKey 椤甸潰鍏抽敭璇� */ -function countGetTime(page, key) { +function countGetTime(page, key, pageKey) { var dayStamp = new Date().getTime() - var timer = null + fn_obj[`timer_${pageKey}`] = null var time = new Date(dayStamp) var year = time.getFullYear() let month = time.getMonth() + 1 @@ -311,13 +314,61 @@ time: `${hours}:${minute}:${second}`, timeStamp: dayStamp } - // console.log('1111111111111111111111', page, key) page[key] = res - timer = setTimeout(() => { - countGetTime(page, key) - clearTimeout(timer) - timer = null + fn_obj[`timer_${pageKey}`] = setTimeout(() => { + countGetTime(page, key, pageKey) }, 1000) + // console.log('1111111111111111111111', fn_obj) +} + +/** + * 鍋滄褰撳墠椤甸潰鐨勮鏃跺姛鑳� + * @param {String} pageKey 椤甸潰鍏抽敭璇� + */ +function stopCountGetTime(pageKey) { + clearTimeout(fn_obj[`timer_${pageKey}`]) + fn_obj[`timer_${pageKey}`] = null +} + +/** + * 杞寮傛璋冪敤鎺ュ彛 + * @param {Object} page 椤甸潰瀵硅薄this + * @param {String} fnName 瑕佽疆璇㈢殑鏂规硶鍚嶇О + * @param {String} pageKey 椤甸潰鍏抽敭瀛� + * @param {Number} timeStamp 澶氬皯绉掕疆璇� + */ +function pollingAjaxFn(page, fnName, pageKey, timeStamp = 1000) { + if (!page || !fnName || !pageKey) { + return + } + page[fnName] && page[fnName]() + fn_obj[`pollingTimer_${pageKey}`] = setTimeout(() => { + pollingAjaxFn(page, fnName, pageKey, timeStamp) + }, timeStamp) +} + +/** + * 鍋滄杞 + * @param {String} pageKey 椤甸潰鍏抽敭璇� + */ +function stopPollingAjaxFn(pageKey) { + clearTimeout(fn_obj[`pollingTimer_${pageKey}`]) + fn_obj[`pollingTimer_${pageKey}`] = null +} + +// 闅忔満12浣嶆暟 +function getCheckedId() { + var s = [] + var hexDigits = '0123456789abcdef' + for (var i = 0; i < 12; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) + } + // s[14] = '4'; + // s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); + + // s[8] = s[13] = s[18] = s[23] = '-' + var uuid = s.join('') + return uuid } var fn = { @@ -347,6 +398,10 @@ urlReplace, countGetTime, + stopCountGetTime, + pollingAjaxFn, + stopPollingAjaxFn, + getCheckedId, /** * 娣辨嫹璐� -- Gitblit v1.8.0