history.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <!-- 历史记录 -->
  3. <view v-if="loading">
  4. <!-- 统计图 -->
  5. <view class="ui-card history-chart">
  6. <view class="row-end">
  7. <ui-picker :value="pickesId" :list="pickerList" @onChagne="changeChartData"></ui-picker>
  8. </view>
  9. <line-charts :chartData="chartShowData"></line-charts>
  10. </view>
  11. <!-- 统计图end -->
  12. <!-- 历史数据列表 -->
  13. <view class="ui-card history-panel">
  14. <!-- 选择时间范围 -->
  15. <view class="mb">
  16. <uni-datetime-picker v-model="searchTime" type="daterange" rangeSeparator="-"
  17. @change="changeSearchTime" />
  18. </view>
  19. <!-- 历史数据表格 -->
  20. <uni-table class="table-style" ref="table" :loading="pageLoading" emptyText="暂无更多数据">
  21. <uni-tr>
  22. <block v-for="(header,index) in historyHeader" :key="index">
  23. <uni-th align="center">{{header.text}}</uni-th>
  24. </block>
  25. </uni-tr>
  26. <uni-tr v-for="(item, index) in historyList" :key="index">
  27. <block v-for="(val,key,i) in item" :key="i">
  28. <uni-td align="center">{{item[key]}}</uni-td>
  29. </block>
  30. </uni-tr>
  31. </uni-table>
  32. <!-- 页码 -->
  33. <uni-pagination :total="total" title="标题文字" @change="changePagination" />
  34. <!-- 页码end -->
  35. </view>
  36. <!-- 历史数据列表end -->
  37. </view>
  38. </template>
  39. <script>
  40. import lineCharts from './components/w-line-charts.vue' // 折线图
  41. import {
  42. getWeatherHistory,
  43. getWeatherChart
  44. } from '@/api/weather.js'
  45. import {
  46. timeFrame,
  47. dateToUnix
  48. } from '@/utils/utils.js'
  49. export default {
  50. data() {
  51. return {
  52. loading: false, // 页面加载状态
  53. pageLoading: false, //分页加载状态
  54. deviceId: '', // 设备id
  55. // 统计图展示
  56. chartShowData: {
  57. categories: [],
  58. series: [],
  59. },
  60. pickesId: '', //当前下拉框的值(通道号)
  61. pickerList: [], //下拉列表
  62. // 统计图储存数据 格式 {通道号:数据列表}
  63. chartData: null,
  64. // 历史记录搜索参数
  65. params: {
  66. start_time: timeFrame('start'), // 开始时间
  67. end_time: timeFrame('end'), // 结束时间
  68. device_id: '', //设备号
  69. page: 1,
  70. page_size: 10,
  71. },
  72. searchTime: ['', ''],
  73. historyHeader: [], // 头部列表
  74. historyList: [], // 历史数据
  75. total: 0, // 数据总数
  76. };
  77. },
  78. components: {
  79. lineCharts
  80. },
  81. async onLoad(options) {
  82. this.deviceId = options.id;
  83. this.params.device_id = options.id;
  84. this.$api.loading('加载中...');
  85. await Promise.all([
  86. this.getHistoryList(),
  87. this.getWeatherChart()
  88. ])
  89. this.loading = true;
  90. this.$api.hide();
  91. },
  92. methods: {
  93. // 选择时间
  94. changeSearchTime(time) {
  95. this.params.start_time = time[0] ? dateToUnix(time[0]) : timeFrame('start');
  96. this.params.end_time = time[0] ? dateToUnix(time[1]) : timeFrame('end');
  97. this.searchTime = time;
  98. this.params.page = 1;
  99. this.getHistoryList();
  100. this.getWeatherChart();
  101. },
  102. // 切换统计图数据
  103. changeChartData(e) {
  104. this.pickesId = e.value;
  105. this.chartShowData.series = [{
  106. name: e.text,
  107. data: this.chartData[e.value] ?? []
  108. }]
  109. },
  110. // 切换页码
  111. changePagination(e) {
  112. this.params.page = e.current;
  113. this.getHistoryList();
  114. },
  115. // 获取历史数据
  116. async getHistoryList() {
  117. this.pageLoading = true;
  118. const res = await getWeatherHistory(this.params);
  119. this.historyHeader = res.headers; // 头部列表
  120. this.historyList = res.list; // 历史数据
  121. this.total = res.nums;
  122. this.pageLoading = false;
  123. },
  124. // 获取气象统计数据
  125. async getWeatherChart() {
  126. const {
  127. times,
  128. pickes,
  129. charts
  130. } = await getWeatherChart({
  131. device_id: this.params.device_id,
  132. begin: this.params.start_time,
  133. end: this.params.end_time
  134. });
  135. this.chartData = charts; // 统计数据集合
  136. this.pickerList = pickes; // 下拉列表集合
  137. this.pickesId = pickes[0]?.value ?? ''; // 当前通道号
  138. // 统计图显示数据
  139. this.chartShowData = {
  140. categories: times,
  141. series: [{
  142. name: pickes[0]?.text ?? '',
  143. data: charts[this.pickesId] ?? []
  144. }]
  145. }
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. .history-chart {
  152. padding: 32rpx 24rpx;
  153. }
  154. .history-panel {
  155. padding: 24rpx 26rpx;
  156. margin-bottom: 100rpx;
  157. }
  158. </style>