createSpeed.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * 创建进度条 组件
  3. */
  4. function CreateSpeed(option){
  5. this.option = option;
  6. this.isFirstLoad = true;
  7. this.init();
  8. }
  9. CreateSpeed.prototype = {
  10. init:function () {
  11. this.createSpeed();
  12. },
  13. createSpeed:function () {
  14. var _view_ = this;
  15. var html = '';
  16. html += '<div id="'+_view_.option.id+'" class="speed-container">';
  17. if (_view_.option.title) {
  18. html += '<div class="speed-title">';
  19. html += '<span><img src="'+ compbase +'/'+_view_.option.icon+'"></span><span>'+_view_.option.title+'</span><span><img src="'+ compbase +'/icon/xjt.png"></span>';
  20. html += '</div>';
  21. }
  22. html += '<div class="speed-content">';
  23. html += '<ul>';
  24. html += '<ul>';
  25. html += '</div>';
  26. html += '</div>';
  27. $("#"+_view_.option.id).append(html);
  28. },
  29. setData:function (series) {
  30. var _view_ = this;
  31. function toPoint(point){
  32. var str=Number(point*100).toFixed(1);
  33. str+="%";
  34. return str;
  35. }
  36. var html = '';
  37. series.forEach(function (item,index) {
  38. html += '<li><span>'+item["name"]+'</span><span class="speed-line"><span id="'+_view_.option.id+index+'" class="speed-num" style="background-color: '+item["color"]+'"></span><span class="numText">'+item["data"]+'</span></span></li>';
  39. });
  40. $("#"+_view_.option.id + " ul").html(html);
  41. //动画效果加载数据
  42. if(_view_.isFirstLoad){
  43. series.forEach(function (item,index) {
  44. var dataNum = null;
  45. if(_view_.option.max === null){
  46. dataNum = item["data"];
  47. }else{
  48. dataNum = toPoint(item["data"]/_view_.option.max);
  49. }
  50. $("#"+_view_.option.id+index).animate({
  51. width:dataNum
  52. },2000);
  53. });
  54. _view_.isFirstLoad = false;
  55. }else{
  56. series.forEach(function (item,index) {
  57. var dataNum = null;
  58. if(_view_.option.max === null){
  59. dataNum = item["data"];
  60. }else{
  61. dataNum = toPoint(item["data"]/_view_.option.max);
  62. }
  63. $("#"+_view_.option.id+index).width({
  64. width:dataNum
  65. })
  66. });
  67. }
  68. }
  69. };