rankfunc.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import tools from '/common/tools';
  2. import {
  3. teamName
  4. } from '/common/define';
  5. var rankfunc = {
  6. getTeamName(teamType, teamIndex) {
  7. return teamName[teamType][teamIndex];
  8. },
  9. fmtTime(time) {
  10. if (time > 0)
  11. return tools.convertSecondsToHMS(time, 1);
  12. else
  13. return '--';
  14. },
  15. // 格式化 距离
  16. fmtDistanct(val) {
  17. return Math.round(val * 100 / 1000) / 100;
  18. // if (val < 1000)
  19. // return Math.round(val * 10 / 1000) / 10;
  20. // else
  21. // return Math.round(val / 1000);
  22. },
  23. // 格式化 配速
  24. fmtPace(val) {
  25. if (val > 0)
  26. return tools.convertSecondsToHMS(val, 2);
  27. else
  28. return '--';
  29. },
  30. // 根据成绩类型格式化成绩
  31. // rankNum:成绩,rankType:成绩类型,addUnit:是否添加单位
  32. fmtRankNumByType(rankNum, rankType, addUnit=true) {
  33. let fmtRank = rankNum;
  34. let unit = '';
  35. if (rankType == 'totalDistance') {
  36. fmtRank = this.fmtDistanct(rankNum);
  37. unit = ' km';
  38. } else if (rankType == 'fastPace') {
  39. fmtRank = this.fmtPace(rankNum);
  40. } else if (rankType == 'speed') {
  41. fmtRank = this.fmtTime(rankNum);
  42. } else if (rankType == 'rightAnswerPer') {
  43. unit = '%';
  44. } else if (rankType == 'totalCp' || rankType == 'totalSysPoint') {
  45. unit = ' 个';
  46. }
  47. if (addUnit) {
  48. fmtRank += unit;
  49. }
  50. return fmtRank;
  51. }
  52. };
  53. export default rankfunc;