history.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <!-- 虫情历史数据 -->
  3. <view>
  4. <!-- 统计图 -->
  5. <view class="ui-card history-chart">
  6. <!-- 按钮组合 -->
  7. <view class="time-btn-group">
  8. <block v-for="(time,index) in timeList" :key="index">
  9. <view class="row-center time-btn" :class="params.start_time==time.value?'active':''"
  10. @click="selectTime(time.value)"> {{time.text}}</view>
  11. </block>
  12. </view>
  13. <!-- 区域折线图 -->
  14. <area-charts :chartData="historyChartData"></area-charts>
  15. </view>
  16. <!-- 统计图end -->
  17. <!-- 历史数据列表 -->
  18. <view class="ui-card history-panel">
  19. <view class="row-between mb">
  20. <view class="">数据列表</view>
  21. </view>
  22. <!-- 历史数据表格 -->
  23. <uni-table class="table-style" :loading="loading" border emptyText="暂无更多数据">
  24. <uni-tr>
  25. <uni-th width="150" align="center">日期</uni-th>
  26. <uni-th width="150" align="center">环境温度(°C)</uni-th>
  27. <uni-th align="center">环境湿度(%)</uni-th>
  28. <uni-th width="204" align="center">加热仓温度(°C)</uni-th>
  29. </uni-tr>
  30. <uni-tr v-for="(item, index) in historyList" :key="index">
  31. <uni-td>{{ item.addtime | timeFrom}}</uni-td>
  32. <uni-td>{{ item.at }}</uni-td>
  33. <uni-td>
  34. <view class="name">{{ item.ah }}</view>
  35. </uni-td>
  36. <uni-td align="center">{{ item.hrt }}</uni-td>
  37. </uni-tr>
  38. </uni-table>
  39. <!-- 页码 -->
  40. <uni-pagination :total="total" :current="params.page" @change="getHistoryList" />
  41. <!-- 页码end -->
  42. </view>
  43. <!-- 历史数据列表end -->
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. getWormLampHistory
  49. } from '@/api/worm.js'
  50. import areaCharts from './components/w-area-charts.vue'
  51. import moment from 'moment';
  52. // 获取开始还见
  53. const startTime = (num, str) => {
  54. let time = moment().subtract(num, str);
  55. return moment(time).unix();
  56. }
  57. export default {
  58. data() {
  59. return {
  60. // 时间列表
  61. timeList: [{
  62. text: '24小时',
  63. value: startTime(1, 'days'),
  64. },
  65. {
  66. text: '近一个月',
  67. value: startTime(1, 'months'),
  68. }, {
  69. text: '近半年',
  70. value: startTime(6, 'months'),
  71. }, {
  72. text: '近一年',
  73. value: startTime(1, 'years'),
  74. }
  75. ],
  76. loading: false, // 表格加载状态
  77. params: {
  78. device_type_id: 3, // 设备类型id 3测报灯 6孢子仪
  79. device_id: '', // 设备号
  80. start_time: 0, //开始时间
  81. end_time: moment().unix(), // 结束时间
  82. page: 1,
  83. },
  84. // 历史数据列表
  85. historyList: [],
  86. total: 0,
  87. // 历史数据折线图
  88. historyChartData: {
  89. categories: [],
  90. //{name: "",data: []}
  91. series: []
  92. }
  93. };
  94. },
  95. onLoad(options) {
  96. this.params.device_id = options.imeiId;
  97. this.params.start_time = this.timeList[0].value;
  98. this.getHistoryList();
  99. },
  100. components: {
  101. areaCharts
  102. },
  103. methods: {
  104. // 选择时间范围
  105. selectTime(value) {
  106. this.params.start_time = value;
  107. this.getHistoryList();
  108. },
  109. /**
  110. * 获取历史数据列表
  111. * @param {Object} e 获取当前页数 e.current
  112. */
  113. async getHistoryList(e) {
  114. this.params.page = e?.current ?? 1;
  115. this.loading=true;
  116. const {
  117. data,
  118. counts
  119. } = await getWormLampHistory(this.params);
  120. this.loading=false;
  121. const historyList = data.map(item => item.d_h_t);
  122. this.historyList = historyList;
  123. this.total = counts;
  124. let categories = [];
  125. let series = [];
  126. let seriesKey = {
  127. at: '环境温度(°C)',
  128. ah: '环境湿度(%)',
  129. hrt: '加热仓温度(°C)'
  130. }
  131. for (let key in seriesKey) {
  132. series.push({
  133. name: seriesKey[key],
  134. data: [],
  135. key,
  136. });
  137. }
  138. this.historyList.forEach((item) => {
  139. categories.push(moment(item.addtime*1000).format('MM-月DD日'));
  140. series.forEach(serieItem=>{
  141. serieItem.data.push(item[serieItem.key]);
  142. })
  143. })
  144. this.historyChartData = {
  145. categories,
  146. series: series
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss">
  153. .history-chart {
  154. padding: 32rpx 24rpx;
  155. }
  156. .time-btn-group {
  157. display: flex;
  158. justify-content: center;
  159. margin-bottom: 24rpx;
  160. .time-btn {
  161. width: 125rpx;
  162. height: 55rpx;
  163. font-size: 24rpx;
  164. color: #999;
  165. border-radius: 8rpx;
  166. border: 1rpx solid #DDDDDD;
  167. &.active {
  168. border-color: #317afd;
  169. color: #317afd;
  170. }
  171. }
  172. }
  173. .history-panel {
  174. padding: 24rpx 26rpx;
  175. margin-bottom: 56rpx;
  176. }
  177. </style>