Browse Source

添加历史数据统计接口

master
song 4 years ago
parent
commit
121b9968f7
  1. 16
      src/routers/index.js
  2. 43
      src/views/statistical-history.vue

16
src/routers/index.js

@ -29,21 +29,21 @@ export const routes = [
{ {
path: '/data-history', path: '/data-history',
name: 'data-history', name: 'data-history',
meta: { title: '历史数据查看', icon: 'el-icon-data-line' }, meta: { title: '历史数据查看', icon: 'el-icon-document-copy' },
component: () => import('@/views/data-history.vue'), component: () => import('@/views/data-history.vue'),
}, },
{
path: '/statistical-realtime',
name: 'statistical-realtime',
meta: { title: '实时数据统计' },
component: () => import('@/views/statistical-realtime.vue'),
},
{ {
path: '/statistical-history', path: '/statistical-history',
name: 'statistical-history', name: 'statistical-history',
meta: { title: '历史数据统计' }, meta: { title: '历史数据统计', icon: 'el-icon-data-line' },
component: () => import('@/views/statistical-history.vue'), component: () => import('@/views/statistical-history.vue'),
}, },
{
path: '/statistical-realtime',
name: 'statistical-realtime',
meta: { title: '实时数据统计', icon: 'el-icon-time' },
component: () => import('@/views/statistical-realtime.vue'),
},
{ {
path: '/months', path: '/months',
name: 'months', name: 'months',

43
src/views/statistical-history.vue

@ -1,39 +1,42 @@
<template> <template>
<DataSearchBar @getDate="getDate" /> <SearchBar @search="getDate" />
<HistoryData ref="childRef" class="mt-4" /> <HistoryData ref="childRef" class="mt-4" />
</template> </template>
<script setup> <script setup>
import DataSearchBar from 'components/data-search-bar.vue'; import SearchBar from 'components/search-bar-data.vue';
import HistoryData from 'components/history-data.vue'; import HistoryData from 'components/history-data.vue';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { getHistories } from 'apis/index';
const childRef = ref(null); const childRef = ref(null);
let timer = null; let timer = null;
const page = ref({ page: 2, size: 10 });
const data = ref(null);
const search = ref({});
const store = useStore(); const store = useStore();
const token = computed(() => store.getters['user/token']); const token = computed(() => store.getters['user/token']);
const realtimeData = computed(() => store.state.statistics.realtimeData);
// //
const getDate = async options => { const getDate = async () => {
if (token) { try {
const params = { if (token) {
deviceId: options && options.deviceId ? options.deviceId : '', // id const params = { search: { ...search.value }, page: { page: page.value.page, size: page.value.size } };
date: options && options.date && options.date.length ? options.date : [], // const resData = await getHistories(params);
sort: 1, // 1 -> -1-> data.value = resData.data;
page: 1, // page.value = resData.page;
size: 10, // timer && clearTimeout(timer);
}; timer = null;
await store.dispatch('statistics/getRealtimeData', params); childRef.value.changeDate(data.value);
timer && clearTimeout(timer); } else {
timer = null; timer = setTimeout(() => {
childRef.value.changeDate(realtimeData.value); getDate();
} else { });
timer = setTimeout(() => { }
getDate(); } catch (error) {
}); console.log('error: ', error);
} }
}; };

Loading…
Cancel
Save