wind-monitor.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="windMonitor">
  3. <div class="title-top" @click="getDetail">风量监测</div>
  4. <div class="wind-contents">
  5. <div class="wind-bar" ref="windBar"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script lang="ts" setup>
  10. import { ref, reactive, nextTick, onMounted, defineProps, watch } from 'vue';
  11. import * as echarts from 'echarts';
  12. import { getMaxY, getMinY } from '../clique.data'
  13. const emit = defineEmits(['goDetail']);
  14. let props = defineProps({
  15. flList: Array,
  16. });
  17. //获取dom节点
  18. let windBar = ref<any>();
  19. //坐标轴最大值
  20. let maxY = ref<any>(0);
  21. let minY = ref<any>(0)
  22. //echart数据
  23. let echartData = reactive<any>({ ydata: [], xdata: [] });
  24. //跳转详情
  25. function getDetail() {
  26. emit('goDetail', 'windrect');
  27. }
  28. function getOption() {
  29. nextTick(() => {
  30. const myChart = echarts.init(windBar.value);
  31. let option = {
  32. color: [
  33. '#63caff',
  34. '#49beff',
  35. 'rgba(74, 205, 255,.1)',
  36. '#03387a',
  37. '#03387a',
  38. '#6c93ee',
  39. '#a9abff',
  40. '#f7a23f',
  41. '#27bae7',
  42. '#ff6d9d',
  43. '#cb79ff',
  44. '#f95b5a',
  45. '#ccaf27',
  46. '#38b99c',
  47. '#93d0ff',
  48. '#bd74e0',
  49. '#fd77da',
  50. '#dea700',
  51. ],
  52. grid: {
  53. containLabel: true,
  54. left: 30,
  55. right: 30,
  56. bottom: echartData.xdata.length > 8 ? 30 : 15,
  57. top: 40,
  58. },
  59. xAxis: {
  60. type: 'category',
  61. data: echartData.xdata,
  62. axisLabel: {
  63. formatter: function (params) {
  64. var newParamsName = ''; // 最终拼接成的字符串
  65. var paramsNameNumber = params.length; // 实际标签的个数
  66. var provideNumber = 6; // 每行能显示的字的个数
  67. var rowNumber = Math.ceil(paramsNameNumber / provideNumber); // 换行的话,需要显示几行,向上取整
  68. /**
  69. * 判断标签的个数是否大于规定的个数, 如果大于,则进行换行处理 如果不大于,即等于或小于,就返回原标签
  70. */
  71. // 条件等同于rowNumber>1
  72. if (paramsNameNumber > provideNumber) {
  73. /** 循环每一行,p表示行 */
  74. for (var p = 0; p < rowNumber; p++) {
  75. var tempStr = ''; // 表示每一次截取的字符串
  76. var start = p * provideNumber; // 开始截取的位置
  77. var end = start + provideNumber; // 结束截取的位置
  78. // 此处特殊处理最后一行的索引值
  79. if (p == rowNumber - 1) {
  80. // 最后一次不换行
  81. tempStr = params.substring(start, paramsNameNumber);
  82. } else {
  83. // 每一次拼接字符串并换行
  84. tempStr = params.substring(start, end) + '\n';
  85. }
  86. newParamsName += tempStr; // 最终拼成的字符串
  87. }
  88. } else {
  89. // 将旧标签的值赋给新标签
  90. newParamsName = params;
  91. }
  92. //将最终的字符串返回
  93. return newParamsName;
  94. },
  95. fontSize: 14,
  96. margin: 15,
  97. interval: 0,
  98. textStyle: {
  99. color: '#b3b8cc',
  100. },
  101. },
  102. axisLine: {
  103. lineStyle: {
  104. color: 'rgba(62, 103, 164)',
  105. },
  106. },
  107. splitLine: {
  108. show: false,
  109. },
  110. axisTick: {
  111. show: false,
  112. },
  113. },
  114. yAxis: {
  115. type: 'value',
  116. name: '(m³/min)',
  117. // max: maxY.value,
  118. // min:minY.value,
  119. axisLabel: {
  120. textStyle: {
  121. fontSize: 14,
  122. color: '#b3b8cc',
  123. },
  124. },
  125. nameTextStyle: {
  126. color: '#fff',
  127. fontSize: 12,
  128. lineHeight: 10,
  129. },
  130. splitLine: {
  131. lineStyle: {
  132. color: 'rgba(62, 103, 164,.4)',
  133. },
  134. },
  135. axisLine: {
  136. show: false,
  137. },
  138. axisTick: {
  139. show: false,
  140. },
  141. },
  142. series: [
  143. {
  144. data: echartData.ydata,
  145. type: 'bar',
  146. barMaxWidth: 'auto',
  147. barWidth: 25,
  148. itemStyle: {
  149. color: {
  150. x: 0,
  151. y: 0,
  152. x2: 0,
  153. y2: 1,
  154. type: 'linear',
  155. global: false,
  156. colorStops: [
  157. {
  158. offset: 0,
  159. color: '#0b9eff',
  160. },
  161. {
  162. offset: 1,
  163. color: '#63caff',
  164. },
  165. ],
  166. },
  167. },
  168. label: {
  169. show: true,
  170. position: 'top',
  171. distance: 10,
  172. color: '#fff',
  173. },
  174. },
  175. {
  176. data: [1, 1, 1, 1, 1, 1, 1, 1],
  177. type: 'pictorialBar',
  178. barMaxWidth: '25',
  179. symbol: 'diamond',
  180. symbolOffset: [0, '50%'],
  181. symbolSize: [25, 15],
  182. },
  183. {
  184. data: echartData.ydata,
  185. type: 'pictorialBar',
  186. barMaxWidth: '25',
  187. symbolPosition: 'end',
  188. symbol: 'diamond',
  189. symbolOffset: [0, '-50%'],
  190. symbolSize: [25, 12],
  191. zlevel: 2,
  192. },
  193. {
  194. data: [741, 741, 741, 741, 741, 741, 741, 741],
  195. type: 'bar',
  196. barMaxWidth: 'auto',
  197. barWidth: 25,
  198. barGap: '-100%',
  199. zlevel: -1,
  200. },
  201. {
  202. data: [1, 1, 1, 1, 1, 1, 1, 1],
  203. type: 'pictorialBar',
  204. barMaxWidth: '25',
  205. symbol: 'diamond',
  206. symbolOffset: [0, '50%'],
  207. symbolSize: [25, 15],
  208. zlevel: -2,
  209. },
  210. {
  211. data: [741, 741, 741, 741, 741, 741, 741, 741],
  212. type: 'pictorialBar',
  213. barMaxWidth: '25',
  214. symbolPosition: 'end',
  215. symbol: 'diamond',
  216. symbolOffset: [0, '-50%'],
  217. symbolSize: [25, 12],
  218. zlevel: -1,
  219. },
  220. ],
  221. dataZoom: [
  222. {
  223. // 这部分是关键
  224. show: echartData.xdata.length > 8 ? true : false,
  225. type: 'slider', // 这里可以选择你需要的类型,例如 'inside'
  226. start: 0, // 数据窗口范围的起始百分比
  227. end: echartData.xdata.length > 8 && echartData.xdata.length <= 16 ? 50 : echartData.xdata.length > 16 ? 25 : 100, // 数据窗口范围的结束百分比
  228. height: 10, // 设置缩放条高度
  229. left: 'center',
  230. bottom: 25,
  231. labelPrecision: 0, // 标签精度,默认为auto
  232. showDetail: false, // 是否显示详情
  233. showDataShadow: false, // 是否显示数据阴影
  234. },
  235. ],
  236. tooltip: {
  237. trigger: 'axis',
  238. show: false,
  239. },
  240. };
  241. myChart.setOption(option);
  242. window.onresize = function () {
  243. myChart.resize();
  244. };
  245. });
  246. }
  247. watch(
  248. () => props.flList,
  249. (val) => {
  250. echartData.xdata.length = 0;
  251. echartData.ydata.length = 0;
  252. val.forEach((el: any) => {
  253. if (el.readData.m3) {
  254. echartData.xdata.push(el.strinstallpos);
  255. echartData.ydata.push(el.readData.m3);
  256. } else {
  257. echartData.xdata.push(el.strinstallpos);
  258. echartData.ydata.push('0');
  259. }
  260. });
  261. maxY.value = getMaxY(echartData.ydata)
  262. minY.value = getMinY(echartData.ydata)
  263. getOption();
  264. },
  265. {
  266. deep: true,
  267. }
  268. );
  269. onMounted(() => { });
  270. </script>
  271. <style lang="less" scoped>
  272. .windMonitor {
  273. width: 100%;
  274. height: 100%;
  275. position: relative;
  276. .title-top {
  277. position: absolute;
  278. top: 9px;
  279. left: 46px;
  280. color: #fff;
  281. font-size: 16px;
  282. font-family: 'douyuFont';
  283. cursor: pointer;
  284. &:hover {
  285. color: #66ffff;
  286. }
  287. }
  288. .wind-contents {
  289. position: absolute;
  290. left: 0;
  291. top: 36px;
  292. width: 100%;
  293. height: calc(100% - 36px);
  294. .wind-bar {
  295. width: 100%;
  296. height: 100%;
  297. }
  298. }
  299. }
  300. </style>