detail.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <!-- 历史记录 -->
  3. <view v-if="loading">
  4. <!-- 统计图end -->
  5. <!-- 历史数据列表 -->
  6. <view class="ui-card history-panel">
  7. <!-- 选择时间范围 -->
  8. <view class="mb">
  9. <uni-datetime-picker v-model="searchTime" type="daterange" rangeSeparator="-"
  10. @change="changeSearchTime" />
  11. </view>
  12. <!-- 历史数据表格 -->
  13. <uni-table class="table-style" ref="table" :loading="pageLoading" emptyText="暂无更多数据">
  14. <uni-tr>
  15. <block v-for="(header,index) in historyHeader" :key="index">
  16. <uni-th :width="index==0?120:80" align="center">{{header.text}}</uni-th>
  17. </block>
  18. </uni-tr>
  19. <uni-tr v-for="(item, index) in historyList" :key="index">
  20. <block v-for="(header) in historyHeader" :key="header.key">
  21. <uni-td align="center" v-if="header.key == 'wind_o'">{{fengObj[item[header.key]]}}</uni-td>
  22. <uni-td align="center" v-else-if="header.key == 'updateTime'">{{new Date(item.updateTime).getTime()/1000 | timeFrom}}</uni-td>
  23. <uni-td align="center" v-else>{{item[header.key]}}</uni-td>
  24. </block>
  25. </uni-tr>
  26. </uni-table>
  27. <!-- 页码 -->
  28. <uni-pagination :current="params.page" :total="total" title="标题文字" @change="changePagination" />
  29. <!-- 页码end -->
  30. </view>
  31. <!-- 历史数据列表end -->
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. getDetail
  37. } from '@/api/weatherother.js'
  38. import {
  39. timeFormat,
  40. timeFrame,
  41. timeFrameText
  42. } from '@/utils/utils.js'
  43. export default {
  44. data() {
  45. return {
  46. loading: false, // 页面加载状态
  47. pageLoading: false, //分页加载状态
  48. deviceId: '', // 设备id
  49. // 历史记录搜索参数
  50. params: {
  51. start_time: timeFormat(timeFrame('start')), // 开始时间
  52. end_time: timeFormat(timeFrame('end')), // 结束时间
  53. device_id: '', //设备号
  54. page: 1,
  55. page_size: 10,
  56. },
  57. searchTime: [timeFormat(timeFrameText('start')), timeFormat(timeFrameText('end'))],
  58. fengObj:{
  59. "N": "北",
  60. "NE": "东北",
  61. "E": "东",
  62. "SE": "东南",
  63. "S": "南",
  64. "SW": "西南",
  65. "W": "西",
  66. "NW": "西北",
  67. "C": "静风"
  68. },
  69. historyHeader: [{
  70. text: '更新时间',
  71. key:'updateTime'
  72. },
  73. {
  74. text: '设备ID',
  75. key:'devid'
  76. },
  77. {
  78. text: '空气温度',
  79. key:'air_t'
  80. },
  81. {
  82. text: '空气湿度',
  83. key:'air_rh'
  84. },
  85. {
  86. text: '土壤温度',
  87. key:'earth_t'
  88. },
  89. {
  90. text: '土壤湿度',
  91. key:'earth_rh'
  92. },
  93. {
  94. text: '风向',
  95. key:'wind_o'
  96. },
  97. {
  98. text: '风速',
  99. key:'wind_speed'
  100. },
  101. {
  102. text: '降雨量',
  103. key:'rainfull'
  104. },
  105. {
  106. text: '蒸发量',
  107. key:'vasp'
  108. },
  109. {
  110. text: '光照强度',
  111. key:'sunlight'
  112. },
  113. {
  114. text: '大气压强',
  115. key:'pressure'
  116. },
  117. {
  118. text: '土壤EC值',
  119. key:'ec'
  120. },
  121. {
  122. text: '露点温度',
  123. key:'ludian'
  124. }
  125. ], // 头部列表
  126. historyList: [], // 历史数据
  127. total: 0, // 数据总数
  128. };
  129. },
  130. components: {},
  131. async onLoad(options) {
  132. this.deviceId = options.id;
  133. this.params.device_id = options.id;
  134. this.$api.loading('加载中...');
  135. await Promise.all([
  136. this.getHistoryList(),
  137. ])
  138. this.loading = true;
  139. this.$api.hide();
  140. },
  141. methods: {
  142. // 选择时间
  143. changeSearchTime(time) {
  144. this.params.start_time = time[0] ? dateToUnix(time[0]) : timeFrame('start');
  145. this.params.end_time = time[0] ? dateToUnix(time[1]) : timeFrame('end');
  146. this.searchTime = time;
  147. this.params.page = 1;
  148. this.getHistoryList();
  149. this.getWeatherChart();
  150. },
  151. // 切换页码
  152. changePagination(e) {
  153. this.params.page = e.current;
  154. this.getHistoryList();
  155. },
  156. // 获取历史数据
  157. async getHistoryList() {
  158. this.pageLoading = true;
  159. const res = await getDetail(this.params);
  160. this.historyList = res.data; // 历史数据
  161. this.total = res.num;
  162. this.pageLoading = false;
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .history-chart {
  169. padding: 32rpx 24rpx;
  170. }
  171. .history-panel {
  172. padding: 24rpx 26rpx;
  173. margin-bottom: 100rpx;
  174. }
  175. </style>