diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTab.vue index 563e59fd4..caad524b9 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTab.vue @@ -531,6 +531,7 @@ export default { }) }, getAlertList () { + this.setSearchTime('searchTime') this.tableData = [] this.loading = true this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo) diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue index 4ea39c3fa..e40e536c2 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue @@ -382,6 +382,7 @@ export default { }) }, dateChange () { + this.setSearchTime('searchTimeHeader') this.getTableData() }, getTableData (state) { diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/endpointQueryTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/endpointQueryTab.vue index e8c45f60f..7f7d9b8ff 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/endpointQueryTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/endpointQueryTab.vue @@ -431,6 +431,7 @@ export default { }) }, queryChartDate () { + this.setSearchTime('searchTime') const start = this.searchTime[0] ? this.searchTime[0] : this.getTime(-1, 'h') const end = this.searchTime[1] ? this.searchTime[1] : this.getTime(0, 'h') this.searchTime = [start, end] diff --git a/nezha-fronted/src/components/common/mixin/mainMixinFun.js b/nezha-fronted/src/components/common/mixin/mainMixinFun.js index 81e127835..de60172f4 100644 --- a/nezha-fronted/src/components/common/mixin/mainMixinFun.js +++ b/nezha-fronted/src/components/common/mixin/mainMixinFun.js @@ -152,6 +152,38 @@ export default { } return aliasExpression } + }, + /* 时间条件查询--end */ + setSearchTime (key, cb) { // 设置searchTime + if (this.$refs.pickTime) { + const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType + this.nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType + const type = nowTimeType.type + const val = nowTimeType.value + 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[key], 0, startTime) + this.$set(this[key], 1, endTime) + this.$set(this[key], 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[key], 0, startTime) + this.$set(this[key], 1, endTime) + this.$set(this[key], 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[key], 0, startTime) + this.$set(this[key], 1, endTime) + this.$set(this[key], 2, val + 'd') + } + this.$refs.pickTime.$refs.timePicker.searchTime = this[key] + } + if (cb) { + this.cb() + } } } } diff --git a/nezha-fronted/src/components/page/alert/alertMessage.vue b/nezha-fronted/src/components/page/alert/alertMessage.vue index 6c6fd1ed5..447410db5 100644 --- a/nezha-fronted/src/components/page/alert/alertMessage.vue +++ b/nezha-fronted/src/components/page/alert/alertMessage.vue @@ -881,6 +881,7 @@ export default { }, dateChange () { + this.setSearchTime('searchTime') this.getTableData() }, getTableData (state) { diff --git a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue index fbca9f952..0c8a1f9b2 100644 --- a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue +++ b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue @@ -3988,6 +3988,11 @@ export default { } }, expressionChange () { + if (this.$refs.pickTime) { + const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType + this.nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType + this.setSearchTime(nowTimeType.type, nowTimeType.value) + } if (this.expressions && this.expressions.length >= 1) { if (this.showMetrics) { this.queryTableData() diff --git a/nezha-fronted/src/store/timePicker.js b/nezha-fronted/src/store/timePicker.js index bc6afd612..18f904cf6 100644 --- a/nezha-fronted/src/store/timePicker.js +++ b/nezha-fronted/src/store/timePicker.js @@ -1,7 +1,7 @@ const timePicker = { state: { timePickerLocked: localStorage.getItem('nz-time-picker-locked') ? JSON.parse(localStorage.getItem('nz-time-picker-locked')) : false, - timePickerRange: localStorage.getItem('nz-time-picker-range') ? JSON.parse(localStorage.getItem('nz-time-picker-range')) : {}, + timePickerRange: localStorage.getItem('nz-time-picker-range') ? JSON.parse(localStorage.getItem('nz-time-picker-range')) : {} }, mutations: { setTimePickerLocked (state, flag) {