fix(查询组件): 时间范围的动态时间自定义会出现 默认值超出日期筛选范围内

This commit is contained in:
dataeaseShu
2025-09-18 15:19:22 +08:00
committed by dataeaseShu
parent f21c0bcd23
commit 5c6f44eabb
5 changed files with 40 additions and 13 deletions

View File

@@ -3,7 +3,7 @@ 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 { getThisStart, getThisEnd, getLastStart, getAround } from './time-format-dayjs'
import { getThisStart, getThisEnd, getLastStart, getAroundStart } from './time-format-dayjs'
interface SelectConfig {
intervalType: string
regularOrTrendsValue: Date
@@ -86,7 +86,7 @@ const init = () => {
return
}
if (relativeToCurrent === 'custom') {
config.value.regularOrTrendsValue = getAround(
config.value.regularOrTrendsValue = getAroundStart(
relativeToCurrentType,
around === 'f' ? 'subtract' : 'add',
timeNum

View File

@@ -3,7 +3,7 @@ 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, getCustomRange } from './time-format-dayjs'
import { getAround, getCustomRange, getAroundStart } from './time-format-dayjs'
interface SelectConfig {
regularOrTrends: string
regularOrTrendsValue: [Date, Date]
@@ -109,13 +109,17 @@ const init = () => {
)
return
config.value.regularOrTrendsValue = [
getAround(relativeToCurrentTypeRange, 'add', 0),
getAroundStart(relativeToCurrentTypeRange, 'add', 0),
getAround(relativeToCurrentTypeRange, 'add', 1)
]
return
}
const startTime = getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
const startTime = getAroundStart(
relativeToCurrentType,
around === 'f' ? 'subtract' : 'add',
timeNum
)
const endTime = getAround(
relativeToCurrentTypeRange,
aroundRange === 'f' ? 'subtract' : 'add',

View File

@@ -33,6 +33,7 @@ import {
getThisEnd,
getLastStart,
getAround,
getAroundStart,
getCustomRange
} from './time-format-dayjs'
import { snapshotStoreWithOut } from '@/store/modules/data-visualization/snapshot'
@@ -1087,7 +1088,7 @@ const isInRange = (ele, startWindowTime, timeStamp) => {
}
let startTime
if (relativeToCurrent === 'custom') {
startTime = getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
startTime = getAroundStart(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
} else {
switch (relativeToCurrent) {
case 'thisYear':
@@ -1130,6 +1131,7 @@ const isInRange = (ele, startWindowTime, timeStamp) => {
break
}
}
const startValue = regularOrTrends === 'fixed' ? regularOrTrendsValue : startTime
if (intervalType === 'start') {
return startWindowTime < +new Date(startValue) || isDynamicWindowTime
@@ -1147,7 +1149,7 @@ const isInRange = (ele, startWindowTime, timeStamp) => {
? new Date(
dayjs(new Date(regularOrTrendsValue[0])).startOf(noTime).format('YYYY/MM/DD HH:mm:ss')
)
: getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
: getAroundStart(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
endTime =
regularOrTrends === 'fixed'
? new Date(
@@ -1508,6 +1510,8 @@ const validate = () => {
return true
}
if (!ele.setTimeRange) return false
console.log(startTime, endTime)
if (
isInRange(
ele,
@@ -3723,14 +3727,15 @@ defineExpose({
margin-bottom: 8px;
.field-select--input {
.ed-select-tags-wrapper.has-prefix {
margin-left: 25px;
.ed-select__prefix {
padding-right: 0;
}
.ed-select__input {
margin-left: 6px !important;
}
.ed-tag {
max-width: 52px;
max-width: 46px !important;
.ed-tag__close {
margin-left: 2px;
}

View File

@@ -12,6 +12,7 @@ import {
getThisEnd,
getLastStart,
getAround,
getAroundStart,
getCustomRange
} from './time-format-dayjs'
import VanPopup from 'vant/es/popup'
@@ -298,7 +299,7 @@ const disabledDate = val => {
}
let startTime
if (relativeToCurrent === 'custom') {
startTime = getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
startTime = getAroundStart(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
} else {
switch (relativeToCurrent) {
case 'thisYear':
@@ -361,7 +362,7 @@ const disabledDate = val => {
.startOf(queryTimeType.value)
.format('YYYY/MM/DD HH:mm:ss')
)
: getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
: getAroundStart(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
endTime =
regularOrTrends === 'fixed'
? new Date(

View File

@@ -23,6 +23,15 @@ function getAround(val = 'month' as ManipulateType, type = 'add', num = 0) {
return new Date(dayjs()[type](num, val).endOf('day').format('YYYY/MM/DD HH:mm:ss'))
}
function getAroundStart(val = 'month' as ManipulateType, type = 'add', num = 0) {
if (val === 'week') {
return new Date(
dayjs().startOf('week').add(1, 'day').startOf('day').format('YYYY/MM/DD HH:mm:ss')
)
}
return new Date(dayjs()[type](num, val).startOf('day').format('YYYY/MM/DD HH:mm:ss'))
}
function getThisWeek(): [Date, Date] {
return [
new Date(dayjs().startOf('week').add(1, 'day').startOf('day').format('YYYY/MM/DD HH:mm:ss')),
@@ -76,4 +85,12 @@ function getCustomRange(relativeToCurrentRange: string): [Date, Date] {
return [new Date(), new Date()]
}
}
export { getThisStart, getThisEnd, getLastStart, getLastEnd, getAround, getCustomRange }
export {
getThisStart,
getThisEnd,
getLastStart,
getLastEnd,
getAround,
getCustomRange,
getAroundStart
}