| | |
| | | */ |
| | | // 通用function,通过全局安装,或import引用调用 |
| | | |
| | | var fn_obj = {}// fn.js对象 |
| | | |
| | | let scrollBarWidth // 滚动条宽度 |
| | | // 获取浏览器滚动条宽度 |
| | | function getScrollBarWidth() { |
| | |
| | | * 获取当前时间的对应的时间对象(如年月日,时分秒,星期几,时间戳) |
| | | * @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 |
| | |
| | | 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 = { |
| | |
| | | urlReplace, |
| | | |
| | | countGetTime, |
| | | stopCountGetTime, |
| | | pollingAjaxFn, |
| | | stopPollingAjaxFn, |
| | | getCheckedId, |
| | | |
| | | /** |
| | | * 深拷贝 |