detail.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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" :clear-icon="false"/>
  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).toFixed(0) | 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. dateToUnix,
  42. timeFrameText
  43. } from '@/utils/utils.js'
  44. export default {
  45. data() {
  46. return {
  47. loading: false, // 页面加载状态
  48. pageLoading: false, //分页加载状态
  49. deviceId: '', // 设备id
  50. // 历史记录搜索参数
  51. params: {
  52. start_time: timeFormat(timeFrame('start')), // 开始时间
  53. end_time: timeFormat(timeFrame('end')), // 结束时间
  54. device_id: '', //设备号
  55. page: 1,
  56. page_size: 10,
  57. },
  58. timeVal: timeFormat(timeFrame('start')).slice(-8), // 存当前时分秒
  59. searchTime: [timeFormat(timeFrameText('start')), timeFormat(timeFrameText('end'))],
  60. fengObj:{
  61. "N": "北",
  62. "NE": "东北",
  63. "E": "东",
  64. "SE": "东南",
  65. "S": "南",
  66. "SW": "西南",
  67. "W": "西",
  68. "NW": "西北",
  69. "C": "静风"
  70. },
  71. historyHeader: [{
  72. text: '更新时间',
  73. key:'updateTime'
  74. },
  75. {
  76. text: '设备ID',
  77. key:'devid'
  78. },
  79. {
  80. text: '空气温度',
  81. key:'air_t'
  82. },
  83. {
  84. text: '空气湿度',
  85. key:'air_rh'
  86. },
  87. {
  88. text: '土壤温度',
  89. key:'earth_t'
  90. },
  91. {
  92. text: '土壤湿度',
  93. key:'earth_rh'
  94. },
  95. {
  96. text: '风向',
  97. key:'wind_o'
  98. },
  99. {
  100. text: '风速',
  101. key:'wind_speed'
  102. },
  103. {
  104. text: '降雨量',
  105. key:'rainfull'
  106. },
  107. {
  108. text: '蒸发量',
  109. key:'vasp'
  110. },
  111. {
  112. text: '光照强度',
  113. key:'sunlight'
  114. },
  115. {
  116. text: '大气压强',
  117. key:'pressure'
  118. },
  119. {
  120. text: '土壤EC值',
  121. key:'ec'
  122. },
  123. {
  124. text: '露点温度',
  125. key:'ludian'
  126. }
  127. ], // 头部列表
  128. historyList: [], // 历史数据
  129. total: 0, // 数据总数
  130. };
  131. },
  132. components: {},
  133. async onLoad(options) {
  134. this.deviceId = options.id;
  135. this.params.device_id = options.id;
  136. this.$api.loading('加载中...');
  137. await Promise.all([
  138. this.getHistoryList(),
  139. ])
  140. this.loading = true;
  141. this.$api.hide();
  142. },
  143. methods: {
  144. // 选择时间
  145. changeSearchTime(val) {
  146. if(val.length == 0) {
  147. val = [timeFormat(timeFrame('start')), timeFormat(timeFrame('end'))];
  148. this.searchTime = val
  149. }
  150. this.params.start_time = val[0] + ' ' + this.timeVal;
  151. this.params.end_time = val[1] + ' ' + this.timeVal;
  152. this.params.page = 1;
  153. this.getHistoryList();
  154. },
  155. // 切换页码
  156. changePagination(e) {
  157. this.params.page = e.current;
  158. this.getHistoryList();
  159. },
  160. // 获取历史数据
  161. async getHistoryList() {
  162. this.pageLoading = true;
  163. const res = await getDetail(this.params);
  164. this.historyList = res.data; // 历史数据
  165. this.total = res.num;
  166. this.pageLoading = false;
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss">
  172. .history-chart {
  173. padding: 32rpx 24rpx;
  174. }
  175. .history-panel {
  176. padding: 24rpx 26rpx;
  177. margin-bottom: 100rpx;
  178. }
  179. </style>