fix:修复 url 中包含的时间 优先级 应高于 锁定的时间优先级

This commit is contained in:
zhangyu
2023-07-20 16:55:13 +08:00
parent e3e0ca8055
commit ae79dc8674
3 changed files with 56 additions and 4 deletions

View File

@@ -878,7 +878,7 @@ export default {
}) })
}, },
setTimePickerRange () { setTimePickerRange () {
if (!this.timePickerRange.nowTimeType) { if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) {
this.setDefaultTimeRange() this.setDefaultTimeRange()
} }
const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType

View File

@@ -30,7 +30,7 @@
</el-select> </el-select>
<button slot="suffix" class="search-icon-btn"><i class="el-icon-search" @click="dateChange()"></i></button> <button slot="suffix" class="search-icon-btn"><i class="el-icon-search" @click="dateChange()"></i></button>
</el-input> </el-input>
<pick-time id="explore" ref="pickTime" v-model="filterTime" :refresh-data-func="getData" :sign="sign" :use-chart-unit="false" :use-refresh="false"> <pick-time id="explore" ref="pickTime" v-model="filterTime" :refresh-data-func="getData" :show-locked="true" :sign="sign" :use-chart-unit="false" :use-refresh="false">
<template slot="added-text">{{$t('overall.query')}}</template> <template slot="added-text">{{$t('overall.query')}}</template>
</pick-time> </pick-time>
</template> </template>
@@ -73,7 +73,16 @@ export default {
matchContent: '', matchContent: '',
loading: true, loading: true,
endpointLoading: false, endpointLoading: false,
limit: 100 limit: 100,
nowTimeType: {}
}
},
computed: {
timePickerLocked () {
return this.$store.getters.getTimePickerLocked
},
timePickerRange () {
return this.$store.getters.getTimePickerRange
} }
}, },
methods: { methods: {
@@ -119,8 +128,45 @@ export default {
this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker.refresh() this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker.refresh()
}, },
getData () { getData () {
const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
this.setSearchTime(nowTimeType.type, nowTimeType.value)
this.$store.dispatch('dispatchTimePickerRange', {
time: this.searchTime,
nowTimeType: this.nowTimeType
})
this.queryLogData() this.queryLogData()
}, },
setTimePickerRange () {
if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) {
return
}
const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType
this.filterTime = this.timePickerRange.time
this.$refs.pickTime.$refs.timePicker.setTimeRange(this.nowTimeType, this.filterTime)
this.setSearchTime(nowTimeType.type, nowTimeType.value, nowTimeType)
},
setSearchTime (type, val) { // 设置searchTime
if (type === 'minute') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setMinutes(new Date(bus.computeTimezone(new Date().getTime())).getMinutes() - val))
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
this.$set(this.filterTime, 0, startTime)
this.$set(this.filterTime, 1, endTime)
this.$set(this.filterTime, 2, val + 'm')
} else if (type === 'hour') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setHours(new Date(bus.computeTimezone(new Date().getTime())).getHours() - val))
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
this.$set(this.filterTime, 0, startTime)
this.$set(this.filterTime, 1, endTime)
this.$set(this.filterTime, 2, val + 'h')
} else if (type === 'date') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setDate(new Date(bus.computeTimezone(new Date().getTime())).getDate() - val))
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
this.$set(this.filterTime, 0, startTime)
this.$set(this.filterTime, 1, endTime)
this.$set(this.filterTime, 2, val + 'd')
}
this.$refs.pickTime.$refs.timePicker.searchTime = this.filterTime
},
queryLogData (limit) { // log的chart和table是一个请求 queryLogData (limit) { // log的chart和table是一个请求
this.loading = true this.loading = true
if (limit) { if (limit) {
@@ -162,6 +208,7 @@ export default {
} else if (this.from === fromRoute.asset) { } else if (this.from === fromRoute.asset) {
this.expressions = [`{asset="${this.obj.name}"}`] this.expressions = [`{asset="${this.obj.name}"}`]
} }
this.setTimePickerRange()
this.$nextTick(() => { this.$nextTick(() => {
this.queryLogData() this.queryLogData()
}) })

View File

@@ -1171,7 +1171,8 @@ export default {
}) })
}, },
setTimePickerRange () { setTimePickerRange () {
if (!this.timePickerRange.nowTimeType) { if (this.$route.query.searchTime) return
if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) {
this.setDefaultTimeRange() this.setDefaultTimeRange()
} }
const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType
@@ -1202,6 +1203,10 @@ export default {
mode: { target: this, propertyName: 'mode', type: 'string' } mode: { target: this, propertyName: 'mode', type: 'string' }
} }
this.initQueryFromPath(searchKeys) this.initQueryFromPath(searchKeys)
this.$store.dispatch('dispatchTimePickerRange', {
time: this.searchTime,
nowTimeType: this.nowTimeType
})
this.showPanel.id = this.dashboardId this.showPanel.id = this.dashboardId
this.filter.dashboardId = this.dashboardId this.filter.dashboardId = this.dashboardId
// 设置查看模式 // 设置查看模式