SensorStatusCircle.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="item sensor-status-chart-circle">
  3. <div class="title">
  4. <span class="name">传感器状态<span class="number" style="padding-left:10px;">{{ total }}</span></span>
  5. <!-- <span class="detail" @click="linkTo">详情>></span> -->
  6. </div>
  7. <div class="container">
  8. <div v-if="status" id="sensor-status-chart-circle" />
  9. <div class="legend">
  10. <div v-for="(legend,index) in option.series" :key="index" class="legend-item">
  11. <div class="lable">{{ legend.name }}</div>
  12. <div class="number" :style="{background: `linear-gradient(90deg, #021a34 0%, ${legend.data[0].itemStyle.color} 100%)`}">
  13. <span>{{ legend.data[0].value }}</span>
  14. <span class="unit">台</span>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import * as echarts from 'echarts'
  23. export default {
  24. name: 'SensorStatusCircle',
  25. data() {
  26. return {
  27. myChart: null,
  28. status: true,
  29. total: '',
  30. option: {
  31. tooltip: {
  32. trigger: 'item',
  33. formatter: '{a} <br/>{b}: {c} ({d}%)'
  34. },
  35. series: [
  36. {
  37. name: '正常',
  38. type: 'pie',
  39. selectedMode: 'single',
  40. radius: ['65%', '70%'],
  41. center: ['25%', '50%'],
  42. clockWise: false,
  43. label: {
  44. show: false
  45. },
  46. labelLine: {
  47. show: false
  48. },
  49. data: [
  50. { value: 0, name: '正常', itemStyle: { color: '#2affff' }},
  51. { value: 0, name: '其他', itemStyle: { color: '#021a34' }}
  52. ]
  53. },
  54. {
  55. name: '一般报警',
  56. type: 'pie',
  57. clockWise: false,
  58. selectedMode: 'single',
  59. radius: ['55%', '60%'],
  60. center: ['25%', '50%'],
  61. label: {
  62. show: false
  63. },
  64. labelLine: {
  65. show: false
  66. },
  67. data: [
  68. { value: 0, name: '一般报警', itemStyle: { color: '#fac858' }},
  69. { value: 0, name: '其他', itemStyle: { color: '#021a34' }}
  70. ]
  71. },
  72. {
  73. name: '重大报警',
  74. type: 'pie',
  75. clockWise: false,
  76. selectedMode: 'single',
  77. radius: ['45%', '50%'],
  78. center: ['25%', '50%'],
  79. label: {
  80. show: false
  81. },
  82. labelLine: {
  83. show: false
  84. },
  85. data: [
  86. { value: 0, name: '重大报警', itemStyle: { color: '#f44336' }},
  87. { value: 0, name: '其他', itemStyle: { color: '#021a34' }}
  88. ]
  89. }
  90. // ,{
  91. // name: '离线报警',
  92. // type: 'pie',
  93. // clockWise: false,
  94. // radius: ['35%', '40%'],
  95. // center: ['25%', '50%'],
  96. // label: {
  97. // show: false
  98. // },
  99. // data: [
  100. // { value: 0, name: '离线报警', itemStyle: { color: '#5470c6' }},
  101. // { value: 0, name: '总数', itemStyle: { color: '#021a34' }}
  102. // ]
  103. // }
  104. ]
  105. }
  106. }
  107. },
  108. created() {
  109. this.$nextTick(() => {
  110. this.init()
  111. })
  112. },
  113. destroyed() {
  114. this.status = false
  115. },
  116. methods: {
  117. init() {
  118. var chartDom = document.getElementById('sensor-status-chart-circle')
  119. var myChart = echarts.init(chartDom)
  120. this.option && myChart.setOption(this.option)
  121. myChart.on('click', function(params) {
  122. console.log('SensorStatus', params)
  123. })
  124. this.myChart = myChart
  125. },
  126. loadData(data) {
  127. let tableData = []
  128. for (let i = 0; i < data.length; i++) {
  129. tableData = tableData.concat(data[i].goafSensorData.map((item, index) => { return { ...item, goafDevName: data[i].goafDevName, goafDevTypename: data[i].goafDevTypename } }))
  130. }
  131. const normal = tableData.filter(item => !item.goafSensorAlarmType).length
  132. const level_1 = tableData.filter(item => item.goafSensorAlarmType && item.goafSensorAlarmLevel === 0).length
  133. const level_2 = tableData.filter(item => item.goafSensorAlarmType && item.goafSensorAlarmLevel === 2).length
  134. const option = JSON.parse(JSON.stringify(this.option))
  135. const total = tableData.length
  136. option.series[0].data[0].value = normal
  137. option.series[1].data[0].value = level_1
  138. option.series[2].data[0].value = level_2
  139. option.series[0].data[1].value = total - normal
  140. option.series[1].data[1].value = total - level_1
  141. option.series[2].data[1].value = total - level_2
  142. this.option = option
  143. if (!this.myChart) {
  144. var chartDom = document.getElementById('sensor-status-chart-circle')
  145. var myChart = echarts.init(chartDom)
  146. this.myChart = myChart
  147. }
  148. this.myChart.setOption(option)
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .sensor-status-chart-circle{
  155. ::v-deep .container{
  156. height: 26vh !important;
  157. // min-height: 164px;
  158. position: relative;
  159. #sensor-status-chart-circle{
  160. width: 95%;
  161. height: 100%;
  162. }
  163. .legend{
  164. position: absolute;
  165. right: 20px;
  166. top: 20%;
  167. .legend-item{
  168. color: #fff;
  169. display: flex;
  170. justify-content: flex-end;
  171. align-items: center;
  172. .lable{
  173. padding: 8px 10px;
  174. flex: 1;
  175. }
  176. .number{
  177. width: 100px;
  178. padding: 8px 10px;
  179. margin-left: 10px;
  180. text-align: center;
  181. .unit{
  182. padding-left: 10px;
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. </style>