From 7ebddf4905d0d534241015d107feec41a6c43d1e Mon Sep 17 00:00:00 2001 From: zhangyu Date: Thu, 20 Jul 2023 17:03:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Aexplore=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=94=81=E5=AE=9A=20=E4=BB=A5=E5=8F=8A=20das?= =?UTF-8?q?hboard=20=E6=97=B6=E9=97=B4=E9=94=81=E5=AE=9A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bottomBox/tabs/dashboardTab.vue | 2 +- .../common/bottomBox/tabs/logBottomTab.vue | 51 ++++++++++++++++++- .../components/page/dashboard/dashboard.vue | 7 ++- .../page/dashboard/explore/exploreItem.vue | 10 +--- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue index 4fcbedebb..671750f1c 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue @@ -868,7 +868,7 @@ export default { }) }, setTimePickerRange () { - if (!this.timePickerRange.nowTimeType) { + if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) { this.setDefaultTimeRange() } const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/logBottomTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/logBottomTab.vue index e24178ad2..1a7aeb9b7 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/logBottomTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/logBottomTab.vue @@ -30,7 +30,7 @@ - + @@ -73,7 +73,16 @@ export default { matchContent: '', loading: true, endpointLoading: false, - limit: 100 + limit: 100, + nowTimeType: {} + } + }, + computed: { + timePickerLocked () { + return this.$store.getters.getTimePickerLocked + }, + timePickerRange () { + return this.$store.getters.getTimePickerRange } }, methods: { @@ -119,8 +128,45 @@ export default { this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker.refresh() }, 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() }, + 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是一个请求 this.loading = true if (limit) { @@ -162,6 +208,7 @@ export default { } else if (this.from === fromRoute.asset) { this.expressions = [`{asset="${this.obj.name}"}`] } + this.setTimePickerRange() this.$nextTick(() => { this.queryLogData() }) diff --git a/nezha-fronted/src/components/page/dashboard/dashboard.vue b/nezha-fronted/src/components/page/dashboard/dashboard.vue index 4bb80fc1f..05867f29e 100644 --- a/nezha-fronted/src/components/page/dashboard/dashboard.vue +++ b/nezha-fronted/src/components/page/dashboard/dashboard.vue @@ -1157,7 +1157,8 @@ export default { }) }, setTimePickerRange () { - if (!this.timePickerRange.nowTimeType) { + if (this.$route.query.searchTime) return + if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) { this.setDefaultTimeRange() } const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType @@ -1188,6 +1189,10 @@ export default { mode: { target: this, propertyName: 'mode', type: 'string' } } this.initQueryFromPath(searchKeys) + this.$store.dispatch('dispatchTimePickerRange', { + time: this.searchTime, + nowTimeType: this.nowTimeType + }) this.showPanel.id = this.dashboardId this.filter.dashboardId = this.dashboardId // 设置查看模式 diff --git a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue index bae8bf141..42d8dc9b2 100644 --- a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue +++ b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue @@ -28,7 +28,7 @@
- + @@ -3563,7 +3563,6 @@ export default { mounted () { this.scrollbarWrap = this.$refs.exploreScrollbar this.scrollbarWrap.addEventListener('scroll', this.onScroll) - this.setTimePickerRange() this.initQueryFromPath() }, beforeDestroy () { @@ -3987,13 +3986,6 @@ export default { } }, expressionChange () { - const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType - this.pageObj.pageNo = 1 - this.setSearchTime(nowTimeType.type, nowTimeType.value) - this.$store.dispatch('dispatchTimePickerRange', { - time: this.searchTime, - nowTimeType: this.nowTimeType - }) if (this.expressions && this.expressions.length >= 1) { if (this.showMetrics) { this.queryTableData()