ContinueData.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <script setup>
  2. import { onMounted, onUnmounted, watch, ref } from 'vue';
  3. import * as echarts from 'echarts';
  4. import { formatDecimals } from "@/utils/format";
  5. import { screenApi } from '@/api/screen';
  6. import dayjs from 'dayjs';
  7. import LayoutCard from './LayoutCard.vue';
  8. import { getBarOptions } from '../config/echartOption';
  9. const props = defineProps({
  10. screenData: {
  11. type: Object,
  12. default: []
  13. }
  14. })
  15. let barOption = {};
  16. let lineOption = {};
  17. let timer = null;
  18. let chart = null;
  19. const activeIndex = ref(0);
  20. const echartRef = ref(null);
  21. const windowResize = () => {
  22. clearTimeout(timer);
  23. timer = setTimeout(() => chart.resize(), 100);
  24. };
  25. watch(() => props.screenData, (currentVal) => {
  26. const { no3Hlj1Jqr, no3Hlj2Jqr, nh31Jqr, nh32Jqr, tpRccJqr } = currentVal;
  27. const options = [ no3Hlj1Jqr, no3Hlj2Jqr, nh31Jqr, nh32Jqr, tpRccJqr ].map(item => {
  28. return item ? Number(item.toFixed(2)) : 0;
  29. })
  30. barOption = options;
  31. chart.setOption( getBarOptions(options) )
  32. })
  33. const getLineOptions = ({xAxisData, seriesData}) => {
  34. const colors = ['#F7931E', '#2454FF', '#00FFFF', '#00FF00', '#3DB0F1', '#F4CF35',];
  35. const series = Object.keys(seriesData).map(((key, index) => {
  36. const item = seriesData[key];
  37. const color = colors[index];
  38. return {
  39. name: key,
  40. type: "line",
  41. smooth: true,
  42. symbol: 'none',
  43. areaStyle: {
  44. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  45. {
  46. offset: 0,
  47. color,
  48. },
  49. {
  50. offset: 1,
  51. color: "rgba(255, 255, 255, 0.3)",
  52. },
  53. ]),
  54. },
  55. itemStyle: { color },
  56. lineStyle: {
  57. width: '2',
  58. color
  59. },
  60. data: item
  61. }
  62. }));
  63. const option = {
  64. grid: {
  65. bottom: '4%',
  66. top: "23%",
  67. left: "5%",
  68. right: "2%",
  69. containLabel: true,
  70. },
  71. tooltip: {
  72. trigger: "axis",
  73. },
  74. legend: [
  75. {
  76. show: true,
  77. orient: 'horizontal',
  78. icon: 'circle',
  79. itemWidth: 8,
  80. y: 'top',
  81. x: 'right',
  82. textStyle: {fontSize: '12px', color: '#415B73'},
  83. data: ['1#好氧池硝酸盐', '1#缺氧氨氮', '二沉池正磷酸盐']
  84. },
  85. {
  86. show: true,
  87. orient: 'horizontal',
  88. icon: 'circle',
  89. itemWidth: 8,
  90. y: '8%',
  91. x: 'right',
  92. textStyle: {fontSize: '12px', color: '#415B73'},
  93. data: ['2#好氧池硝酸盐', '2#缺氧氨氮',]
  94. }
  95. ],
  96. xAxis: {
  97. type: "category",
  98. data: xAxisData,
  99. axisLabel: {
  100. interval: 'auto',
  101. show: true,
  102. fontSize: '11px',
  103. color: "#0A284E",
  104. },
  105. axisLine: {
  106. show: true,
  107. lineStyle: {
  108. type: 'dashed',
  109. show: true,
  110. color: "#c1d3e6",
  111. },
  112. },
  113. axisTick: {
  114. show: false,
  115. },
  116. interval: 0, // 0 表示强制显示所有标签,'auto' 表示自动间隔
  117. // boundaryGap: true,
  118. },
  119. yAxis: {
  120. splitNumber: 4,
  121. type: "value",
  122. axisLabel: {
  123. show: true,
  124. fontSize: '12px',
  125. color: "#7395B3"
  126. },
  127. axisLine: {
  128. show: false,
  129. lineStyle: {
  130. color: "#BDD4E8",
  131. },
  132. },
  133. axisTick: {
  134. show: false,
  135. },
  136. splitLine: {
  137. lineStyle: {
  138. color: "#BDD4E8",
  139. type: "dashed",
  140. },
  141. }
  142. },
  143. series
  144. };
  145. return option;
  146. }
  147. const onChangeTab = (index) => {
  148. activeIndex.value = index;
  149. if (index == 0) {
  150. chart.setOption( getBarOptions(barOption), {notMerge: true} )
  151. } else {
  152. chart.setOption( getLineOptions(lineOption), {notMerge: true} )
  153. }
  154. setTimeout(() => chart.resize());
  155. }
  156. onMounted(() => {
  157. screenApi.getContinueDataByDays().then(({ data }) => {
  158. const seriesData = { '1#好氧池硝酸盐': [], '2#好氧池硝酸盐': [], '1#缺氧氨氮': [], '2#缺氧氨氮': [], '二沉池正磷酸盐': [] };
  159. const xAxisData = data.map(item => dayjs(item.testHour).format('MM/DD HH'));
  160. data.forEach(({ no3Hlj1Jqr, no3Hlj2Jqr, nh31Jqr, nh32Jqr, tpRccJqr }) => {
  161. seriesData['1#好氧池硝酸盐'].push(formatDecimals(no3Hlj1Jqr));
  162. seriesData['2#好氧池硝酸盐'].push(formatDecimals(no3Hlj2Jqr));
  163. seriesData['1#缺氧氨氮'].push(formatDecimals(nh31Jqr));
  164. seriesData['2#缺氧氨氮'].push(formatDecimals(nh32Jqr));
  165. seriesData['二沉池正磷酸盐'].push(formatDecimals(tpRccJqr));
  166. })
  167. lineOption = {xAxisData, seriesData};
  168. })
  169. chart = echarts.init(echartRef.value, 'light');
  170. window.addEventListener("resize", windowResize);
  171. })
  172. onUnmounted(() => {
  173. window.removeEventListener("resize", windowResize);
  174. })
  175. </script>
  176. <template>
  177. <LayoutCard title="连续检测数据">
  178. <template #headerRight>
  179. <ul>
  180. <li :class="['btn', activeIndex == 0 ? 'action' : '']" @click="onChangeTab(0)">当前</li>
  181. <li :class="['btn', activeIndex == 1 ? 'action' : '']" @click="onChangeTab(1)">近7日</li>
  182. </ul>
  183. </template>
  184. <div class="main-container">
  185. <div class="echart-card">
  186. <div class="title" v-show="activeIndex == 0">
  187. <span></span>
  188. <ul class="tabs space-x-[18px]">
  189. <li class="item space-x-[6px]">
  190. <span class="square-icon border-[#FF6737]"><i class="bg-[#FF6737]"></i></span>
  191. <span>当前值</span>
  192. </li>
  193. <li class="item space-x-[6px]">
  194. <span class="square-icon border-[#00AB84]"><i class="bg-[#00AB84]"></i></span>
  195. <span>标准值</span>
  196. </li>
  197. </ul>
  198. </div>
  199. <div class="echart-inner" ref="echartRef" ></div>
  200. <!-- :style="{ height: activeIndex === 0 ? '10rem' : '20rem' }" -->
  201. </div>
  202. </div>
  203. </LayoutCard>
  204. </template>
  205. <style lang="scss" scoped>
  206. .main-container {
  207. width: 100%;
  208. height: 236px;
  209. .echart-card {
  210. display: flex;
  211. flex-flow: column;
  212. height: 100%;
  213. color: #415B73;
  214. font-size: 12px;
  215. font-weight: bold;
  216. .title {
  217. flex-shrink: 0;
  218. display: flex;
  219. align-items: center;
  220. justify-content: space-between;
  221. padding: 0px 0 12px 0;
  222. .tabs {
  223. display: flex;
  224. .item {
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. font-size: 12px;
  229. .square-icon {
  230. display: inline-block;
  231. padding: 1px;
  232. border-width: 1px;
  233. border-style: solid;
  234. background: #fff;
  235. i {
  236. display: block;
  237. width: 8px;
  238. height: 8px;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. .echart-inner {
  245. flex: 1;
  246. }
  247. }
  248. }
  249. .btn {
  250. width: 62px;
  251. height: 28px;
  252. background: rgba(238, 249, 255, 1);
  253. border: 1px solid rgba(122, 215, 249, 1);
  254. float: left;
  255. border-radius: 0;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. cursor: pointer;
  260. color: rgba(84, 194, 248, 1);
  261. font-size: 14px;
  262. &:first-child {
  263. border-right: 0;
  264. border-top-left-radius: 4px;
  265. border-bottom-left-radius: 4px;
  266. }
  267. &:last-child {
  268. border-left: 0;
  269. border-top-right-radius: 4px;
  270. border-bottom-right-radius: 4px;
  271. }
  272. }
  273. .action, .btn:hover {
  274. background: linear-gradient(270deg, #59CCFA 0%, #3C97F7 100%);
  275. border: none;
  276. color: #fff;
  277. }
  278. </style>