index.js 710 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import request from './request'
  2. export function withInstall(component) {
  3. component.install = function (app) {
  4. app.component(component.name, component);
  5. };
  6. return component;
  7. }
  8. export function WithInstallOfGlobalMethod(globalName, method) {
  9. method.install = function (app) {
  10. app.prototype[globalName] = method;
  11. };
  12. return method;
  13. }
  14. export {
  15. request
  16. }
  17. export function calcPercent(bn, tq) {
  18. if (bn - tq === 0) {
  19. return '0%'
  20. }
  21. if (tq === 0) {
  22. return '100%'
  23. }
  24. return `${(parseInt((Math.abs(bn - tq) / tq).toFixed(2) * 100 ))}%`
  25. }
  26. export function getState(bn, tq) {
  27. if (bn -tq > 0) {
  28. return 1;
  29. } else if (bn - tq < 0){
  30. return -1;
  31. } else {
  32. return 0;
  33. }
  34. }