NowData.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div
  3. class="NowData"
  4. :class="[
  5. screenType === 'hor'
  6. ? 'horizontalClass'
  7. : 'verticalClass verticalNowData',
  8. ]"
  9. >
  10. <div class="head-title">
  11. <span>实时数据</span>
  12. <div class="normal-explain">
  13. <span class="title-right-icon"></span>
  14. <span>正常范围</span>
  15. </div>
  16. </div>
  17. <div class="subhead-title">主动式空调,会呼吸的写字楼</div>
  18. <div class="contain">
  19. <div class="item" v-for="(item, index) in realDataArr" :key="index">
  20. <div class="item_content">
  21. <img
  22. :class="[screenType === 'hor' ? '' : 'vert']"
  23. :src="item.img"
  24. alt=""
  25. />
  26. <div class="content_value">
  27. <span>{{ item.value }}</span
  28. ><span>{{ item.unit }}</span>
  29. </div>
  30. <div class="content_name">
  31. <span>{{ item.name }}</span>
  32. </div>
  33. <div
  34. class="content_level"
  35. :style="{
  36. backgroundColor: selectColor(item.value, item.id),
  37. }"
  38. :class="item.level"
  39. ></div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import icon_temp from "@/assets/icon_temp.png";
  47. import icon_humidity from "@/assets/icon_humidity.png";
  48. import icon_CO2 from "@/assets/icon_CO2.png";
  49. import icon_formaldehyde from "@/assets/icon_formaldehyde.png";
  50. import icon_PM2d5 from "@/assets/icon_PM2d5.png";
  51. import { selectColor } from "@/utils/publicMethod";
  52. import { mapState, mapActions } from "vuex";
  53. export default {
  54. props: {
  55. screenType: {
  56. type: String,
  57. default: () => {
  58. return "hor";
  59. }, //hor 横屏 vert 竖屏
  60. },
  61. },
  62. data() {
  63. return {};
  64. },
  65. watch: {
  66. // "$store.state.realTimeData"(newv, oldv) {
  67. // //debugger;
  68. // this.realData.forEach(function(item) {
  69. // item.value = newv[item.id];
  70. // });
  71. // },
  72. realDataArr(newv, oldv) {
  73. // debugger;
  74. },
  75. },
  76. mounted() {
  77. // setTimeout(() => {
  78. this.getRealTimeData(); //实时数据
  79. // }, 20000);
  80. },
  81. computed: {
  82. ...mapState({
  83. realDataArr(state) {
  84. //debugger;
  85. var realTimeData = state.realTimeData;
  86. var realInit = [
  87. {
  88. id: "temp",
  89. code: "Tdb",
  90. name: "温度",
  91. img: icon_temp,
  92. //value: 24.5,
  93. unit: "℃",
  94. level: "low",
  95. },
  96. {
  97. id: "humidity",
  98. name: "湿度",
  99. code: "RH",
  100. img: icon_humidity,
  101. // value: 33,
  102. unit: "%",
  103. level: "middle",
  104. },
  105. {
  106. id: "co2",
  107. name: "CO2",
  108. code: "CO2",
  109. img: icon_CO2,
  110. // value: 2399,
  111. unit: "ppm",
  112. level: "low",
  113. },
  114. {
  115. id: "methanal",
  116. code: "HCHO",
  117. name: "甲醛",
  118. img: icon_formaldehyde,
  119. // value: 0.12,
  120. unit: "mg/m³",
  121. level: "low",
  122. },
  123. {
  124. id: "pm25",
  125. code: "PM2d5",
  126. name: "PM2.5",
  127. img: icon_PM2d5,
  128. // value: 100,
  129. unit: "ug/m³",
  130. level: "low",
  131. },
  132. ];
  133. realInit.forEach((item) => {
  134. var filterRes = realTimeData.filter((ele) => {
  135. return ele.code == item.code;
  136. });
  137. var value = (filterRes[0] || {}).data;
  138. item.value = value ? Number(value.toFixed(1)) : value;
  139. });
  140. return realInit;
  141. },
  142. }),
  143. },
  144. methods: {
  145. ...mapActions(["getRealTimeData"]),
  146. selectColor: selectColor,
  147. },
  148. };
  149. </script>
  150. <style lang="less" scoped>
  151. .NowData {
  152. &.horizontalClass {
  153. //width: 1508px;
  154. height: 498px;
  155. }
  156. .head-title {
  157. justify-content: space-between;
  158. }
  159. .title-right-icon {
  160. display: inline-block;
  161. padding: 0;
  162. width: 12px;
  163. height: 12px;
  164. margin-right: 8px;
  165. border-radius: 50%;
  166. background: rgba(126, 216, 116, 1);
  167. }
  168. .contain {
  169. display: flex;
  170. padding-top: 47px;
  171. }
  172. .item {
  173. width: calc(100% / 5);
  174. .item_content {
  175. // height: 100%;
  176. display: flex;
  177. flex-direction: column;
  178. justify-content: center;
  179. align-items: center;
  180. text-align: center;
  181. img {
  182. width: 150px;
  183. height: 150px;
  184. &.vert {
  185. width: 130px;
  186. height: 130px;
  187. }
  188. }
  189. .content_value {
  190. font-family: Persagy;
  191. font-size: 42px;
  192. font-weight: 700;
  193. margin-top: 10px;
  194. color: rgba(59, 53, 88, 1);
  195. }
  196. .content_name {
  197. margin-top: 8px;
  198. font-family: PingFang SC;
  199. font-size: 24px;
  200. font-weight: 400;
  201. line-height: 34px;
  202. }
  203. }
  204. }
  205. .content_level {
  206. margin-top: 8px;
  207. margin-right: 8px;
  208. box-sizing: border-box;
  209. width: 16px;
  210. height: 16px;
  211. border-radius: 50%;
  212. background: rgba(126, 216, 116, 1);
  213. &.middle {
  214. background: rgba(239, 214, 46, 1);
  215. }
  216. }
  217. .normal-explain {
  218. display: flex;
  219. align-items: center;
  220. font-size: 14px;
  221. }
  222. &.verticalNowData {
  223. height: 460px;
  224. .item {
  225. .item_content {
  226. .content_value {
  227. font-size: 32px;
  228. }
  229. .content_name {
  230. margin-top: 12px;
  231. font-size: 20px;
  232. }
  233. .content_level {
  234. margin-top: 12px;
  235. }
  236. }
  237. }
  238. }
  239. }
  240. </style>