fix: chart 时间回显错误

This commit is contained in:
zhangyu
2023-02-15 12:02:17 +08:00
parent adb06297ce
commit 1115992d7d
2 changed files with 30 additions and 8 deletions

View File

@@ -170,7 +170,15 @@ export default {
const now = new Date(bus.computeTimezone(new Date().getTime()))
const origin = new Date(bus.timeFormate(bus.formateTimeToTime(this.timeRange[1]), 'YYYY-MM-DD HH:mm:ss'))
const numInterval = now.getTime() - origin.getTime()
if (numInterval >= 60000) { // 大于1分钟则start、end均往后移numInterval否则时间不变
let nowTimeType = this.$route.query.nowTimeType
if (!nowTimeType) {
nowTimeType = {
value: 1
}
} else {
nowTimeType = JSON.parse(nowTimeType)
}
if (numInterval >= 6 && nowTimeType.value !== -1) { // 大于1分钟则start、end均往后移numInterval否则时间不变
startTime = bus.getNewTime(bus.formateTimeToTime(this.timeRange[0]), numInterval, 'YYYY-MM-DD HH:mm:ss')
endTime = bus.timeFormate(now, 'YYYY-MM-DD HH:mm:ss')
} else {
@@ -306,6 +314,7 @@ export default {
} else {
if (r.status === 'success') {
r.data.result.forEach(item => {
item.elements = elements[rIndex - elements.length]
this.allDataLength++
item.values.forEach(values => {
values[0] = values[0] + this.minusTime / 1000
@@ -470,7 +479,13 @@ export default {
case 'logs': {
this.chartData = []
elements.forEach((element, index) => {
this.chartData.push(this.dataJson[this.chartInfo.id + '_' + index].data.result)
const data = this.dataJson[this.chartInfo.id + '_' + index].data.result.map(item => {
return {
...item,
elements: element
}
})
this.chartData.push(data)
})
break
}

View File

@@ -106,7 +106,7 @@
<div class="date-range-title">{{$t('timepicker.relatime')}}</div>
<ul class="date-range-item">
<li
v-for="(item, key) in timeData"
v-for="(item, key) in timeShowData"
@click="timeChange(item)"
:class="showTime.id === item.id ? 'activeLi' : ''"
:key="key"
@@ -182,11 +182,11 @@ export default {
text: this.$t('dashboard.panel.lastOneHour')
},
timeData: [
// {
// id: 0,
// text: this.$t("dashboard.panel.customTimeRange"),
// value: -1,
// },
{
id: 0,
text: this.$t('dashboard.panel.customTimeRange'),
value: -1
},
{
id: 12,
text: this.$t('dashboard.panel.noDate'),
@@ -259,6 +259,7 @@ export default {
value: 30
}
],
timeShowData: [],
nowTimeType: {
id: 4,
text: this.$t('dashboard.panel.lastOneHour'),
@@ -273,6 +274,8 @@ export default {
}
},
mounted () {
this.timeShowData = JSON.parse(JSON.stringify(this.timeData))
this.timeShowData.shift()
this.getItem()
this.getUtcStr()
this.getRangeHistoryArr()
@@ -419,10 +422,14 @@ export default {
this.oldSearchTimeError[1] = false
},
setCustomTime (timeGroup, timeRange) {
console.log(timeGroup)
if (timeGroup) {
this.showTime = this.nowTimeType = this.timeData.find(
(item) => item.id == timeGroup.id
)
if (timeGroup.value == -1) {
this.isCustom = true
}
if (this.showTime) {
this.showTime = Object.assign({}, this.showTime)
this.$set(this.searchTime, 0, timeGroup.start_time)