history.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 :width="index==0?120:80" 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 :current="params.page" :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. timeFrameText,
  48. dateToUnix
  49. } from '@/utils/utils.js'
  50. export default {
  51. data() {
  52. return {
  53. loading: false, // 页面加载状态
  54. pageLoading: false, //分页加载状态
  55. deviceId: '', // 设备id
  56. // 统计图展示
  57. chartShowData: {
  58. categories: [],
  59. series: [],
  60. },
  61. pickesId: '', //当前下拉框的值(通道号)
  62. pickerList: [], //下拉列表
  63. // 统计图储存数据 格式 {通道号:数据列表}
  64. chartData: null,
  65. // 历史记录搜索参数
  66. params: {
  67. start_time: timeFrame('start'), // 开始时间
  68. end_time: timeFrame('end'), // 结束时间
  69. device_id: '', //设备号
  70. page: 1,
  71. page_size: 10,
  72. },
  73. searchTime: [timeFrameText('start'), timeFrameText('end')],
  74. historyHeader: [], // 头部列表
  75. historyList: [], // 历史数据
  76. total: 0, // 数据总数
  77. };
  78. },
  79. components: {
  80. lineCharts
  81. },
  82. async onLoad(options) {
  83. this.deviceId = options.id;
  84. this.params.device_id = options.id;
  85. this.$api.loading('加载中...');
  86. await Promise.all([
  87. this.getHistoryList(),
  88. this.getWeatherChart()
  89. ])
  90. this.loading = true;
  91. this.$api.hide();
  92. },
  93. methods: {
  94. // 选择时间
  95. changeSearchTime(time) {
  96. this.params.start_time = time[0] ? dateToUnix(time[0]) : timeFrame('start');
  97. this.params.end_time = time[0] ? dateToUnix(time[1]) : timeFrame('end');
  98. this.searchTime = time;
  99. this.params.page = 1;
  100. this.getHistoryList();
  101. this.getWeatherChart();
  102. },
  103. // 切换统计图数据
  104. changeChartData(e) {
  105. this.pickesId = e.value;
  106. this.chartShowData.series = [{
  107. name: e.text,
  108. data: this.chartData[e.value] ?? []
  109. }]
  110. },
  111. // 切换页码
  112. changePagination(e) {
  113. this.params.page = e.current;
  114. this.getHistoryList();
  115. },
  116. // 获取历史数据
  117. async getHistoryList() {
  118. this.pageLoading = true;
  119. const res = await getWeatherHistory(this.params);
  120. this.historyHeader = res.headers; // 头部列表
  121. this.historyList = res.list; // 历史数据
  122. this.total = res.nums;
  123. this.pageLoading = false;
  124. },
  125. // 获取气象统计数据
  126. async getWeatherChart() {
  127. const {
  128. times,
  129. pickes,
  130. charts
  131. } = await getWeatherChart({
  132. device_id: this.params.device_id,
  133. begin: this.params.start_time,
  134. end: this.params.end_time
  135. });
  136. this.chartData = charts; // 统计数据集合
  137. console.log(pickes);
  138. this.pickerList = pickes; // 下拉列表集合
  139. this.pickesId = pickes[0]?.value ?? ''; // 当前通道号
  140. // 统计图显示数据
  141. this.chartShowData = {
  142. categories: times,
  143. series: [{
  144. name: pickes[0]?.text ?? '',
  145. data: charts[this.pickesId] ?? []
  146. }]
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss">
  153. .history-chart {
  154. padding: 32rpx 24rpx;
  155. }
  156. .history-panel {
  157. padding: 24rpx 26rpx;
  158. margin-bottom: 100rpx;
  159. }
  160. </style>