5 changed files with 118 additions and 44 deletions
@ -1,41 +1,78 @@ |
|||||
<template> |
<template> |
||||
<DataSearchBar @getDate="getDate" /> |
<SearchBar @search="getDate" /> |
||||
<RealtimeData ref="childRef" class="mt-4" /> |
<RealtimeData ref="childRef" class="mt-4" /> |
||||
</template> |
</template> |
||||
|
|
||||
<script setup> |
<script setup> |
||||
import DataSearchBar from 'components/data-search-bar.vue'; |
import { computed, ref, onUnmounted } from 'vue'; |
||||
import RealtimeData from 'components/realtime-data.vue'; |
|
||||
import { computed, ref } from 'vue'; |
|
||||
import { useStore } from 'vuex'; |
import { useStore } from 'vuex'; |
||||
|
import SearchBar from 'components/search-bar.vue'; |
||||
|
import RealtimeData from 'components/realtime-data.vue'; |
||||
|
|
||||
const childRef = ref(null); |
const childRef = ref(null); |
||||
|
|
||||
let timer = null; |
let timer = null; |
||||
|
let apiTimer = null; |
||||
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 realtimeData = computed(() => store.state.statistics.realtimeData); |
||||
|
|
||||
// 实时数据统计 |
/** |
||||
|
* 格式化日期 |
||||
|
* @param {Date} date 选择的日期 |
||||
|
*/ |
||||
|
const formatDate = date => { |
||||
|
const year = date.getFullYear(); |
||||
|
const month = date.getMonth() + 1; |
||||
|
const day = date.getDate(); |
||||
|
return `${year}-${month}-${day}`; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 实时数据统计 |
||||
|
* @param {*} deviceId // 站点 设备id |
||||
|
* @param {*} date // 年月时间段 |
||||
|
* @param {*} sort // 1 -> 按时间正序 -1->按时间倒序 |
||||
|
* @param {*} page // 第几页 |
||||
|
* @param {*} size // 每页多少条 |
||||
|
* @param {*} type // 0查全部 |
||||
|
*/ |
||||
const getDate = async options => { |
const getDate = async options => { |
||||
if (token) { |
try { |
||||
const params = { |
if (token) { |
||||
deviceId: options && options.deviceId ? options.deviceId : '', // 站点 设备id |
const startTime = new Date(new Date(new Date().toLocaleDateString()).getTime()); |
||||
date: options && options.date && options.date.length ? options.date : [], // 年月时间段 |
const start = formatDate(startTime); |
||||
sort: 1, // 1 -> 按时间正序 -1->按时间倒序 |
const end = formatDate(new Date()); |
||||
page: 1, // 第几页 |
|
||||
size: 10, // 每页多少条 |
const params = { |
||||
}; |
deviceId: options && options.deviceId ? options.deviceId : '', |
||||
await store.dispatch('statistics/getRealtimeData', params); |
date: [start, end], |
||||
timer && clearTimeout(timer); |
sort: 1, |
||||
timer = null; |
page: 1, |
||||
childRef.value.changeDate(realtimeData.value); |
size: 10, |
||||
} else { |
type: 0, |
||||
timer = setTimeout(() => { |
}; |
||||
getDate(); |
await store.dispatch('statistics/getRealtimeData', params); |
||||
}); |
timer && clearTimeout(timer); |
||||
|
timer = null; |
||||
|
childRef.value.changeDate(realtimeData.value); |
||||
|
} else { |
||||
|
timer = setTimeout(() => { |
||||
|
getDate(); |
||||
|
}); |
||||
|
} |
||||
|
} catch (error) { |
||||
|
console.log('error: ', error); |
||||
} |
} |
||||
}; |
}; |
||||
|
|
||||
getDate(); |
getDate(); |
||||
|
apiTimer = setInterval(() => { |
||||
|
getDate(); |
||||
|
}, 5000); |
||||
|
|
||||
|
onUnmounted(() => { |
||||
|
apiTimer && clearInterval(apiTimer); |
||||
|
apiTimer = null; |
||||
|
}); |
||||
</script> |
</script> |
||||
|
Loading…
Reference in new issue