details.vue 5.0 KB

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