element.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="element">
  3. <view class="element-header">
  4. <view class="element-title">{{ title }}</view>
  5. <view class="element-status" v-if="!sensorList">
  6. 2024-01-25 16:05:05
  7. <u-icon name="reload" color="#14A478" style="margin-left: 20rpx" />
  8. </view>
  9. </view>
  10. <view class="element-body">
  11. <view class="element-row" v-for="(item, index) in displayList" :key="index">
  12. <image :src="item.url" class="element-col-icon" />
  13. <view class="element-col">
  14. <view class="element-col-title"
  15. >{{ item.content }}
  16. <text class="unit">{{ item.unit }}</text>
  17. </view>
  18. <view class="element-col-content">{{ item.title }}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'Element',
  27. props: {
  28. // status 接口返回的 sensor_list,为空时展示内置示例
  29. sensorList: {
  30. type: Array,
  31. default: null,
  32. },
  33. title: {
  34. type: String,
  35. default: '1号环控',
  36. },
  37. },
  38. computed: {
  39. displayList() {
  40. if (!this.sensorList || !this.sensorList.length) {
  41. return this.list;
  42. }
  43. return this.sensorList.map((item) => {
  44. // 取形如 SensorDev00:Temp 的遥测 key 对应的值
  45. const key = Object.keys(item).find((k) =>
  46. /^SensorDev\d+:\w+$/.test(k)
  47. );
  48. const val = key ? item[key] : null;
  49. return {
  50. title: item.display_name || '',
  51. unit: item.unit || '',
  52. content: val == null ? '--' : val,
  53. url: this.iconByName(item.display_name),
  54. };
  55. });
  56. },
  57. },
  58. data() {
  59. return {
  60. list: [
  61. {
  62. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_temp.png',
  63. title: '空气温度',
  64. unit: '℃',
  65. content: '12',
  66. },
  67. {
  68. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_humidity.png',
  69. title: '空气湿度',
  70. unit: '%',
  71. content: '80',
  72. },
  73. {
  74. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_soil_temp.png',
  75. title: '土壤温度',
  76. unit: '℃',
  77. content: '80',
  78. },
  79. {
  80. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_soil_humidity.png',
  81. title: '土壤湿度',
  82. unit: '%',
  83. content: '80',
  84. },
  85. {
  86. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_co2.png',
  87. title: '二氧化碳',
  88. unit: 'ppm',
  89. content: '80',
  90. },
  91. {
  92. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_sun.png',
  93. title: '光照',
  94. unit: 'LUX',
  95. content: '80',
  96. },
  97. {
  98. url: 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_ph.png',
  99. title: '土壤PH值',
  100. unit: '',
  101. content: '80',
  102. },
  103. ],
  104. };
  105. },
  106. methods: {
  107. // 按传感器名称匹配图标
  108. iconByName(name) {
  109. const n = String(name || '');
  110. if (n.includes('土壤') && n.includes('湿')) {
  111. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_soil_humidity.png';
  112. }
  113. if (n.includes('土壤')) {
  114. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_soil_temp.png';
  115. }
  116. if (n.includes('湿')) {
  117. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_humidity.png';
  118. }
  119. if (n.includes('二氧化碳')) {
  120. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_co2.png';
  121. }
  122. if (n.includes('光照') || n.includes('亮度')) {
  123. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_sun.png';
  124. }
  125. if (n.toLowerCase().includes('ph')) {
  126. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_ph.png';
  127. }
  128. return 'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/greenHouseIcon/sensor_temp.png';
  129. },
  130. },
  131. };
  132. </script>
  133. <style lang="less" scoped>
  134. .element {
  135. .element-header {
  136. display: flex;
  137. justify-content: space-between;
  138. align-items: center;
  139. margin-bottom: 20rpx;
  140. color: #042118;
  141. font-family: 'Source Han Sans CN VF';
  142. font-size: 28rpx;
  143. font-weight: 700;
  144. .element-status {
  145. color: #687a74;
  146. text-align: center;
  147. font-family: 'Source Han Sans CN VF';
  148. font-size: 28rpx;
  149. font-weight: 400;
  150. }
  151. }
  152. .element-body {
  153. display: grid;
  154. grid-template-columns: repeat(2, 1fr);
  155. grid-gap: 20rpx;
  156. padding: 20rpx;
  157. .element-row {
  158. display: flex;
  159. margin-bottom: 20rpx;
  160. .element-col-icon {
  161. width: 80rpx;
  162. height: 80rpx;
  163. margin-right: 10rpx;
  164. }
  165. .element-col {
  166. margin-left: 10rpx;
  167. .element-col-title {
  168. font-size: 28rpx;
  169. color: #042118;
  170. font-weight: 700;
  171. .unit {
  172. font-size: 24rpx;
  173. color: #999;
  174. }
  175. }
  176. .element-col-content {
  177. font-size: 24rpx;
  178. color: #666;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. </style>