dialogChartOne-old.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="dialogVisible"
  5. width="800px"
  6. @close="closeDialog()"
  7. @open="open"
  8. >
  9. <div style="width: 100%; height: 400px">
  10. <div shadow="never" class="homeBoxCard" v-loading="loading">
  11. <div
  12. style="height: 400px"
  13. ref="lineChartBanlance"
  14. id="lineChartBanlance"
  15. />
  16. </div>
  17. </div>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. import { defineComponent, ref, watchEffect, onMounted, watch } from 'vue'
  22. import * as echarts from 'echarts'
  23. export default defineComponent({
  24. name: 'DialogChartOne',
  25. components: {
  26. },
  27. emits: ['closeDialog'],
  28. props: {
  29. flag: Boolean,
  30. dialogTitle: String,
  31. itemInfo: Object,
  32. echartsAllData: Array,
  33. echartsTitle: String,
  34. },
  35. setup(props, context) {
  36. context
  37. const dialogVisible = ref(false)
  38. const dataList = ref([])
  39. const dataTimes = ref([])
  40. const getData = async () => {
  41. var arrOld = props.echartsAllData
  42. let dataTime = arrOld.map((item) => {
  43. return item.dataTime
  44. })
  45. let cos = arrOld.map((item) => {
  46. return item.cos
  47. })
  48. let ua = arrOld.map((item) => {
  49. return item.ua
  50. })
  51. let ub = arrOld.map((item) => {
  52. return item.ub
  53. })
  54. let uc = arrOld.map((item) => {
  55. return item.uc
  56. })
  57. dataTimes.value = dataTime;
  58. switch (props.echartsTitle) {
  59. case '功率因数':
  60. dataList.value = cos
  61. break
  62. case 'A相电压':
  63. dataList.value = ua
  64. break
  65. case 'B相电压':
  66. dataList.value = ub
  67. break
  68. case 'C相电压':
  69. dataList.value = uc
  70. break
  71. default:
  72. }
  73. }
  74. function echarts2() {
  75. // 新建一个promise对象
  76. let newPromise = new Promise((resolve) => {
  77. resolve()
  78. })
  79. //然后异步执行echarts的初始化函数
  80. newPromise.then(() => {
  81. // 此dom为echarts图标展示dom
  82. let myChart = echarts.init(document.getElementById('lineChartBanlance'))
  83. myChart.setOption({
  84. color: ['#1187FF'],
  85. legend: {
  86. top: '0',
  87. // data: ['电流不平衡度'],
  88. },
  89. tooltip: {
  90. trigger: 'axis',
  91. axisPointer: { type: 'cross' },
  92. },
  93. grid: {
  94. left: '20',
  95. right: '40',
  96. top: '40',
  97. bottom: '30',
  98. containLabel: true,
  99. },
  100. xAxis: {
  101. axisLabel: {
  102. color: '#444',
  103. fontSize: 14,
  104. },
  105. /*改变xy轴颜色*/
  106. axisLine: {
  107. lineStyle: {
  108. color: '#444',
  109. width: 1, //这里是为了突出显示加上的
  110. },
  111. },
  112. boundaryGap: false,
  113. data: dataTimes.value,
  114. },
  115. yAxis: {
  116. name: '%',
  117. nameTextStyle: {
  118. color: 'black',
  119. fontSize: 10,
  120. },
  121. type: 'value',
  122. axisTick: {
  123. show: true, //去除刻度线
  124. },
  125. axisLabel: {
  126. color: 'black', // 文本颜色
  127. },
  128. axisLine: {
  129. show: true, // 去除轴线
  130. lineStyle: {
  131. color: 'black',
  132. },
  133. },
  134. splitNumber: 5,
  135. splitLine: {
  136. show: true,
  137. lineStyle: {
  138. color: '#9d9d9d',
  139. },
  140. },
  141. },
  142. series: [
  143. {
  144. name: props.echartsTitle + '实时数据',
  145. type: 'line',
  146. symbolSize: 7,
  147. smooth: false,
  148. data: dataList.value,
  149. markLine: {
  150. //最大值和最小值
  151. // data: [
  152. // {
  153. // yAxis: 30,
  154. // label: {
  155. // position: 'middle',
  156. // formatter: '严重三项不平衡',
  157. // },
  158. // lineStyle: {
  159. // width: 2,
  160. // color: '#FF5D1D',
  161. // },
  162. // },
  163. // {
  164. // yAxis: 14,
  165. // label: {
  166. // position: 'middle',
  167. // formatter: '不平衡度',
  168. // },
  169. // lineStyle: {
  170. // width: 2,
  171. // color: '#f2e251',
  172. // },
  173. // },
  174. // ],
  175. },
  176. },
  177. ],
  178. })
  179. window.addEventListener('resize', () => {
  180. myChart.resize()
  181. })
  182. })
  183. }
  184. // 关闭弹框
  185. const closeDialog = () => {
  186. context.emit('closeDialog', false)
  187. dialogVisible.value = false
  188. }
  189. watchEffect((fn) => {
  190. fn
  191. dialogVisible.value = props.flag
  192. })
  193. const writeValue = (val) => {
  194. val
  195. getData()
  196. echarts2()
  197. }
  198. //监听变化
  199. watch(
  200. () => props.echartsAllData,
  201. (newVal, oldVal, clear) => {
  202. // 执行异步任务,并得到关闭异步任务的 id
  203. // console.log(newVal)
  204. let id = writeValue(newVal, oldVal)
  205. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  206. clear(() => clearTimeout(id))
  207. },
  208. { lazy: true }
  209. )
  210. onMounted(() => {})
  211. return {
  212. closeDialog,
  213. dialogVisible,
  214. echarts2,
  215. }
  216. },
  217. })
  218. </script>
  219. <style scoped lang="scss">
  220. </style>