diff --git a/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js b/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js index ec41b71476..94dcb6321e 100644 --- a/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js +++ b/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js @@ -222,6 +222,10 @@ class TimeDateRangeServiceImpl extends WidgetService { } } dynamicDateFormNow(element) { + const values = this.dynamicDateFormNowProxy(element) + return this.formatDynamicTimes(values, element) + } + dynamicDateFormNowProxy(element) { if (element.options.attrs.default === null || typeof element.options.attrs.default === 'undefined' || !element.options.attrs.default.isDynamic) return null if (element.options.attrs.default.dkey === 0) { @@ -265,6 +269,34 @@ class TimeDateRangeServiceImpl extends WidgetService { return [startTime, endTime] } } + + formatDynamicTimes(values, element) { + if (!values || !values.length || !element.options.attrs.default.isDynamic) { + return values + } + const baseTime = new Date('2022-11-09 00:00:00.000').getTime() + let labelFormat = 'yyyy-MM-dd' + if (element.options.attrs.showTime && element.options.attrs.accuracy) { + labelFormat = labelFormat + ' ' + element.options.attrs.accuracy + } + let start = values[0] + let end = values[1] + const attrs = element.options.attrs + + if (attrs.default.sDynamicSuffixTime && attrs.default.isDynamic && attrs.default.dkey === 4 && attrs.showTime) { + start = attrs.default.sDynamicSuffixTime - baseTime + timeSection(start, 'date')[0] + } else { + start = timeSection(start, 'date', labelFormat)[0] + } + if (attrs.default.eDynamicSuffixTime && attrs.default.isDynamic && attrs.default.dkey === 4 && attrs.showTime) { + end = attrs.default.eDynamicSuffixTime - baseTime + timeSection(end, 'date')[0] + } else { + end = timeSection(end, 'date', labelFormat)[1] + } + + const results = [start, end] + return results + } validDynamicValue(element) { if (!element.options.attrs.default.isDynamic) return true if (element.options.attrs.default.dkey !== 4) return true diff --git a/frontend/src/styles/index.scss b/frontend/src/styles/index.scss index 3b1b8cfb1d..c7cf1088bc 100644 --- a/frontend/src/styles/index.scss +++ b/frontend/src/styles/index.scss @@ -770,7 +770,7 @@ div:focus { .no-label-item { .el-form-item__content { - margin-left: 10px !important; + margin-left: 5px !important; } } diff --git a/frontend/src/views/panel/filter/defaultValue/DeDateRangeDefault.vue b/frontend/src/views/panel/filter/defaultValue/DeDateRangeDefault.vue index a43ca1ea5a..50f4324659 100644 --- a/frontend/src/views/panel/filter/defaultValue/DeDateRangeDefault.vue +++ b/frontend/src/views/panel/filter/defaultValue/DeDateRangeDefault.vue @@ -13,10 +13,8 @@ @change="dynamicChange" > {{ $t('dynamic_time.fix') }} - {{ $t('dynamic_time.dynamic') }} + {{ $t('dynamic_time.dynamic') }} + @@ -82,6 +80,7 @@ > + + + +
@@ -153,6 +169,7 @@ > + + + +
time[0] || this.isOneDay)) this.element.options.manualModify = false + }, + + fillEmptySuffixTime() { + if (!this.element.options.attrs.default.sDynamicSuffixTime) { + this.$set(this.element.options.attrs.default, 'sDynamicSuffixTime', this.baseTime) + } + + if (!this.element.options.attrs.default.eDynamicSuffixTime) { + this.$set(this.element.options.attrs.default, 'eDynamicSuffixTime', new Date('2022-11-09 23:59:59.999').getTime()) + } + }, + eDynamicSuffixTimeChange(val) { + this.setDval() + }, + sDynamicSuffixTimeChange(val) { + this.setDval() } } } diff --git a/frontend/src/views/panel/filter/filterMain/FilterControl.vue b/frontend/src/views/panel/filter/filterMain/FilterControl.vue index d4234d9e74..4067341c30 100644 --- a/frontend/src/views/panel/filter/filterMain/FilterControl.vue +++ b/frontend/src/views/panel/filter/filterMain/FilterControl.vue @@ -270,7 +270,10 @@ export default { }, showTimeChange(value) { this.attrs.accuracy = this.accuracyOptions[1].id - this.attrs.default.isDynamic = false + if (this.widget.name !== 'timeDateRangeWidget') { + this.attrs.default.isDynamic = false + } + this.fillAttrs2Filter() }, checkedViewsChange(values) {