forked from github/dataease
fix(查询组件): 日期筛选支持按周,按月范围过滤 #7310
This commit is contained in:
parent
3100b24e45
commit
8835f633d3
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { toRefs, PropType, ref, onBeforeMount, watch, nextTick, computed, h } from 'vue'
|
import { toRefs, PropType, ref, onBeforeMount, watch, nextTick, computed } from 'vue'
|
||||||
import { type DatePickType } from 'element-plus-secondary'
|
import { type DatePickType } from 'element-plus-secondary'
|
||||||
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
|
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
|
||||||
import type { ManipulateType } from 'dayjs'
|
import type { ManipulateType } from 'dayjs'
|
||||||
@ -81,8 +81,108 @@ watch(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
const callback = () => {
|
const isInRange = (ele, startWindowTime, timeStamp) => {
|
||||||
return true
|
const {
|
||||||
|
intervalType,
|
||||||
|
regularOrTrends,
|
||||||
|
regularOrTrendsValue,
|
||||||
|
relativeToCurrent,
|
||||||
|
timeNum,
|
||||||
|
relativeToCurrentType,
|
||||||
|
around,
|
||||||
|
dynamicWindow,
|
||||||
|
maximumSingleQuery,
|
||||||
|
timeNumRange,
|
||||||
|
relativeToCurrentTypeRange,
|
||||||
|
aroundRange
|
||||||
|
} = ele.timeRange || {}
|
||||||
|
let isDynamicWindowTime = false
|
||||||
|
const noTime = ele.timeGranularityMultiple.split('time').join('').split('range')[0]
|
||||||
|
const queryTimeType = noTime === 'date' ? 'day' : (noTime as ManipulateType)
|
||||||
|
if (startWindowTime && dynamicWindow) {
|
||||||
|
isDynamicWindowTime =
|
||||||
|
dayjs(startWindowTime)
|
||||||
|
.add(maximumSingleQuery, queryTimeType)
|
||||||
|
.startOf(queryTimeType)
|
||||||
|
.valueOf() -
|
||||||
|
1000 <
|
||||||
|
timeStamp
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intervalType === 'none') {
|
||||||
|
if (dynamicWindow) return isDynamicWindowTime
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let startTime
|
||||||
|
if (relativeToCurrent === 'custom') {
|
||||||
|
startTime = getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
|
||||||
|
} else {
|
||||||
|
switch (relativeToCurrent) {
|
||||||
|
case 'thisYear':
|
||||||
|
startTime = getThisStart('year')
|
||||||
|
break
|
||||||
|
case 'lastYear':
|
||||||
|
startTime = getLastStart('year')
|
||||||
|
break
|
||||||
|
case 'thisMonth':
|
||||||
|
startTime = getThisStart('month')
|
||||||
|
break
|
||||||
|
case 'lastMonth':
|
||||||
|
startTime = getLastStart('month')
|
||||||
|
break
|
||||||
|
case 'today':
|
||||||
|
startTime = getThisStart('day')
|
||||||
|
break
|
||||||
|
case 'yesterday':
|
||||||
|
startTime = getLastStart('day')
|
||||||
|
break
|
||||||
|
case 'monthBeginning':
|
||||||
|
startTime = getThisStart('month')
|
||||||
|
break
|
||||||
|
case 'yearBeginning':
|
||||||
|
startTime = getThisStart('year')
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const startValue = regularOrTrends === 'fixed' ? regularOrTrendsValue : startTime
|
||||||
|
if (intervalType === 'start') {
|
||||||
|
return startWindowTime < +new Date(startValue) || isDynamicWindowTime
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intervalType === 'end') {
|
||||||
|
return timeStamp > +new Date(startValue) || isDynamicWindowTime
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intervalType === 'timeInterval') {
|
||||||
|
const startTime =
|
||||||
|
regularOrTrends === 'fixed'
|
||||||
|
? regularOrTrendsValue[0]
|
||||||
|
: getAround(relativeToCurrentType, around === 'f' ? 'subtract' : 'add', timeNum)
|
||||||
|
const endTime =
|
||||||
|
regularOrTrends === 'fixed'
|
||||||
|
? regularOrTrendsValue[1]
|
||||||
|
: getAround(
|
||||||
|
relativeToCurrentTypeRange,
|
||||||
|
aroundRange === 'f' ? 'subtract' : 'add',
|
||||||
|
timeNumRange
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
startWindowTime < +new Date(startTime) - 1000 ||
|
||||||
|
timeStamp > +new Date(endTime) ||
|
||||||
|
isDynamicWindowTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const callback = param => {
|
||||||
|
startWindowTime.value = param[0]
|
||||||
|
const disabled = param.some(ele => {
|
||||||
|
return disabledDate(ele)
|
||||||
|
})
|
||||||
|
startWindowTime.value = 0
|
||||||
|
return disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
const { shortcuts } = useShortcuts(callback)
|
const { shortcuts } = useShortcuts(callback)
|
||||||
@ -382,7 +482,9 @@ const formatDate = computed(() => {
|
|||||||
@calendar-change="calendarChange"
|
@calendar-change="calendarChange"
|
||||||
:format="formatDate"
|
:format="formatDate"
|
||||||
v-if="multiple"
|
v-if="multiple"
|
||||||
:shortcuts="shortcuts"
|
:shortcuts="
|
||||||
|
['datetimerange', 'daterange'].includes(config.timeGranularityMultiple) ? shortcuts : []
|
||||||
|
"
|
||||||
@change="handleValueChange"
|
@change="handleValueChange"
|
||||||
:range-separator="$t('cron.to')"
|
:range-separator="$t('cron.to')"
|
||||||
:start-placeholder="$t('datasource.start_time')"
|
:start-placeholder="$t('datasource.start_time')"
|
||||||
|
@ -37,70 +37,75 @@ let callback: Function = () => {}
|
|||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
text: 'dynamic_time.cweek',
|
text: 'dynamic_time.cweek',
|
||||||
onClick: ({ attrs, slots, emit }) => {
|
onClick: ({ emit }) => {
|
||||||
if (
|
const startTime = new Date(+new Date(getThisStart('week')) + 24 * 1000 * 3600)
|
||||||
callback([
|
const endTime = new Date(+new Date(getThisEnd('week')) + 24 * 1000 * 3600)
|
||||||
new Date(+new Date(getThisStart('week')) + 24 * 1000 * 3600),
|
if (callback([startTime, endTime])) return
|
||||||
new Date(+new Date(getThisEnd('week')) + 24 * 1000 * 3600)
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
])
|
|
||||||
)
|
|
||||||
return
|
|
||||||
emit('pick', [
|
|
||||||
dayjs(new Date(+new Date(getThisStart('week')) + 24 * 1000 * 3600)),
|
|
||||||
dayjs(new Date(+new Date(getThisEnd('week')) + 24 * 1000 * 3600))
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_month.current',
|
text: 'dynamic_month.current',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getThisStart('month'), getThisEnd('month')]
|
const startTime = getThisStart('month')
|
||||||
},
|
const endTime = getThisEnd('month')
|
||||||
onClick: () => {
|
if (callback([startTime, endTime])) return
|
||||||
console.log(113)
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_time.cquarter',
|
text: 'dynamic_time.cquarter',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getThisStart('quarter'), getThisEnd('quarter')]
|
const startTime = getThisStart('quarter')
|
||||||
},
|
const endTime = getThisEnd('quarter')
|
||||||
onClick: () => {
|
if (callback([startTime, endTime])) return
|
||||||
console.log(113)
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_year.current',
|
text: 'dynamic_year.current',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getThisStart('year'), getThisEnd('year')]
|
const startTime = getThisStart('year')
|
||||||
|
const endTime = getThisEnd('year')
|
||||||
|
if (callback([startTime, endTime])) return
|
||||||
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
text: 'dynamic_time.lweek',
|
text: 'dynamic_time.lweek',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [
|
const startTime = new Date(+new Date(getLastStart('week')) + 24 * 1000 * 3600)
|
||||||
new Date(+new Date(getLastStart('week')) + 24 * 1000 * 3600),
|
const endTime = new Date(+new Date(getLastEnd('week')) + 24 * 1000 * 3600)
|
||||||
new Date(+new Date(getLastEnd('week')) + 24 * 1000 * 3600)
|
if (callback([startTime, endTime])) return
|
||||||
]
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_month.last',
|
text: 'dynamic_month.last',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getLastStart('month'), getLastEnd('month')]
|
const startTime = getLastStart('month')
|
||||||
|
const endTime = getLastEnd('month')
|
||||||
|
if (callback([startTime, endTime])) return
|
||||||
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_time.lquarter',
|
text: 'dynamic_time.lquarter',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getLastStart('quarter'), getLastEnd('quarter')]
|
const startTime = getLastStart('quarter')
|
||||||
|
const endTime = getLastEnd('quarter')
|
||||||
|
if (callback([startTime, endTime])) return
|
||||||
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'dynamic_year.last',
|
text: 'dynamic_year.last',
|
||||||
value: () => {
|
onClick: ({ emit }) => {
|
||||||
return [getLastStart('year'), getLastEnd('year')]
|
const startTime = getLastStart('year')
|
||||||
|
const endTime = getLastEnd('year')
|
||||||
|
if (callback([startTime, endTime])) return
|
||||||
|
emit('pick', [dayjs(startTime), dayjs(endTime)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user