NowData.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div
  3. class="NowData"
  4. :class="[screenType === 'hor' ? 'horiNowClass' : 'verticalNowData']"
  5. >
  6. <div class="head-title">
  7. <span>实时数据</span>
  8. <span class="subhead-title">主动式空调,会呼吸的写字楼</span>
  9. </div>
  10. <div class="contain">
  11. <div class="item" v-for="(item, index) in realDataArr" :key="index">
  12. <div
  13. class="item_content"
  14. :style="{
  15. backgroundImage:
  16. 'url(' + selectColor(item.value, item.id) + ')',
  17. }"
  18. >
  19. <div class="content_value">
  20. <span>{{ item.value }}</span
  21. ><span>{{ item.unit }}</span>
  22. </div>
  23. <div class="content_name">
  24. <span>{{ item.name }}</span>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script lang="ts">
  32. import { ref, defineComponent, reactive, toRefs, onMounted } from "vue";
  33. import { queryEnvCurrent } from "@/api/index";
  34. import { selectColor } from "@/utils/publicMethod";
  35. export default defineComponent({
  36. props: {
  37. screenType: {
  38. type: String,
  39. },
  40. },
  41. setup(props, contx) {
  42. const allData = reactive({
  43. realDataArr: [],
  44. selectColor: selectColor,
  45. });
  46. onMounted(() => {
  47. queryEnvCurrent()
  48. .then((res) => {
  49. let realTimeData = res.data.data || [];
  50. let realInit = [
  51. {
  52. id: "temp",
  53. code: "Tdb",
  54. name: "温度",
  55. //value: 24.5,
  56. unit: "℃",
  57. level: "low",
  58. fixed: 1,
  59. },
  60. {
  61. id: "humidity",
  62. name: "湿度",
  63. code: "RH",
  64. // value: 33,
  65. unit: "%",
  66. level: "middle",
  67. fixed: 0,
  68. },
  69. {
  70. id: "co2",
  71. name: "CO₂",
  72. code: "CO2",
  73. unit: "ppm",
  74. level: "low",
  75. fixed: 0,
  76. },
  77. {
  78. id: "methanal",
  79. code: "HCHO",
  80. name: "甲醛",
  81. unit: "mg/m³",
  82. level: "low",
  83. fixed: 2,
  84. },
  85. {
  86. id: "pm25",
  87. code: "PM2d5",
  88. name: "PM2.5",
  89. unit: "ug/m³",
  90. level: "low",
  91. fixed: 0,
  92. },
  93. ];
  94. realInit.forEach((item) => {
  95. var filterRes = realTimeData.filter((ele) => {
  96. return ele.code == item.code;
  97. });
  98. var value = (filterRes[0] || {}).data;
  99. item.value = value
  100. ? Number(value.toFixed(item.fixed))
  101. : value;
  102. });
  103. allData.realDataArr = realInit;
  104. })
  105. .catch((err) => {});
  106. });
  107. return { ...toRefs(allData) };
  108. },
  109. });
  110. </script>
  111. <style scoped lang="scss">
  112. .horiNowClass {
  113. height: 48%;
  114. }
  115. .NowData {
  116. .subhead-title {
  117. margin-left: 14px;
  118. }
  119. .title-right-icon {
  120. display: inline-block;
  121. padding: 0;
  122. width: 12px;
  123. height: 12px;
  124. margin-right: 8px;
  125. border-radius: 50%;
  126. background: rgba(126, 216, 116, 1);
  127. }
  128. .contain {
  129. height: calc(100% - 60px);
  130. display: flex;
  131. }
  132. .item {
  133. width: calc(100% / 5);
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. .item_content {
  138. // height: 100%;
  139. background-size: auto 240px;
  140. background-position: center -36px;
  141. background-repeat: no-repeat;
  142. padding-bottom: 30px;
  143. // display: flex;
  144. // flex-direction: column;
  145. // justify-content: center;
  146. // align-items: center;
  147. width: 100%;
  148. text-align: center;
  149. .content_value {
  150. font-family: Persagy;
  151. font-size: 52px;
  152. font-weight: 700;
  153. background: linear-gradient(180deg, #fff5df 0%, #ead0b1 100%);
  154. -webkit-background-clip: text;
  155. -webkit-text-fill-color: transparent;
  156. background-clip: text;
  157. text-fill-color: transparent;
  158. text-shadow: 0px 0px 8px rgba(255, 255, 255, 0.4);
  159. line-height: 64px;
  160. }
  161. .content_name {
  162. margin-top: 8px;
  163. font-family: PingFang SC;
  164. font-size: 32px;
  165. font-weight: 400;
  166. line-height: 46px;
  167. color: #f7e6cd;
  168. }
  169. }
  170. }
  171. .content_level {
  172. margin-top: 8px;
  173. margin-right: 8px;
  174. box-sizing: border-box;
  175. width: 16px;
  176. height: 16px;
  177. border-radius: 50%;
  178. background: rgba(126, 216, 116, 1);
  179. &.middle {
  180. background: rgba(239, 214, 46, 1);
  181. }
  182. }
  183. .normal-explain {
  184. display: flex;
  185. align-items: center;
  186. font-size: 14px;
  187. }
  188. }
  189. .verticalNowData {
  190. height: 380px;
  191. .item {
  192. .item_content {
  193. .content_value {
  194. font-size: 46px;
  195. }
  196. .content_name {
  197. margin-top: 12px;
  198. font-size: 28px;
  199. }
  200. .content_level {
  201. margin-top: 12px;
  202. }
  203. }
  204. }
  205. }
  206. </style>