left-center.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!--
  2. * @Author: daidai
  3. * @Date: 2022-02-28 16:16:42
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-04-28 09:46:18
  6. * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
  7. -->
  8. <template>
  9. <Echart
  10. id="leftCenter"
  11. :options="options"
  12. class="left_center_inner"
  13. v-if="pageflag"
  14. ref="charts"
  15. />
  16. <Reacquire v-else @onclick="getData" style="line-height: 200px">
  17. 重新获取
  18. </Reacquire>
  19. </template>
  20. <script>
  21. // import { currentGET } from 'api/modules'
  22. export default {
  23. data() {
  24. return {
  25. options: {},
  26. countUserNumData: {
  27. lockNum: 0,
  28. onlineNum: 0,
  29. offlineNum: 0,
  30. totalNum: 0,
  31. },
  32. pageflag: true,
  33. timer: null,
  34. a:1
  35. }
  36. },
  37. created() {
  38. this.getData()
  39. },
  40. mounted() {},
  41. beforeDestroy() {
  42. this.clearData()
  43. },
  44. methods: {
  45. clearData() {
  46. if (this.timer) {
  47. clearInterval(this.timer)
  48. this.timer = null
  49. }
  50. },
  51. getData() {
  52. let that = this
  53. this.pageflag = true
  54. setTimeout(function () {
  55. that.countUserNumData = {
  56. lockNum: that.a++,
  57. offlineNum: 55,
  58. onlineNum: 162,
  59. totalNum: 218,
  60. }
  61. that.$nextTick(() => {
  62. that.init()
  63. that.switper()
  64. })
  65. }, 1000)
  66. // this.pageflag =false
  67. // currentGET('big1').then(res => {
  68. // //只打印一次
  69. // if (!this.timer) {
  70. // console.log('设备总览', res);
  71. // }
  72. // if (res.success) {
  73. // this.countUserNumData = res.data
  74. // this.$nextTick(() => {
  75. // this.init()
  76. // this.switper()
  77. // })
  78. // } else {
  79. // this.pageflag = false
  80. // this.$Message({
  81. // text: res.msg,
  82. // type: 'warning'
  83. // })
  84. // }
  85. // })
  86. },
  87. //轮询
  88. switper() {
  89. if (this.timer) {
  90. return
  91. }
  92. let looper = (a) => {
  93. this.getData()
  94. }
  95. this.timer = setInterval(looper, 1000)
  96. let myChart = this.$refs.charts.chart
  97. myChart.on('mouseover', (params) => {
  98. this.clearData()
  99. })
  100. myChart.on('mouseout', (params) => {
  101. this.timer = setInterval(looper, 1000)
  102. })
  103. },
  104. init() {
  105. debugger
  106. let total = this.countUserNumData.totalNum
  107. let colors = ['#ECA444', '#33A1DB', '#56B557']
  108. let piedata = {
  109. name: '用户总览',
  110. type: 'pie',
  111. radius: ['42%', '65%'],
  112. avoidLabelOverlap: false,
  113. itemStyle: {
  114. borderRadius: 4,
  115. borderColor: 'rgba(0,0,0,0)',
  116. borderWidth: 2,
  117. },
  118. color: colors,
  119. data: [
  120. // {
  121. // value: 0,
  122. // name: "告警",
  123. // label: {
  124. // shadowColor: colors[0],
  125. // },
  126. // },
  127. {
  128. value: this.countUserNumData.lockNum,
  129. name: '锁定',
  130. label: {
  131. shadowColor: colors[0],
  132. },
  133. },
  134. {
  135. value: this.countUserNumData.onlineNum,
  136. name: '在线',
  137. label: {
  138. shadowColor: colors[2],
  139. },
  140. },
  141. {
  142. value: this.countUserNumData.offlineNum,
  143. name: '离线',
  144. label: {
  145. shadowColor: colors[1],
  146. },
  147. },
  148. ],
  149. }
  150. this.options = {
  151. title: {
  152. // zlevel: 0,
  153. text: ['{value|' + total + '}', '{name|总数}'].join('\n'),
  154. top: 'center',
  155. left: 'center',
  156. textStyle: {
  157. rich: {
  158. value: {
  159. color: '#ffffff',
  160. fontSize: 24,
  161. fontWeight: 'bold',
  162. lineHeight: 20,
  163. },
  164. name: {
  165. color: '#ffffff',
  166. lineHeight: 20,
  167. },
  168. },
  169. },
  170. },
  171. tooltip: {
  172. trigger: 'item',
  173. backgroundColor: 'rgba(0,0,0,.6)',
  174. borderColor: 'rgba(147, 235, 248, .8)',
  175. textStyle: {
  176. color: '#FFF',
  177. },
  178. },
  179. legend: {
  180. show: false,
  181. top: '5%',
  182. left: 'center',
  183. },
  184. series: [
  185. //展示圆点
  186. {
  187. ...piedata,
  188. tooltip: { show: true },
  189. label: {
  190. formatter: ' {b|{b}} \n {c|{c}个} {per|{d}%} ',
  191. // position: "outside",
  192. rich: {
  193. b: {
  194. color: '#fff',
  195. fontSize: 12,
  196. lineHeight: 26,
  197. },
  198. c: {
  199. color: '#31ABE3',
  200. fontSize: 14,
  201. },
  202. per: {
  203. color: '#31ABE3',
  204. fontSize: 14,
  205. },
  206. },
  207. },
  208. labelLine: {
  209. length: 20, // 第一段线 长度
  210. length2: 36, // 第二段线 长度
  211. show: true,
  212. emphasis: {
  213. show: true,
  214. },
  215. },
  216. },
  217. {
  218. ...piedata,
  219. tooltip: { show: true },
  220. itemStyle: {},
  221. label: {
  222. backgroundColor: 'auto', //圆点颜色,auto:映射的系列色
  223. height: 0,
  224. width: 0,
  225. lineHeight: 0,
  226. borderRadius: 2.5,
  227. shadowBlur: 8,
  228. shadowColor: 'auto',
  229. padding: [2.5, -2.5, 2.5, -2.5],
  230. },
  231. labelLine: {
  232. length: 20, // 第一段线 长度
  233. length2: 36, // 第二段线 长度
  234. show: false,
  235. },
  236. },
  237. ],
  238. }
  239. },
  240. },
  241. }
  242. </script>
  243. <style lang='scss' scoped>
  244. </style>