dashboard.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
  2. var Controller = {
  3. index: function () {
  4. // 基于准备好的dom,初始化echarts实例
  5. var myChart = Echarts.init(document.getElementById('echart'), 'walden');
  6. // 指定图表的配置项和数据
  7. var option = {
  8. title: {
  9. text: '',
  10. subtext: ''
  11. },
  12. tooltip: {
  13. trigger: 'axis'
  14. },
  15. legend: {
  16. data: [__('Sales'), __('Orders')]
  17. },
  18. toolbox: {
  19. show: false,
  20. feature: {
  21. magicType: {show: true, type: ['stack', 'tiled']},
  22. saveAsImage: {show: true}
  23. }
  24. },
  25. xAxis: {
  26. type: 'category',
  27. boundaryGap: false,
  28. data: Orderdata.column
  29. },
  30. yAxis: {
  31. },
  32. grid: [{
  33. left: 'left',
  34. top: 'top',
  35. right: '10',
  36. bottom: 30
  37. }],
  38. series: [{
  39. name: __('Sales'),
  40. type: 'line',
  41. smooth: true,
  42. areaStyle: {
  43. normal: {
  44. }
  45. },
  46. lineStyle: {
  47. normal: {
  48. width: 1.5
  49. }
  50. },
  51. data: Orderdata.paydata
  52. },
  53. {
  54. name: __('Orders'),
  55. type: 'line',
  56. smooth: true,
  57. areaStyle: {
  58. normal: {
  59. }
  60. },
  61. lineStyle: {
  62. normal: {
  63. width: 1.5
  64. }
  65. },
  66. data: Orderdata.createdata
  67. }]
  68. };
  69. // 使用刚指定的配置项和数据显示图表。
  70. myChart.setOption(option);
  71. //动态添加数据,可以通过Ajax获取数据然后填充
  72. setInterval(function () {
  73. Orderdata.column.push((new Date()).toLocaleTimeString().replace(/^\D*/, ''));
  74. var amount = Math.floor(Math.random() * 200) + 20;
  75. Orderdata.createdata.push(amount);
  76. Orderdata.paydata.push(Math.floor(Math.random() * amount) + 1);
  77. //按自己需求可以取消这个限制
  78. if (Orderdata.column.length >= 20) {
  79. //移除最开始的一条数据
  80. Orderdata.column.shift();
  81. Orderdata.paydata.shift();
  82. Orderdata.createdata.shift();
  83. }
  84. myChart.setOption({
  85. xAxis: {
  86. data: Orderdata.column
  87. },
  88. series: [{
  89. name: __('Sales'),
  90. data: Orderdata.paydata
  91. },
  92. {
  93. name: __('Orders'),
  94. data: Orderdata.createdata
  95. }]
  96. });
  97. }, 2000);
  98. $(window).resize(function () {
  99. myChart.resize();
  100. });
  101. $(document).on("click", ".btn-checkversion", function(){
  102. top.window.$("[data-toggle=checkupdate]").trigger("click");
  103. });
  104. //读取FastAdmin的更新信息和社区动态
  105. $.ajax({
  106. url: Config.fastadmin.api_url + '/news/index',
  107. type: 'post',
  108. dataType: 'jsonp',
  109. success: function (ret) {
  110. $("#news-list").html(Template("newstpl", {news: ret.newslist}));
  111. }
  112. });
  113. $.ajax({
  114. url: Config.fastadmin.api_url + '/forum/discussion',
  115. type: 'post',
  116. dataType: 'jsonp',
  117. success: function (ret) {
  118. $("#discussion-list").html(Template("discussiontpl", {news: ret.discussionlist}));
  119. }
  120. });
  121. }
  122. };
  123. return Controller;
  124. });