faultEchartLine.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="faultEchartLine">
  3. <div class="box-search">
  4. <a-date-picker v-model:value="historyParams.startTime" valueFormat="YYYY-MM-DD HH:mm:ss" placeholder="开始时间"
  5. size="small" :showTime="true" style="position: absolute; z-index: 99; left: 0px; width: 170px; top: 2px"
  6. @change="changeStart" />
  7. <a-date-picker v-model:value="historyParams.endTime" valueFormat="YYYY-MM-DD HH:mm:ss" placeholder="结束时间"
  8. size="small" :showTime="true" style="position: absolute; z-index: 99; left: 175px; width: 170px; top: 2px"
  9. @change="changeEnd" />
  10. <a-select ref="select" v-model:value="historyParams.interval" placeholder="请选择间隔时间" size="small"
  11. style="position: absolute; z-index: 99; top: 2px; left: 350px; width: 150px">
  12. <a-select-option v-for="(item, index) in skipOption" :key="index" :value="item.value">{{ item.label
  13. }}</a-select-option>
  14. </a-select>
  15. </div>
  16. <div ref="echartline" class="echart-line"></div>
  17. </div>
  18. </template>
  19. <script setup lang="ts">
  20. import dayjs from 'dayjs';
  21. import { ref, reactive, onMounted, nextTick, watch } from 'vue'
  22. import * as echarts from 'echarts';
  23. import { listdays } from '../main.api'
  24. let props = defineProps({
  25. //当前激活风机索引
  26. warningMonitorRowIndex: {
  27. type: Number
  28. },
  29. deviceId: {
  30. type: String
  31. },
  32. deviceType: {
  33. type: String
  34. },
  35. Type: {
  36. type: String
  37. },
  38. addData: {
  39. type: String
  40. },
  41. legendName: {
  42. type: String
  43. },
  44. echartColor: {
  45. type: String
  46. }
  47. })
  48. let skipOption = ref<any[]>([
  49. { label: '1秒', value: '1' },
  50. { label: '5秒', value: '2' },
  51. { label: '10秒', value: '3' },
  52. { label: '30秒', value: '4' },
  53. { label: '1分钟', value: '5' },
  54. { label: '10分钟', value: '6' },
  55. { label: '30分钟', value: '7' },
  56. { label: '1小时', value: '8' },
  57. { label: '1天', value: '9' },
  58. ])
  59. let historyParams = reactive({
  60. skip: '8',
  61. startTime: dayjs().startOf('date').format('YYYY-MM-DD HH:mm:ss'),
  62. endTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  63. interval: '1h',
  64. })
  65. let echartline = ref(null)
  66. let xData = ref<any[]>([])
  67. let yData = ref<any[]>([])
  68. function changeStart(val) {
  69. historyParams.startTime = val
  70. getData()
  71. }
  72. function changeEnd(val) {
  73. historyParams.endTime = val
  74. getData()
  75. }
  76. function getOption() {
  77. nextTick(() => {
  78. let myChart = echarts.init(echartline.value);
  79. let option = {
  80. grid: {
  81. top: '22%',
  82. left: '5%',
  83. bottom: '13%',
  84. right: '5%',
  85. // containLabel: true,
  86. },
  87. tooltip: {
  88. trigger: 'axis',
  89. backgroundColor: 'rgba(0, 0, 0, .6)',
  90. textStyle: {
  91. color: '#fff',
  92. fontSize: 12,
  93. },
  94. },
  95. legend: {
  96. align: 'left',
  97. right: 'center',
  98. top: '10',
  99. type: 'plain',
  100. textStyle: {
  101. color: '#7ec7ff',
  102. fontSize: 14,
  103. },
  104. // icon:'rect',
  105. itemGap: 25,
  106. itemWidth: 18,
  107. icon: 'path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z',
  108. data: [
  109. {
  110. name: props.legendName,
  111. },
  112. ],
  113. },
  114. xAxis: [
  115. {
  116. type: 'category',
  117. boundaryGap: false,
  118. axisLabel: {
  119. // formatter: '{value}',
  120. fontSize: 14,
  121. margin: 20,
  122. textStyle: {
  123. color: '#b3b8cc',
  124. },
  125. },
  126. axisLine: {
  127. lineStyle: {
  128. color: 'rgba(48, 98, 162,.4)',
  129. },
  130. },
  131. splitLine: {
  132. show: false,
  133. },
  134. axisTick: {
  135. show: false,
  136. },
  137. data: xData.value,
  138. },
  139. ],
  140. yAxis: [
  141. {
  142. boundaryGap: false,
  143. type: 'value',
  144. // max: props.maxY,
  145. // min: props.minY,
  146. axisLabel: {
  147. textStyle: {
  148. color: '#b3b8cc',
  149. },
  150. formatter: '{value}',
  151. },
  152. name: '',
  153. nameTextStyle: {
  154. color: '#fff',
  155. fontSize: 12,
  156. lineHeight: 10,
  157. },
  158. splitLine: {
  159. lineStyle: {
  160. color: 'rgba(48, 98, 162,.4)',
  161. },
  162. },
  163. axisLine: {
  164. show: true,
  165. lineStyle: {
  166. color: 'rgba(48, 98, 162,.4)',
  167. },
  168. },
  169. axisTick: {
  170. show: false,
  171. },
  172. },
  173. ],
  174. series: [
  175. {
  176. name: props.legendName,
  177. type: 'line',
  178. smooth: true,
  179. symbol: 'none',
  180. zlevel: 3,
  181. itemStyle: {
  182. color: props.echartColor,
  183. borderColor: props.echartColor,
  184. },
  185. lineStyle: {
  186. normal: {
  187. width: 2,
  188. color: props.echartColor,
  189. },
  190. },
  191. data: yData.value,
  192. },
  193. ],
  194. };
  195. myChart.setOption(option);
  196. window.onresize = function () {
  197. myChart.resize();
  198. };
  199. });
  200. }
  201. async function getData() {
  202. let res = await listdays({ ttime_begin: historyParams.startTime, ttime_end: historyParams.endTime, strtype: props.deviceType, gdeviceid: props.deviceId, skip: historyParams.skip, pageSize: 100, pageNo: 1 })
  203. let data = res.datalist.records
  204. xData.value = res.xlist
  205. if (props.Type == 'tempZw') {
  206. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Tempzw) : data.map(el => el.readData.Fan2Tempzw)
  207. } else if (props.Type == 'tempDj') {
  208. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Tempdj) : data.map(el => el.readData.Fan2Tempdj)
  209. } else if (props.Type == 'Dl') {
  210. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dl) : data.map(el => el.readData.Fan2Dl)
  211. } else if (props.Type == 'Dy') {
  212. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dy) : data.map(el => el.readData.Fan2Dy)
  213. } else if (props.Type == 'jxzd') {
  214. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Jxzd) : data.map(el => el.readData.Fan2Jxzd)
  215. } else if (props.Type == 'czzd') {
  216. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Czzd) : data.map(el => el.readData.Fan2Czzd)
  217. }
  218. getOption()
  219. }
  220. watch(() => props.addData, (newV, oldV) => {
  221. if (yData.value.length>=10) {
  222. yData.value.push(newV)
  223. yData.value.shift()
  224. } else {
  225. yData.value.push(newV)
  226. }
  227. getOption()
  228. }, { immediate: true })
  229. onMounted(() => {
  230. getData()
  231. })
  232. </script>
  233. <style lang="less" scoped>
  234. @import '/@/design/theme.less';
  235. .faultEchartLine {
  236. position: relative;
  237. width: 100%;
  238. height: 100%;
  239. }
  240. .box-search {
  241. width: 100%;
  242. height: 30px;
  243. }
  244. .echart-line {
  245. width: 100%;
  246. height: calc(100% - 30px);
  247. }
  248. .@{ventSpace}-picker {
  249. background: #00000017 !important;
  250. border: 1px solid @vent-form-item-border !important;
  251. input,
  252. .@{ventSpace}-select-selection-item,
  253. .@{ventSpace}-picker-suffix {
  254. color: #fff !important;
  255. }
  256. .@{ventSpace}-select-selection-placeholder {
  257. color: #b7b7b7 !important;
  258. }
  259. }
  260. .@{ventSpace}-picker-separator {
  261. color: #fff !important;
  262. }
  263. :deep(.@{ventSpace}-select-dropdown) {
  264. color: #000 !important;
  265. .@{ventSpace}-select-item {
  266. color: #000 !important;
  267. }
  268. }
  269. :deep(.@{ventSpace}-picker-input > input) {
  270. color: #fff !important;
  271. }
  272. :deep(.@{ventSpace}-picker-suffix) {
  273. color: #fff !important;
  274. }
  275. :deep(.@{ventSpace}-select-selector) {
  276. color: #fff !important;
  277. background: #00000017 !important;
  278. border: 1px solid @vent-form-item-border !important;
  279. }
  280. :deep(.@{ventSpace}-select-arrow) {
  281. color: #fff !important;
  282. }
  283. </style>