fix(查询组件): 默认日期为动态时间,点击重置总是重置到设置查询组件的日期,没有动态变化。 #18219

This commit is contained in:
dataeaseShu
2026-04-15 15:27:24 +08:00
committed by dataeaseShu
parent 2efd006fd0
commit 88ac54496c
3 changed files with 98 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import { getStyle } from '@/utils/style'
import eventBus from '@/utils/eventBus'
import { ref, toRefs, computed, nextTick } from 'vue'
import { ref, toRefs, computed, nextTick, onMounted, onBeforeUnmount } from 'vue'
import findComponent from '@/utils/components'
import { downloadCanvas2 } from '@/utils/imgUtils'
import ComponentEditBar from '@/components/visualization/ComponentEditBar.vue'
@@ -391,6 +391,45 @@ const updateFromMobile = (e, type) => {
const showPositionActive = computed(() =>
showPosition.value === 'edit-preview' ? 'preview' : showPosition.value
)
const isIntersecting = ref(false)
const observer = ref<IntersectionObserver | null>(null)
// 移动端懒加载开关
const isMobileLazyLoadEnabled = computed(() => {
return isMobile() || dvMainStore.inMobile || dvMainStore.mobileInPc
})
// 初始化IntersectionObserver
onMounted(() => {
if (isMobileLazyLoadEnabled.value && showPositionActive.value === 'preview') {
const wrapperInner = componentWrapperInnerRef.value
if (wrapperInner) {
observer.value = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
isIntersecting.value = true
// 一旦加载完成,不再监听
if (observer.value) {
observer.value.unobserve(entry.target)
}
}
})
},
{
rootMargin: '200px 0px', // 提前200px开始加载
threshold: 0.1
}
)
observer.value.observe(wrapperInner)
}
}
})
// 清理Observer
onBeforeUnmount(() => {
if (observer.value) {
observer.value.disconnect()
}
})
</script>
<template>
@@ -454,6 +493,7 @@ const showPositionActive = computed(() =>
@mousedown="onWrapperClickCur"
>
<component
v-if="isIntersecting || !isMobileLazyLoadEnabled"
:is="findComponent(config['component'])"
:view="viewInfo"
ref="component"

View File

@@ -10,6 +10,8 @@ import { ElMessage } from 'element-plus-secondary'
import { snapshotStoreWithOut } from '@/store/modules/data-visualization/snapshot'
import QueryConditionConfiguration from './QueryConditionConfiguration.vue'
import type { ComponentInfo } from '@/api/chart'
import { getDynamicRange, getCustomTime } from '@/custom-component/v-query/time-format'
import { getCustomRange } from '@/custom-component/v-query/time-format-dayjs'
import { infoFormat } from './options'
import {
onBeforeUnmount,
@@ -692,6 +694,57 @@ const resetData = () => {
: next.defaultMapValue
}
if (
next.defaultValueCheck &&
[1, 7].includes(+next.displayType) &&
next.timeType === 'dynamic'
) {
if (+next.displayType === 1) {
let selectValue = getDynamicRange(next) || []
next.defaultValue = new Date(selectValue[0])
next.selectValue = new Date(selectValue[0])
} else {
const {
timeNum,
relativeToCurrentType,
around,
relativeToCurrentRange,
arbitraryTime,
timeGranularity,
timeNumRange,
relativeToCurrentTypeRange,
aroundRange,
timeGranularityMultiple,
arbitraryTimeRange
} = next
let startTime = getCustomTime(
timeNum,
relativeToCurrentType,
timeGranularity,
around,
arbitraryTime,
timeGranularityMultiple,
'start-panel'
)
let endTime = getCustomTime(
timeNumRange,
relativeToCurrentTypeRange,
timeGranularity,
aroundRange,
arbitraryTimeRange,
timeGranularityMultiple,
'end-panel'
)
if (!!relativeToCurrentRange && relativeToCurrentRange !== 'custom') {
;[startTime, endTime] = getCustomRange(relativeToCurrentRange)
}
next.defaultValue = [startTime, endTime]
next.selectValue = [startTime, endTime]
}
}
;(props.element.cascade || []).forEach(ele => {
ele.forEach(item => {
const comId = item.datasetId.split('--')[1]

View File

@@ -817,4 +817,7 @@ strong {
.ed-card.ed-card {
--ed-card-border-radius: 12px !important;
}
}
.ed-message-box {
--ed-messagebox-border-radius: 12px !important;
}