faultEchartLine.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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, getHistoryData } from '../fanLocal.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: Object as any
  40. },
  41. legendName: {
  42. type: String
  43. },
  44. echartColor: {
  45. type: String
  46. },
  47. selectData: {
  48. type: Object as any
  49. }
  50. })
  51. let skipOption = ref<any[]>([
  52. { label: '1秒', value: '1' },
  53. { label: '5秒', value: '2' },
  54. { label: '10秒', value: '3' },
  55. { label: '30秒', value: '4' },
  56. { label: '1分钟', value: '5' },
  57. { label: '10分钟', value: '6' },
  58. { label: '30分钟', value: '7' },
  59. { label: '1小时', value: '8' },
  60. { label: '1天', value: '9' },
  61. ])
  62. let historyParams = reactive({
  63. skip: '8',
  64. startTime: dayjs().startOf('date').subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'),
  65. endTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  66. interval: '1h',
  67. })
  68. let echartline = ref(null)
  69. let xData = ref<any[]>([])
  70. let yData = ref<any[]>([])
  71. function changeStart(val) {
  72. historyParams.startTime = val
  73. getData()
  74. }
  75. function changeEnd(val) {
  76. historyParams.endTime = val
  77. getData()
  78. }
  79. function getOption() {
  80. nextTick(() => {
  81. let myChart = echarts.init(echartline.value);
  82. let option = {
  83. grid: {
  84. top: '22%',
  85. left: '5%',
  86. bottom: '13%',
  87. right: '5%',
  88. // containLabel: true,
  89. },
  90. tooltip: {
  91. trigger: 'axis',
  92. backgroundColor: 'rgba(0, 0, 0, .6)',
  93. textStyle: {
  94. color: '#fff',
  95. fontSize: 12,
  96. },
  97. },
  98. legend: {
  99. align: 'left',
  100. right: 'center',
  101. top: '10',
  102. type: 'plain',
  103. textStyle: {
  104. color: '#7ec7ff',
  105. fontSize: 14,
  106. },
  107. // icon:'rect',
  108. itemGap: 25,
  109. itemWidth: 18,
  110. 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',
  111. data: [
  112. {
  113. name: props.legendName,
  114. },
  115. ],
  116. },
  117. xAxis: [
  118. {
  119. type: 'category',
  120. boundaryGap: false,
  121. axisLabel: {
  122. // formatter: '{value}',
  123. fontSize: 14,
  124. margin: 20,
  125. textStyle: {
  126. color: '#b3b8cc',
  127. },
  128. },
  129. axisLine: {
  130. lineStyle: {
  131. color: 'rgba(48, 98, 162,.4)',
  132. },
  133. },
  134. splitLine: {
  135. show: false,
  136. },
  137. axisTick: {
  138. show: false,
  139. },
  140. data: xData.value,
  141. },
  142. ],
  143. yAxis: [
  144. {
  145. boundaryGap: false,
  146. type: 'value',
  147. // max: props.maxY,
  148. // min: props.minY,
  149. axisLabel: {
  150. textStyle: {
  151. color: '#b3b8cc',
  152. },
  153. formatter: '{value}',
  154. },
  155. name: '',
  156. nameTextStyle: {
  157. color: '#fff',
  158. fontSize: 12,
  159. lineHeight: 10,
  160. },
  161. splitLine: {
  162. lineStyle: {
  163. color: 'rgba(48, 98, 162,.4)',
  164. },
  165. },
  166. axisLine: {
  167. show: true,
  168. lineStyle: {
  169. color: 'rgba(48, 98, 162,.4)',
  170. },
  171. },
  172. axisTick: {
  173. show: false,
  174. },
  175. },
  176. ],
  177. series: [
  178. {
  179. name: props.legendName,
  180. type: 'line',
  181. smooth: true,
  182. symbol: 'none',
  183. zlevel: 3,
  184. itemStyle: {
  185. color: props.echartColor,
  186. borderColor: props.echartColor,
  187. },
  188. lineStyle: {
  189. normal: {
  190. width: 2,
  191. color: props.echartColor,
  192. },
  193. },
  194. data: yData.value,
  195. },
  196. ],
  197. };
  198. myChart.setOption(option);
  199. window.onresize = function () {
  200. myChart.resize();
  201. };
  202. });
  203. }
  204. async function getData() {
  205. if (props.selectData.stationtype && props.selectData.stationtype != 'redis') {
  206. let deviceNum = props.warningMonitorRowIndex == 0 ? 'Fan1' : 'Fan2'
  207. let res = await listdays({ deviceNum: deviceNum, ttime_begin: historyParams.startTime, ttime_end: historyParams.endTime, strtype: props.deviceType, gdeviceid: props.deviceId, skip: historyParams.skip, pageSize: 100, pageNo: 1 })
  208. let data = res.datalist.records
  209. xData.value = res.xlist
  210. if (props.Type == 'windSpeed') {
  211. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1WindSpeed) : data.map(el => el.readData.Fan2WindSpeed)
  212. } else if (props.Type == 'wind') {
  213. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Wind) : data.map(el => el.readData.Fan2Wind)
  214. } else if (props.Type == 'Dl') {
  215. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dl) : data.map(el => el.readData.Fan2Dl)
  216. } else if (props.Type == 'Dy') {
  217. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dy) : data.map(el => el.readData.Fan2Dy)
  218. } else if (props.Type == 'wsnd') {
  219. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Wsnd) : data.map(el => el.readData.Fan2Wsnd)
  220. } else if (props.Type == 'Zd') {
  221. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Zd) : data.map(el => el.readData.Fan2Zd)
  222. }
  223. getOption()
  224. } else {
  225. let res = await getHistoryData({ pageNum: 1, pageSize: 100, startTime: historyParams.startTime, endTime: historyParams.endTime, deviceId: props.deviceId, interval: '1h', isEmployee: true, })
  226. let data = res.records
  227. xData.value = res.xlist
  228. if (props.Type == 'windSpeed') {
  229. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1WindSpeed) : data.map(el => el.readData.Fan2WindSpeed)
  230. } else if (props.Type == 'wind') {
  231. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Wind) : data.map(el => el.readData.Fan2Wind)
  232. } else if (props.Type == 'Dl') {
  233. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dl) : data.map(el => el.readData.Fan2Dl)
  234. } else if (props.Type == 'Dy') {
  235. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Dy) : data.map(el => el.readData.Fan2Dy)
  236. } else if (props.Type == 'wsnd') {
  237. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Wsnd) : data.map(el => el.readData.Fan2Wsnd)
  238. } else if (props.Type == 'Zd') {
  239. yData.value = props.warningMonitorRowIndex == 0 ? data.map(el => el.readData.Fan1Zd) : data.map(el => el.readData.Fan2Zd)
  240. }
  241. getOption()
  242. }
  243. }
  244. watch(() => props.addData, (newV, oldV) => {
  245. if (yData.value.length >= 20) {
  246. yData.value.push(newV.y)
  247. yData.value.shift()
  248. xData.value.push(newV.x)
  249. xData.value.shift()
  250. } else {
  251. yData.value.push(newV.y)
  252. xData.value.push(newV.x)
  253. }
  254. getOption()
  255. }, { immediate: true })
  256. onMounted(() => {
  257. getData()
  258. })
  259. </script>
  260. <style lang="less" scoped>
  261. @import '/@/design/theme.less';
  262. .faultEchartLine {
  263. position: relative;
  264. width: 100%;
  265. height: 100%;
  266. }
  267. .box-search {
  268. width: 100%;
  269. height: 30px;
  270. }
  271. .echart-line {
  272. width: 100%;
  273. height: calc(100% - 30px);
  274. }
  275. .@{ventSpace}-picker {
  276. background: #00000017 !important;
  277. border: 1px solid @vent-form-item-border !important;
  278. input,
  279. .@{ventSpace}-select-selection-item,
  280. .@{ventSpace}-picker-suffix {
  281. color: #fff !important;
  282. }
  283. .@{ventSpace}-select-selection-placeholder {
  284. color: #b7b7b7 !important;
  285. }
  286. }
  287. .@{ventSpace}-picker-separator {
  288. color: #fff !important;
  289. }
  290. :deep(.@{ventSpace}-select-dropdown) {
  291. color: #000 !important;
  292. .@{ventSpace}-select-item {
  293. color: #000 !important;
  294. }
  295. }
  296. :deep(.@{ventSpace}-picker-input > input) {
  297. color: #fff !important;
  298. }
  299. :deep(.@{ventSpace}-picker-suffix) {
  300. color: #fff !important;
  301. }
  302. :deep(.@{ventSpace}-select-selector) {
  303. color: #fff !important;
  304. background: #00000017 !important;
  305. border: 1px solid @vent-form-item-border !important;
  306. }
  307. :deep(.@{ventSpace}-select-arrow) {
  308. color: #fff !important;
  309. }
  310. </style>