2020-04-24 12:21:22 +08:00
|
|
|
|
<template>
|
2020-04-24 19:57:04 +08:00
|
|
|
|
<div class="interval-refresh ">
|
2020-10-20 17:03:15 +08:00
|
|
|
|
<time-picker v-if="showTimePicker" ref="timePicker" class="time-picker" @change="dateChange" :default-pick="defaultPick" :show-empty="showEmpty" v-model="this.searchTime"></time-picker>
|
2021-03-31 10:02:12 +08:00
|
|
|
|
<multipleTime ref="multipleTime" v-if="showMultiple" :stepSearchTime="searchTime" @change="dateChange(searchTime)" class="multiple-time"/>
|
2021-03-31 15:26:01 +08:00
|
|
|
|
<chart-unit v-model="unit" v-if="useChartUnit"></chart-unit>
|
2021-03-10 10:27:59 +08:00
|
|
|
|
<div class="nz-btn-group nz-btn-group-size-normal nz-btn-group-light margin-r-20" style="height: 28px;line-height: 28px;vertical-align: middle;" v-show="useRefresh">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<button style="border-right: 1px solid rgba(162,162,162,0.50);" type="button" class="nz-btn nz-btn-size-normal nz-btn-style-light" @click="refreshDataFunc" :id="id+'-refresh'">
|
2020-10-15 15:34:00 +08:00
|
|
|
|
<i style="font-size: 14px" class="global-active-color nz-icon nz-icon-refresh"></i>
|
2020-04-24 19:57:04 +08:00
|
|
|
|
<span class="nz-btn nz-btn-text" ><slot name="added-text"></slot></span>
|
2020-04-24 12:21:22 +08:00
|
|
|
|
</button>
|
2020-04-24 19:57:04 +08:00
|
|
|
|
<el-popover v-model="visible" placement="bottom-start" :width="50" trigger="click" popper-class="interval-refresh-popover" >
|
|
|
|
|
|
<ul class="popover_ul">
|
2020-07-31 20:57:04 +08:00
|
|
|
|
<li v-for="i in $CONSTANTS.intervalList" :style="{color:interval == i.value ? '#31749C' : ''}" :key="i.value + i.label" @click="selectInterval(i)">
|
|
|
|
|
|
{{i.label}}
|
2020-04-24 19:57:04 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
2020-12-21 17:55:40 +08:00
|
|
|
|
<button type="button" style="border-radius: 0 4px 4px 0;padding:0px;" class="nz-btn nz-btn-size-normal nz-btn-style-light" slot="reference">
|
2021-03-05 20:34:58 +08:00
|
|
|
|
<span class="nz-btn nz-btn-text" style="padding-left: 10px;" v-if="interval.value && interval.value != -1">{{interval.label}}</span><i class="nz-icon nz-icon-arrow-down" style="font-size: 14px"></i>
|
2020-04-24 19:57:04 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</el-popover>
|
|
|
|
|
|
</div>
|
2020-04-24 12:21:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-19 18:52:19 +08:00
|
|
|
|
import bus from '../../libs/bus'
|
|
|
|
|
|
import timePicker from './timePicker'
|
2021-03-31 10:02:12 +08:00
|
|
|
|
import multipleTime from './multipleTime'
|
2021-03-19 18:52:19 +08:00
|
|
|
|
import chartUnit from './chartUnit'
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'intervalRefresh',
|
|
|
|
|
|
components: {
|
|
|
|
|
|
'time-picker': timePicker,
|
2021-03-31 10:02:12 +08:00
|
|
|
|
'chart-unit': chartUnit,
|
|
|
|
|
|
multipleTime
|
2021-03-19 18:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
model: {
|
|
|
|
|
|
event: 'change',
|
|
|
|
|
|
prop: 'timeRange'
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
refreshDataFunc: {
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
type: Function
|
2020-04-24 19:57:04 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
timeRange: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
required: true
|
2020-04-24 12:21:22 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
useRefresh: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
2020-04-24 12:21:22 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
useChartUnit: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
2020-04-24 12:21:22 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
showTimePicker: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
2020-04-24 12:21:22 +08:00
|
|
|
|
},
|
2021-03-31 10:02:12 +08:00
|
|
|
|
showMultiple: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false
|
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
defaultPick: Number,
|
|
|
|
|
|
showEmpty: { type: Boolean, default: false },
|
|
|
|
|
|
id: String
|
|
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
searchTime: [],
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
intervalTimer: null,
|
|
|
|
|
|
interval: -1,
|
|
|
|
|
|
unit: 2
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created () {
|
|
|
|
|
|
this.searchTime = this.timeFormate(this.timeRange)
|
|
|
|
|
|
this.$emit('change', this.searchTime)
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
selectInterval (val) {
|
|
|
|
|
|
this.visible = false
|
|
|
|
|
|
clearInterval(this.intervalTimer)
|
|
|
|
|
|
this.interval = val
|
|
|
|
|
|
if (!this.showTimePicker && val && val.value != -1) {
|
|
|
|
|
|
this.intervalTimer = setInterval(() => {
|
|
|
|
|
|
this.$emit('change', this.searchTime)
|
|
|
|
|
|
this.refreshDataFunc()
|
|
|
|
|
|
}, val.value * 1000)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if (val && val.value != -1) {
|
|
|
|
|
|
const start = new Date(this.searchTime[1])
|
|
|
|
|
|
const now = bus.getOffsetTimezoneData()
|
|
|
|
|
|
const interval = Math.floor((now - start.getTime()) / 1000) // 计算当前结束时间到现在的间隔(秒)
|
|
|
|
|
|
if (interval >= 60) { // 如果结束时间到现在超过30s,则
|
|
|
|
|
|
this.getIntervalData(interval)
|
2020-04-24 12:21:22 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.intervalTimer = setInterval(() => {
|
|
|
|
|
|
this.getIntervalData(this.interval.value)
|
|
|
|
|
|
}, val.value * 1000)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
getIntervalData (interval) { // interval:结束时间到现在的秒数
|
2021-03-29 17:57:11 +08:00
|
|
|
|
// const start = new Date(this.searchTime[0])
|
|
|
|
|
|
// const end = new Date(this.searchTime[1])
|
|
|
|
|
|
// start.setSeconds(start.getSeconds() + interval)
|
|
|
|
|
|
// end.setSeconds(end.getSeconds() + interval)
|
|
|
|
|
|
//
|
|
|
|
|
|
// this.searchTime = this.timeFormate([start, end])
|
|
|
|
|
|
// this.$refs.timePicker.setCostomTime(this.searchTime)
|
|
|
|
|
|
// this.$emit('change', this.searchTime)
|
2021-03-19 18:52:19 +08:00
|
|
|
|
// 刷新数据
|
|
|
|
|
|
this.refreshDataFunc()
|
2020-04-28 19:23:48 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
timeFormate (timeRange) {
|
|
|
|
|
|
if (timeRange && timeRange.length < 2) {
|
|
|
|
|
|
return []
|
|
|
|
|
|
}
|
|
|
|
|
|
const startTime = bus.timeFormate(timeRange[0], 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
|
const endTime = bus.timeFormate(timeRange[1], 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
|
return [startTime, endTime]
|
|
|
|
|
|
},
|
|
|
|
|
|
dateChange (time) {
|
|
|
|
|
|
this.searchTime = time
|
|
|
|
|
|
this.$emit('change', this.searchTime)
|
|
|
|
|
|
this.refreshDataFunc()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
unit: {
|
|
|
|
|
|
immediate: true,
|
|
|
|
|
|
handler (n, o) {
|
|
|
|
|
|
this.$emit('unitChange', n)
|
2020-04-28 19:23:48 +08:00
|
|
|
|
}
|
2020-04-24 12:21:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
2020-04-24 12:21:22 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.interval-refresh{
|
|
|
|
|
|
display: flex;
|
2020-04-24 19:57:04 +08:00
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.interval-refresh .time-picker{
|
|
|
|
|
|
margin-right: 20px;
|
2020-04-24 12:21:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
.popover_ul{
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.popover_ul li {
|
|
|
|
|
|
padding: 10px 3px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
.popover_ul li:hover {
|
|
|
|
|
|
background: $dropdown-hover-background-color !important;
|
|
|
|
|
|
color: $global-text-color-active !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
|
|
<style>
|
|
|
|
|
|
.interval-refresh-popover{
|
|
|
|
|
|
min-width: unset !important;
|
2020-12-21 15:09:38 +08:00
|
|
|
|
z-index:3000 !important;
|
2020-04-24 12:21:22 +08:00
|
|
|
|
}
|
2020-12-16 16:27:06 +08:00
|
|
|
|
.sub-top-tools .interval-refresh {
|
|
|
|
|
|
margin-top: -1px;
|
|
|
|
|
|
}
|
2021-03-31 10:02:12 +08:00
|
|
|
|
.multiple-time{
|
2021-03-31 13:59:15 +08:00
|
|
|
|
margin-right: 20px;
|
2021-03-31 10:02:12 +08:00
|
|
|
|
}
|
2020-04-24 12:21:22 +08:00
|
|
|
|
</style>
|