details.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <!-- 设备详情:墒情检测or气象检测 -->
  3. <view>
  4. <!-- 设备卡片 -->
  5. <view class="ui-card forecast-card">
  6. <view class="flex-1">
  7. <view class="font-16 title">设备名称:{{deviceInfo.equip_name}}</view>
  8. <view class="text">设备ID:{{deviceInfo.equip_id}}</view>
  9. <view class="text text-ellipsis">地址:{{deviceInfo.address}}</view>
  10. <view class="text">最新上报时间:{{deviceInfo.uptime | timeFrom}}</view>
  11. </view>
  12. <navigator :url="`warn?type=${deviceInfo.device_type}`" class="font-12 state">预警</navigator>
  13. </view>
  14. <!-- 设备卡片end -->
  15. <view class="row-between m-12">
  16. <view class="font-16 mr">实时数据</view>
  17. <view class="flex-1 font-10 text-sub">(可点击查看24小时数据)</view>
  18. <navigator :url="`history?id=${deviceInfo.equip_id}`" class="font-14 text-primary" hover-class="none">历史数据
  19. </navigator>
  20. </view>
  21. <!-- 数据列表 -->
  22. <view class="latest-list">
  23. <block v-for="(item,index) in latestList" :key="index">
  24. <view class="ui-card latest-item" @click="openLatestChart(item.el,item.text)">
  25. <view class="icon">
  26. <image :src="`/static/icon/${item.markId}.png`"></image>
  27. </view>
  28. <view class="column-between text-info font-12">
  29. <view class="text">{{item.text}}</view>
  30. <view class="text">{{item.value}}</view>
  31. </view>
  32. </view>
  33. </block>
  34. </view>
  35. <!-- 数据列表end -->
  36. <!-- 统计图24小时数据 -->
  37. <uni-popup ref="chartsPopup" type="bottom" :mask-click="false">
  38. <view class="column charts-popup" v-if="dayData">
  39. <view class="flex-1">
  40. <view class="charts-title">
  41. 24小时数据
  42. </view>
  43. <lineCharts :chartData="chartShowData" :width="200" :height="200"></lineCharts>
  44. <view class="charts-text mt-12">
  45. 当天最大值:{{dayData.max}} {{dayData.maxtime | timeFrom}}
  46. </view>
  47. <view class="charts-text">
  48. 当天最小值:{{dayData.min}} {{dayData.mintime | timeFrom}}
  49. </view>
  50. </view>
  51. <view class="row-center charts-cancel" @click="closeChartsPopup">取消</view>
  52. </view>
  53. </uni-popup>
  54. </view>
  55. </template>
  56. <script>
  57. import {
  58. getWeatherDeviceDetail,
  59. getWeatherDayData,
  60. getWeatherChart
  61. } from '@/api/weather.js'
  62. import lineCharts from './components/w-line-charts.vue' // 折线图
  63. // 设备详情
  64. export default {
  65. data() {
  66. return {
  67. deviceInfo: {}, // 设备信息
  68. // 实时数据列表 { icon:'图标', text:'标题',value:'值'}
  69. latestList: [],
  70. dayData: null, //当天24小时数据
  71. dayDatas: [], // 24小时数据列表
  72. // 统计图24小时数据
  73. chartShowData: {
  74. categories: [],
  75. series: [],
  76. },
  77. // 统计图储存数据 格式 {通道号:数据列表}
  78. chartData: null,
  79. };
  80. },
  81. components: {
  82. lineCharts
  83. },
  84. onLoad(options) {
  85. this.deviceInfo = JSON.parse(options.params);
  86. this.getLatestList(); // 获取实时列表
  87. this.getWeatherDayData(); // 获取24小时数据
  88. this.getWeatherChart(); // 获取设备24小时折线图数据
  89. },
  90. methods: {
  91. // 获取实时数据列表
  92. async getLatestList() {
  93. this.latestList = await getWeatherDeviceDetail({
  94. device_id: this.deviceInfo.equip_id
  95. });
  96. },
  97. // 获取24小时实时数据
  98. async getWeatherDayData() {
  99. const {
  100. data
  101. } = await getWeatherDayData({
  102. device_id: this.deviceInfo.equip_id
  103. });
  104. this.dayDatas = data ?? [];
  105. },
  106. /**
  107. * 根据通道号 字段el 获取实时数据折线图信息
  108. * @param {string} el 通道号
  109. * @param {string} name 标识名称
  110. */
  111. openLatestChart(el, name) {
  112. if (!this.chartData) {
  113. return this.$api.msg('数据加载中,请稍后');
  114. }
  115. this.dayData = this.dayDatas.find(item => item.ekey == el);
  116. this.chartShowData.series = [{
  117. name: name,
  118. data: this.chartData[el] ?? []
  119. }]
  120. this.$refs['chartsPopup'].open();
  121. },
  122. // 关闭弹框
  123. closeChartsPopup() {
  124. this.dayData = null;
  125. this.$refs['chartsPopup'].close();
  126. },
  127. // 获取气象统计数据
  128. async getWeatherChart() {
  129. const {
  130. times,
  131. charts
  132. } = await getWeatherChart({
  133. device_id: this.deviceInfo.equip_id,
  134. begin: this.$util.timeFrame('start'),
  135. end: this.$util.timeFrame('end'),
  136. });
  137. this.chartData = charts; // 统计数据集合
  138. console.log(this.chartData);
  139. // 统计图显示数据
  140. this.chartShowData.categories = times;
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .charts-popup {
  147. position: relative;
  148. width: 100%;
  149. background-color: #fff;
  150. padding: 50rpx 32rpx 20rpx;
  151. border-radius: 12rpx 12rpx 0rpx 0rpx;
  152. height: 850rpx;
  153. }
  154. .charts-icon {
  155. position: absolute;
  156. right: -20rpx;
  157. top: -50rpx;
  158. }
  159. .charts-box {
  160. width: 100%;
  161. height: 450rpx;
  162. overflow: hidden;
  163. }
  164. .charts-title {
  165. font-size: $font-size-title;
  166. color: $color-title;
  167. line-height: $line-height-title;
  168. text-align: center;
  169. }
  170. .charts-text {
  171. font-size: 24rpx;
  172. color: $color-subtitle;
  173. line-height: $line-height-subtitle;
  174. }
  175. .charts-cancel{
  176. border-top: #f5f5f5 26rpx solid;
  177. margin-left: -32rpx;
  178. margin-right: -32rpx;
  179. padding: 24rpx;
  180. color:#999
  181. }
  182. </style>