/* eslint-disable no-underscore-dangle */ /* eslint-disable no-continue */ const _list = function (el: any, json: any) { let str = ''; let left = 0; let isDecimalNumber = false; for (let i = 0; i < json.length; i++) { let { width } = json; if (json.valueStr[i] === '.') { width = 4; isDecimalNumber = true; } const t = json.height * parseInt(json.valueStr[i], 10); const h = json.height * 10; str += ``; str += '
'; for (let j = 0; j < 10; j++) { let _j: any = j; if (json.valueStr[i] === '.') { _j = '.'; } str += `
${_j}
`; } str += '
'; str += '
'; for (let j = 0; j < 10; j++) { let _j: any = j; if (json.valueStr[i] === '.') { _j = '.'; } str += `
${_j}
`; } str += '
'; str += '
'; left += json.isOnlyDecimal && !isDecimalNumber ? 0 : width; } el.html(str); }; const _random = function (json: any) { const rate = json.increaseRate; const base = json.baseNumber; const num = base * rate; return num; }; /* 执行动画效果 */ const _animate = function (el: any, value: any, json: any) { let isZero = true; for (let x = 0; x < json.length; x++) { if (value[x] === '.') { continue; } if (Number(value[x]) > 0) { isZero = false; } const topPx = (Number(value[x] || 0) + 10) * json.height; const _topPx = (value[x] || 0) * json.height; const li = el.eq(x); const currentTop = Number(li.css('top').replace('px', '')); if (currentTop === -_topPx && (x + 1 !== json.length || isZero)) { continue; } li.addClass('scroll'); if (currentTop <= -_topPx) { li.css('top', -topPx); setTimeout(function () { li.removeClass('scroll'); li.css('top', -_topPx); }, 1000); } else { li.css('top', -_topPx); } } }; /* 定期刷新动画列表 */ const _interval = function (el: any, json: any) { let val = json.value; return window.setInterval(function () { val += _random(json); _animate(el, val.toFixed(json.length - 2), json); }, json.interval); }; export const runNum = (id: any, val: any, params: any) => { const valString = val || 0; const par = params || {}; const runNumJson = { el: (window as any).$(id), value: valString, valueStr: valString.toFixed(par.length - 2), width: par.width || 12, height: par.height || 16, increaseRate: par.increaseRate || 0, baseNumber: par.baseNumber || 0, interval: par.interval || 3000, length: par.length, isOnlyDecimal: !!params.isOnlyDecimal, }; _list(runNumJson.el, runNumJson); return _interval(runNumJson.el.children('span'), runNumJson); }; export const getValidDecimals = (num: any) => { const numStr = num.toPrecision(2); const [, decimals] = numStr.split('.'); if (decimals === undefined) { return 0; } return decimals.length; };