gasRiskEchart.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <div class="gasRiskBody">
  3. <p class="gasRiskTimeOut" @click="showFenXian('0',false,'')">共计风险:<span class="light-red">{{ totalCount }}</span></p>
  4. <div id="gasRisk-road" />
  5. <div v-show="!isShowBottom" class="echartsBottomTest" @mouseenter="isShowBottom = true" />
  6. <div v-show="isShowBottom" class="echartsBottom" @mouseleave="isShowBottom = false">
  7. <div class="bottomInfoBox" @click="showFenXian('0',false,$constant.RISK_GRADE.get('重大'))">
  8. <span class="iRed">{{ zhongDaCount }}</span>
  9. <span>重 大</span>
  10. </div>
  11. <div class="columLine" />
  12. <div class="bottomInfoBox" @click="showFenXian('0',false,$constant.RISK_GRADE.get('较大'))">
  13. <span class="iRed">{{ jiaoDaCount }}</span>
  14. <span>较 大</span>
  15. </div>
  16. <div class="columLine" />
  17. <div class="bottomInfoBox" @click="showFenXian('0',false,$constant.RISK_GRADE.get('一般'))">
  18. <span class="iGreen">{{ yiBanCount }}</span>
  19. <span>一 般</span>
  20. </div>
  21. <div class="columLine" />
  22. <div class="bottomInfoBox" @click="showFenXian('0',false,$constant.RISK_GRADE.get('低'))">
  23. <span class="iGreen">{{ diCount }}</span>
  24. <span>低</span>
  25. </div>
  26. </div>
  27. <!-- <el-dialog-->
  28. <!-- v-el-drag-dialog-->
  29. <!-- :close-on-click-modal="false"-->
  30. <!-- :close-on-press-escape="false"-->
  31. <!-- :lock-scroll="false"-->
  32. <!-- :modal="false"-->
  33. <!-- :visible.sync="dialogtestVueVisible"-->
  34. <!-- custom-class="dialogNew width3840px"-->
  35. <!-- width="3840px"-->
  36. <!-- >-->
  37. <!-- <testVue v-if="dialogtestVueVisible" ref="detailShow" />-->
  38. <!-- </el-dialog>-->
  39. </div>
  40. </template>
  41. <script>
  42. import * as echarts from 'echarts'
  43. import testVue from '@/views/testProfile/testVue.vue'
  44. import constant from '@/static/utils/constant'
  45. import myBus from '@/views/life-line/monitor/assets/js/myBus'
  46. export default {
  47. name: 'GasRiskEchart',
  48. components: {
  49. testVue
  50. },
  51. props: {
  52. // eslint-disable-next-line vue/require-prop-type-constructor
  53. fenXianOverHourCount: 0, // 超时数量
  54. fenXian: { // 风险
  55. type: Array,
  56. default: function() {
  57. return []
  58. }
  59. }
  60. },
  61. data() {
  62. return {
  63. isShowBottom: false,
  64. dialogtestVueVisible: false,
  65. zhongDaCount: 0,
  66. jiaoDaCount: 0,
  67. yiBanCount: 0,
  68. diCount: 0,
  69. zhongDaCountBai: 0,
  70. jiaoDaCountBai: 0,
  71. yiBanCountBai: 0,
  72. diCountBai: 0,
  73. totalCount: 0
  74. }
  75. },
  76. watch: {
  77. fenXian(newVal, oldVal) {
  78. // 监听 num 属性的数据变化
  79. // 作用 : 只要 num 的值发生变化,这个方法就会被调用
  80. // 只要没有发生变化,就没有办法进行其他的操作
  81. // newData是更新后的数据
  82. // oldData是旧数据
  83. // //console.log('newVal:', newVal)
  84. // //console.log('oldVal:', oldVal)
  85. let zhongDaCount = 0
  86. let jiaoDaCount = 0
  87. let yiBanCount = 0
  88. let diCount = 0
  89. let totalCount = 0
  90. // 0-一级,1-二级,2-三级,3-四级,
  91. for (let i = 0; i < newVal.length; i++) {
  92. if (newVal[i].fxdj == constant.RISK_GRADE.get('低')) {
  93. diCount = newVal[i].count
  94. totalCount += newVal[i].count
  95. } else if (newVal[i].fxdj == constant.RISK_GRADE.get('一般')) {
  96. yiBanCount = newVal[i].count
  97. totalCount += newVal[i].count
  98. } else if (newVal[i].fxdj == constant.RISK_GRADE.get('较大')) {
  99. jiaoDaCount = newVal[i].count
  100. totalCount += newVal[i].count
  101. } else if (newVal[i].fxdj == constant.RISK_GRADE.get('重大')) {
  102. zhongDaCount = newVal[i].count
  103. totalCount += newVal[i].count
  104. }
  105. }
  106. this.zhongDaCount = zhongDaCount
  107. this.jiaoDaCount = jiaoDaCount
  108. // //console.log('jiaoDaCount',jiaoDaCount)
  109. this.yiBanCount = yiBanCount
  110. this.diCount = diCount
  111. this.totalCount = totalCount
  112. let total = zhongDaCount + jiaoDaCount + yiBanCount + diCount
  113. if (total === 0) {
  114. total = 1
  115. }
  116. this.zhongDaCountBai = (zhongDaCount / total * 100).toFixed(2)
  117. this.jiaoDaCountBai = (jiaoDaCount / total * 100).toFixed(2)
  118. this.yiBanCountBai = (yiBanCount / total * 100).toFixed(2)
  119. this.diCountBai = (diCount / total * 100).toFixed(2)
  120. // //console.log('jiaoDaCount1',jiaoDaCount)
  121. this.getChart()
  122. // //console.log('jiaoDaCount2',jiaoDaCount)
  123. }
  124. },
  125. deactivated() {
  126. this.dialogtestVueVisible = false
  127. },
  128. mounted() {
  129. // this.getChart()
  130. },
  131. methods: {
  132. // 显示风险小屏幕, sceneCode选择场景,isOver是否超时,selectGrade选择等级
  133. showFenXian(sceneCode, isOver, selectGrade) {
  134. myBus.$emit('showFenXian', { sceneCode: '6', isOver, selectGrade })
  135. // this.dialogtestVueVisible = true
  136. // this.$nextTick(() => {
  137. // this.$refs.detailShow.toGetData('6', isOver, selectGrade)
  138. // })
  139. },
  140. getChart() {
  141. const myChart = echarts.init(document.getElementById('gasRisk-road'))
  142. var colorList = ['#FB565E', '#F19904', '#5C8BED', '#00F2FF']
  143. var datas = [{
  144. 'value': this.zhongDaCountBai,
  145. 'name': '重大风险',
  146. 'number': this.zhongDaCount
  147. },
  148. {
  149. 'value': this.jiaoDaCountBai,
  150. 'name': '较大风险',
  151. 'number': this.jiaoDaCount
  152. },
  153. {
  154. 'value': this.yiBanCountBai,
  155. 'name': '一般风险',
  156. 'number': this.yiBanCount
  157. },
  158. {
  159. 'value': this.diCountBai,
  160. 'name': '低 风 险',
  161. 'number': this.diCount
  162. }
  163. ]
  164. const maxArr = (new Array(datas.length)).fill(100)
  165. var option = {
  166. tooltip: {
  167. trigger: 'axis',
  168. formatter: (params) => {
  169. // console.log('params', params)
  170. let str = ''
  171. str += `<span
  172. style="display:inline-block;
  173. margin-right:15px;
  174. border-radius:5px;
  175. width:20px;
  176. height:20px;
  177. background-color:${params[0].color}"></span>${params[0].name}:${params[0].value}`
  178. return str
  179. },
  180. backgroundColor: 'rgba(255, 255, 255, 0.8)', // 背景
  181. padding: [10, 30, 10, 30],
  182. textStyle: {
  183. color: 'rgba(51, 51, 51, 0.9)',
  184. fontSize: 30
  185. },
  186. axisPointer: {
  187. type: 'shadow'
  188. }
  189. },
  190. legend: {
  191. show: false
  192. },
  193. grid: {
  194. top: 0,
  195. bottom: 0,
  196. left: 20,
  197. right: 20,
  198. containLabel: true
  199. },
  200. xAxis: {
  201. axisLine: {
  202. show: false
  203. },
  204. splitLine: {
  205. show: false
  206. },
  207. axisLabel: {
  208. show: false,
  209. textStyle: {
  210. color: 'white',
  211. fontSize: 30
  212. }
  213. }
  214. },
  215. yAxis: [{
  216. type: 'category',
  217. inverse: true,
  218. axisLine: {
  219. show: false
  220. },
  221. axisTick: {
  222. show: false
  223. },
  224. axisPointer: {
  225. label: {
  226. show: true,
  227. margin: 30
  228. }
  229. },
  230. data: datas.map(item => item.name),
  231. axisLabel: {
  232. margin: 30,
  233. fontSize: 30,
  234. // align: 'left',
  235. color: 'white'
  236. }
  237. }, {
  238. type: 'category',
  239. inverse: true,
  240. axisTick: 'none',
  241. axisLine: 'none',
  242. show: true,
  243. data: datas.map(item => item.value),
  244. axisLabel: {
  245. show: true,
  246. fontSize: 30,
  247. color: 'rgba(0, 242, 255, 1)',
  248. fontFamily: 'mfNumber',
  249. formatter: function(params, index) {
  250. // //console.log('param', params)
  251. return '\xa0\xa0\xa0\xa0\xa0' + params + '%'
  252. }
  253. // formatter:function (param) {
  254. // return `<div style="color: red">${param}</div>`
  255. // }
  256. }
  257. }],
  258. series: [{
  259. z: 2,
  260. name: 'value',
  261. type: 'bar',
  262. barWidth: 41,
  263. zlevel: 1,
  264. data: datas.map((item, i) => {
  265. const itemStyle = {
  266. color: i > 3 ? colorList[3] : colorList[i],
  267. shadowBlur: 50,
  268. borderWidth: 0,
  269. shadowColor: i > 3 ? colorList[3] : colorList[i],
  270. borderColor: i > 3 ? colorList[3] : colorList[i],
  271. barBorderRadius: [5, 5, 5, 5]
  272. }
  273. return {
  274. value: item.value,
  275. itemStyle: itemStyle
  276. }
  277. }),
  278. label: {
  279. show: false,
  280. position: 'right',
  281. color: '#333333',
  282. fontSize: 30,
  283. offset: [10, 0]
  284. }
  285. },
  286. {
  287. name: '背景',
  288. type: 'bar',
  289. barWidth: 41,
  290. barGap: '-100%',
  291. itemStyle: {
  292. normal: {
  293. color: 'rgba(254, 254, 254, 0.5)',
  294. barBorderRadius: [5, 5, 5, 5]
  295. }
  296. },
  297. data: maxArr
  298. }
  299. ]
  300. }
  301. myChart.setOption(option)
  302. myChart.on('click', (e) => {
  303. // console.log(e)
  304. let selectGrade = ''
  305. if (e.name === '重大风险') {
  306. selectGrade = '4'
  307. } else if (e.name === '较大风险') {
  308. selectGrade = '3'
  309. } else if (e.name === '一般风险') {
  310. selectGrade = '2'
  311. } else if (e.name === '低 风 险') {
  312. selectGrade = '1'
  313. }
  314. this.showFenXian('0', false, selectGrade)
  315. })
  316. }
  317. }
  318. }
  319. </script>
  320. <style scoped>
  321. #gasRisk-road{
  322. width: 765px;
  323. height: 550px;
  324. }
  325. /deep/ .el-dialog__wrapper {
  326. pointer-events: none !important;
  327. }
  328. /deep/ .el-dialog {
  329. pointer-events: auto !important;
  330. }
  331. /deep/ .el-dialog__headerbtn {
  332. //font-size: 75px;
  333. z-index: 10000;
  334. }
  335. </style>