2020-04-24 12:21:22 +08:00
|
|
|
|
<template>
|
2021-04-12 13:00:59 +08:00
|
|
|
|
<div class="interval-refresh">
|
|
|
|
|
|
<time-picker v-if="showTimePicker" ref="timePicker" v-model="searchTime" :default-pick="defaultPick" :show-empty="showEmpty" class="time-picker margin-r-10" size="small" @change="dateChange"></time-picker>
|
2021-08-02 19:51:53 +08:00
|
|
|
|
<multipleTime v-if="showMultiple" ref="multipleTime" :stepSearchTime="searchTime" class="multiple-time margin-r-10" @change="dateChange(searchTime)"/>
|
|
|
|
|
|
<chart-unit v-if="useChartUnit" v-model="unit" class="margin-r-10"></chart-unit>
|
|
|
|
|
|
<div v-show="useRefresh" class="top-tool-btn-group">
|
2021-11-12 17:14:23 +08:00
|
|
|
|
<button :id="id+'-refresh'" class="top-tool-btn top-tool-btn--text" @click="antiShake">
|
2021-04-12 13:00:59 +08:00
|
|
|
|
<i class="global-active-color nz-icon nz-icon-refresh" style="font-size: 14px"></i>
|
2021-04-29 22:24:38 +08:00
|
|
|
|
<span><slot name="added-text"></slot></span>
|
2021-04-12 13:00:59 +08:00
|
|
|
|
</button>
|
2021-11-12 17:14:23 +08:00
|
|
|
|
<button id="browser-go" class="top-tool-btn top-tool-btn--dropdown" @click="dropdownHandler(dropdownShow)">
|
2021-04-29 09:28:39 +08:00
|
|
|
|
<span class="select-refresh-time-label" v-if="interval !== -1">{{interLabel}}</span>
|
2021-04-12 13:00:59 +08:00
|
|
|
|
<i class="nz-icon nz-icon-arrow-down" style="font-size: 12px;"></i>
|
|
|
|
|
|
<transition name="el-zoom-in-top">
|
|
|
|
|
|
<ul v-show="dropdownShow" class="el-dropdown-menu el-popper el-dropdown-menu--mini nz-dropdown">
|
|
|
|
|
|
<li v-for="i in $CONSTANTS.intervalList" :key="i.value + i.label" :style="{color:interval === i.value || interval.value === i.value ? theme.themeColor : ''}" class="el-dropdown-menu__item dropdown-content" @click="selectInterval(i)">
|
2021-11-04 18:21:20 +08:00
|
|
|
|
{{$t(i.label)}}
|
2020-04-24 19:57:04 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
2021-04-12 13:00:59 +08:00
|
|
|
|
</transition>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</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 {
|
2021-06-17 11:24:38 +08:00
|
|
|
|
name: 'pickTime',
|
2021-03-19 18:52:19 +08:00
|
|
|
|
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 },
|
2021-11-12 17:14:23 +08:00
|
|
|
|
id: String
|
2021-03-19 18:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
searchTime: [],
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
intervalTimer: null,
|
|
|
|
|
|
interval: -1,
|
2021-04-12 13:00:59 +08:00
|
|
|
|
unit: 2,
|
2021-04-25 16:28:09 +08:00
|
|
|
|
dropdownShow: false,
|
2021-11-01 17:23:01 +08:00
|
|
|
|
interLabel: '',
|
|
|
|
|
|
theme: {
|
|
|
|
|
|
themeColor: ''
|
2021-11-01 18:42:46 +08:00
|
|
|
|
},
|
2021-12-31 10:10:39 +08:00
|
|
|
|
timer: '',
|
|
|
|
|
|
pickTimer: localStorage.getItem('nz-default-dateFormat') ? localStorage.getItem('nz-default-dateFormat') : 'yyyy-MM-dd hh:mm:ss',
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created () {
|
|
|
|
|
|
this.searchTime = this.timeFormate(this.timeRange)
|
|
|
|
|
|
this.$emit('change', this.searchTime)
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
selectInterval (val) {
|
|
|
|
|
|
this.visible = false
|
2021-11-08 09:32:25 +08:00
|
|
|
|
clearInterval(this.intervalTimer)
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.interval = val.value
|
2021-04-29 09:28:39 +08:00
|
|
|
|
this.interLabel = val.label
|
2021-03-19 18:52:19 +08:00
|
|
|
|
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)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-04-12 13:00:59 +08:00
|
|
|
|
dropdownHandler (show) {
|
2021-10-25 17:16:40 +08:00
|
|
|
|
if (!show) {
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.dropdownShow = true
|
|
|
|
|
|
} else {
|
2021-10-25 17:16:40 +08:00
|
|
|
|
this.dropdownShow = false
|
2021-04-12 13:00:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
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 []
|
|
|
|
|
|
}
|
2021-12-31 10:10:39 +08:00
|
|
|
|
const startTime = bus.timeFormate(timeRange[0], this.pickTimer)
|
|
|
|
|
|
const endTime = bus.timeFormate(timeRange[1], this.pickTimer)
|
2021-03-19 18:52:19 +08:00
|
|
|
|
return [startTime, endTime]
|
|
|
|
|
|
},
|
|
|
|
|
|
dateChange (time) {
|
|
|
|
|
|
this.searchTime = time
|
2021-11-27 13:08:05 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.$emit('change', this.searchTime)
|
|
|
|
|
|
this.refreshDataFunc()
|
|
|
|
|
|
}, 100)
|
2021-10-22 10:32:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
antiShake () {
|
|
|
|
|
|
if (this.timer) {
|
|
|
|
|
|
clearTimeout(this.timer)
|
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
|
this.refreshDataFunc()
|
|
|
|
|
|
this.timer = ''
|
|
|
|
|
|
}, 200)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
|
this.refreshDataFunc()
|
|
|
|
|
|
this.timer = ''
|
|
|
|
|
|
}, 200)
|
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
unit: {
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
2021-11-01 17:23:01 +08:00
|
|
|
|
<style>
|
2021-04-12 13:00:59 +08:00
|
|
|
|
.interval-refresh {
|
2020-04-24 12:21:22 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
}
|
2021-08-05 22:25:55 +08:00
|
|
|
|
.select-refresh-time-label{
|
|
|
|
|
|
margin-left: 5px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.time-picker {
|
|
|
|
|
|
padding-left: 8px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
}
|
2020-04-24 12:21:22 +08:00
|
|
|
|
</style>
|