火箭军大屏html静态页面
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.2 KiB

  1. // var ajaxUrl = 'http://192.168.99.107:7070'
  2. var ajaxUrl = 'http://192.168.1.100:7070'
  3. var chartDom = document.getElementById('chart1');
  4. var myChart = echarts.init(chartDom);
  5. var option;
  6. var lendData = []
  7. var echartsTimer = null
  8. // 每隔一分钟刷新档案借阅和档案类型的数据
  9. echartsTimer = setInterval(() => {
  10. lendData = []
  11. option.series[0].data = lendData
  12. FetchInitBorrowerNumStatistics()
  13. myChart.setOption(option)
  14. }, 60000)
  15. option = {
  16. tooltip: {
  17. trigger: 'item'
  18. },
  19. grid: { // 边距
  20. left: '10%',
  21. right: '16%',
  22. bottom: '3%',
  23. top: '3%',
  24. containLabel: true
  25. },
  26. xAxis: {
  27. type: 'value',
  28. boundaryGap: [0, 0.01],
  29. show: false
  30. },
  31. yAxis: {
  32. type: 'category',
  33. offset: 20,
  34. axisLabel: {// 轴文字的配置
  35. show: true,
  36. textStyle: {
  37. color: '#fff',
  38. fontSize: '14'
  39. }
  40. },
  41. axisLine: {// 轴线的颜色以及宽度
  42. show: false
  43. },
  44. axisTick: {
  45. show: false
  46. },
  47. data: ['异常档案', '逾期档案', '待借档案', '已借档案', '在库档案']
  48. },
  49. series: [
  50. {
  51. name: '数量',
  52. type: 'bar',
  53. barWidth: 15, // 柱图宽度
  54. barGap: 25,
  55. showBackground: true,
  56. backgroundStyle: {
  57. color: '#02255F',
  58. barBorderRadius: [0, 10, 10, 0] // 背景圆角
  59. },
  60. itemStyle: {
  61. normal: {
  62. label: {
  63. show: true, // 开启显示
  64. distance: 20, // 条柱之间的距离
  65. position: 'right', // 在上方top在右侧right显示
  66. textStyle: { // 数值样式
  67. color: '#fff',
  68. fontSize: 14
  69. }
  70. },
  71. // 设置柱子圆角
  72. barBorderRadius: [0, 10, 10, 0],
  73. color: function (params) {
  74. var colorList = [
  75. ['#FF77AA', '#E6236D'],
  76. ['#FF7A7D', '#FF3438'],
  77. ['#FBCE9B', '#FF801E'],
  78. ['#84DFC0', '#0D9D81'],
  79. ['#5FA2E2', '#1C54EE']
  80. ]
  81. var colorItem = colorList[params.dataIndex]
  82. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  83. offset: 0,
  84. color: colorItem[0]
  85. },
  86. {
  87. offset: 1,
  88. color: colorItem[1]
  89. }
  90. ], false)
  91. }
  92. }
  93. },
  94. data: []
  95. }
  96. ]
  97. };
  98. FetchInitBorrowerNumStatistics()
  99. function FetchInitBorrowerNumStatistics(){
  100. $.ajax({
  101. url: ajaxUrl+'/api/borrow/initBorrowerNumStatistics',
  102. type: 'GET',
  103. data: {},
  104. success: function (res) {
  105. if (res.data && res.data.length !== 0) {
  106. delete res.data.total
  107. // 固定排序 '在库档案', '已借档案', '待借档案', '逾期档案', '异常档案'
  108. const borrowerArr = []
  109. for (const i in res.data) {
  110. const obj = {}
  111. obj.name = i
  112. obj.value = res.data[i]
  113. if (i === 'inStorage') {
  114. obj.sequence = 1
  115. } else if (i === 'borrow') {
  116. obj.sequence = 2
  117. } else if (i === 'waitBorrow') {
  118. obj.sequence = 3
  119. } else if (i === 'overdue') {
  120. obj.sequence = 4
  121. } else if (i === 'abnormal') {
  122. obj.sequence = 5
  123. }
  124. borrowerArr.push(obj)
  125. }
  126. arrSortByKey(borrowerArr, 'sequence', false)
  127. borrowerArr.forEach(item => {
  128. lendData.push(item.value)
  129. })
  130. option.series[0].data = lendData
  131. myChart.setOption(option)
  132. } else {
  133. var str = '<div class="empty-main">'
  134. +'<i class="empty-img"></i>'
  135. +'<p>暂无数据</p>'
  136. +'</div>'
  137. $("#chart1").html(str)
  138. }
  139. },
  140. error: function (err) {
  141. console.log(err);
  142. }
  143. });
  144. }
  145. if (option && typeof option === "object") {
  146. myChart.setOption(option, true);
  147. };
  148. function arrSortByKey (array, property, order) {
  149. return array.sort(function (a, b) {
  150. const value1 = a[property]
  151. const value2 = b[property]
  152. if (order) { // 升序
  153. return value1 - value2
  154. } else { // 降序
  155. return value2 - value1
  156. }
  157. })
  158. }