diff --git a/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue b/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue index 4a8630f3e7..971f86f52f 100644 --- a/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue +++ b/core/core-frontend/src/custom-component/v-query/DynamicTimeRangeFiltering.vue @@ -3,11 +3,12 @@ import { toRefs, PropType, onBeforeMount, watch, computed } from 'vue' import { Calendar } from '@element-plus/icons-vue' import { type DatePickType } from 'element-plus-secondary' import type { ManipulateType } from 'dayjs' -import { getAround } from './time-format-dayjs' +import { getAround, getCustomRange } from './time-format-dayjs' interface SelectConfig { regularOrTrends: string regularOrTrendsValue: [Date, Date] intervalType: string + relativeToCurrentRange: string timeNum: number relativeToCurrentType: ManipulateType around: string @@ -27,6 +28,7 @@ const props = defineProps({ regularOrTrends: 'fixed', timeNum: 0, intervalType: 'none', + relativeToCurrentRange: 'custom', relativeToCurrentType: 'year', around: 'f', timeGranularity: 'date', @@ -50,6 +52,7 @@ const timeConfig = computed(() => { timeNum, relativeToCurrentType, around, + relativeToCurrentRange, intervalType, regularOrTrends, timeGranularity, @@ -62,6 +65,7 @@ const timeConfig = computed(() => { relativeToCurrentType, around, intervalType, + relativeToCurrentRange, regularOrTrends, timeGranularity, timeNumRange, @@ -87,10 +91,13 @@ watch( ) const init = () => { + console.log('relativeToCurrentRange') + const { timeNum, relativeToCurrentType, around, + relativeToCurrentRange, regularOrTrends, timeNumRange, relativeToCurrentTypeRange, @@ -117,6 +124,11 @@ const init = () => { timeNumRange ) + if (!!relativeToCurrentRange && relativeToCurrentRange !== 'custom') { + config.value.regularOrTrendsValue = getCustomRange(relativeToCurrentRange) + return + } + config.value.regularOrTrendsValue = [startTime, endTime] } diff --git a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue index e012f070c5..b5ab99edc2 100644 --- a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue +++ b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue @@ -576,16 +576,21 @@ const isInRange = (ele, startWindowTime, timeStamp) => { if (intervalType === 'timeInterval') { const startTime = regularOrTrends === 'fixed' - ? regularOrTrendsValue[0] + ? new Date( + dayjs(new Date(regularOrTrendsValue[0])).startOf(noTime).format('YYYY/MM/DD HH:mm:ss') + ) : getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum) const endTime = regularOrTrends === 'fixed' - ? regularOrTrendsValue[1] + ? new Date( + dayjs(new Date(regularOrTrendsValue[1])).endOf(noTime).format('YYYY/MM/DD HH:mm:ss') + ) : getAround( relativeToCurrentTypeRange, aroundRange === 'f' ? 'subtract' : 'add', timeNumRange ) + return ( startWindowTime < +new Date(startTime) - 1000 || timeStamp > +new Date(endTime) || @@ -760,7 +765,7 @@ const validate = () => { 'end-config' ) : new Date(ele.defaultValue[1]) - if (!relativeToCurrentRange || relativeToCurrentRange === 'custom') { + if (!!relativeToCurrentRange && relativeToCurrentRange !== 'custom') { ;[startTime, endTime] = getCustomRange(relativeToCurrentRange) } if (+startTime > +endTime) { @@ -1032,6 +1037,10 @@ const parameterCompletion = () => { Object.entries(attributes).forEach(([key, val]) => { !curComponent.value[key] && (curComponent.value[key] = val) }) + + if (!curComponent.value.timeRange.relativeToCurrentRange) { + curComponent.value.timeRange.relativeToCurrentRange = 'custom' + } } const handleCondition = item => { diff --git a/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue b/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue index b1ed8a2cc0..b1d08522aa 100644 --- a/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue +++ b/core/core-frontend/src/custom-component/v-query/RangeFilterTime.vue @@ -11,6 +11,7 @@ const props = defineProps({ dynamicWindow: false, maximumSingleQuery: 0, regularOrTrends: 'fixed', + relativeToCurrentRange: 'custom', regularOrTrendsValue: '', relativeToCurrent: 'custom', timeNum: 0, @@ -173,6 +174,85 @@ const relativeToCurrentList = computed(() => { } ] }) + +const relativeToCurrentListRange = computed(() => { + let list = [] + if (!timeRange.value) return list + switch (props.timeGranularityMultiple) { + case 'yearrange': + list = [ + { + label: '今年', + value: 'thisYear' + }, + { + label: '去年', + value: 'lastYear' + } + ] + break + case 'monthrange': + list = [ + { + label: '本月', + value: 'thisMonth' + }, + { + label: '上月', + value: 'lastMonth' + }, + { + label: '最近 3 个 月', + value: 'LastThreeMonths' + }, + { + label: '最近 6 个 月', + value: 'LastSixMonths' + }, + { + label: '最近 12 个 月', + value: 'LastTwelveMonths' + } + ] + break + case 'daterange': + case 'datetimerange': + list = [ + { + label: '今天', + value: 'today' + }, + { + label: '昨天', + value: 'yesterday' + }, + { + label: '最近 3 天', + value: 'LastThreeDays' + }, + { + label: '月初至今', + value: 'monthBeginning' + }, + { + label: '年初至今', + value: 'yearBeginning' + } + ] + break + + default: + break + } + + return [ + ...list, + { + label: '自定义', + value: 'custom' + } + ] +})