import request from './request' export function withInstall(component) { component.install = function (app) { app.component(component.name, component); }; return component; } export function WithInstallOfGlobalMethod(globalName, method) { method.install = function (app) { app.prototype[globalName] = method; }; return method; } export { request } export function calcPercent(bn, tq) { if (bn - tq === 0) { return '-' } if (tq === 0) { return '-' } return `${(parseInt((Math.abs(bn - tq) / tq).toFixed(2) * 100 ))}%` } export function getState(bn, tq) { if(tq === 0) { return 0; } if (bn -tq > 0) { return 1; } else if (bn - tq < 0){ return -1; } else { return 0; } } export const 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) } } } }