mirror of
https://github.com/dataease/dataease.git
synced 2025-02-25 12:03:05 +08:00
feat(查询组件): 日期范围组件,默认值没有本月、本年等 #11283
This commit is contained in:
parent
4287ed620b
commit
fc51f531ed
@ -156,6 +156,85 @@ const relativeToCurrentList = computed(() => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const relativeToCurrentListRange = computed(() => {
|
||||||
|
let list = []
|
||||||
|
if (!curComponent.value) return list
|
||||||
|
switch (curComponent.value.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'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
const aroundList = [
|
const aroundList = [
|
||||||
{
|
{
|
||||||
label: '前',
|
label: '前',
|
||||||
@ -405,8 +484,22 @@ defineExpose({
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="dynamicTime && curComponent.displayType === '7'">
|
<template v-else-if="dynamicTime && curComponent.displayType === '7'">
|
||||||
|
<div class="setting">
|
||||||
|
<div class="setting-label">相对当前</div>
|
||||||
|
<div class="setting-value select">
|
||||||
|
<el-select @focus="handleDialogClick" v-model="curComponent.relativeToCurrentRange">
|
||||||
|
<el-option
|
||||||
|
v-for="item in relativeToCurrentListRange"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="setting"
|
class="setting"
|
||||||
|
v-if="curComponent.relativeToCurrentRange === 'custom'"
|
||||||
:class="
|
:class="
|
||||||
['yearrange', 'monthrange', 'daterange'].includes(
|
['yearrange', 'monthrange', 'daterange'].includes(
|
||||||
curComponent.timeGranularityMultiple
|
curComponent.timeGranularityMultiple
|
||||||
@ -437,6 +530,7 @@ defineExpose({
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="setting"
|
class="setting"
|
||||||
|
v-if="curComponent.relativeToCurrentRange === 'custom'"
|
||||||
:class="
|
:class="
|
||||||
['yearrange', 'monthrange', 'daterange'].includes(
|
['yearrange', 'monthrange', 'daterange'].includes(
|
||||||
curComponent.timeGranularityMultiple
|
curComponent.timeGranularityMultiple
|
||||||
|
@ -3,6 +3,7 @@ import { toRefs, PropType, ref, onBeforeMount, watch, computed } from 'vue'
|
|||||||
import { Calendar } from '@element-plus/icons-vue'
|
import { Calendar } from '@element-plus/icons-vue'
|
||||||
import { type DatePickType } from 'element-plus-secondary'
|
import { type DatePickType } from 'element-plus-secondary'
|
||||||
import { getCustomTime } from './time-format'
|
import { getCustomTime } from './time-format'
|
||||||
|
import { getCustomRange } from './time-format-dayjs'
|
||||||
interface SelectConfig {
|
interface SelectConfig {
|
||||||
timeType: string
|
timeType: string
|
||||||
timeGranularityMultiple: DatePickType
|
timeGranularityMultiple: DatePickType
|
||||||
@ -10,6 +11,7 @@ interface SelectConfig {
|
|||||||
selectValue: [Date, Date]
|
selectValue: [Date, Date]
|
||||||
defaultValueCheck: boolean
|
defaultValueCheck: boolean
|
||||||
id: string
|
id: string
|
||||||
|
relativeToCurrentRange: string
|
||||||
timeNum: number
|
timeNum: number
|
||||||
relativeToCurrentType: string
|
relativeToCurrentType: string
|
||||||
around: string
|
around: string
|
||||||
@ -37,6 +39,7 @@ const props = defineProps({
|
|||||||
defaultValueCheck: false,
|
defaultValueCheck: false,
|
||||||
timeGranularity: 'date',
|
timeGranularity: 'date',
|
||||||
timeNumRange: 0,
|
timeNumRange: 0,
|
||||||
|
relativeToCurrentRange: 'custom',
|
||||||
relativeToCurrentTypeRange: 'year',
|
relativeToCurrentTypeRange: 'year',
|
||||||
aroundRange: 'f',
|
aroundRange: 'f',
|
||||||
arbitraryTimeRange: new Date()
|
arbitraryTimeRange: new Date()
|
||||||
@ -53,6 +56,7 @@ const timeConfig = computed(() => {
|
|||||||
relativeToCurrentType,
|
relativeToCurrentType,
|
||||||
timeGranularityMultiple,
|
timeGranularityMultiple,
|
||||||
around,
|
around,
|
||||||
|
relativeToCurrentRange,
|
||||||
defaultValueCheck,
|
defaultValueCheck,
|
||||||
arbitraryTime,
|
arbitraryTime,
|
||||||
timeGranularity,
|
timeGranularity,
|
||||||
@ -65,6 +69,7 @@ const timeConfig = computed(() => {
|
|||||||
timeNum,
|
timeNum,
|
||||||
relativeToCurrentType,
|
relativeToCurrentType,
|
||||||
around,
|
around,
|
||||||
|
relativeToCurrentRange,
|
||||||
timeGranularityMultiple,
|
timeGranularityMultiple,
|
||||||
defaultValueCheck,
|
defaultValueCheck,
|
||||||
arbitraryTime,
|
arbitraryTime,
|
||||||
@ -113,6 +118,7 @@ const init = () => {
|
|||||||
timeNumRange,
|
timeNumRange,
|
||||||
relativeToCurrentTypeRange,
|
relativeToCurrentTypeRange,
|
||||||
aroundRange,
|
aroundRange,
|
||||||
|
relativeToCurrentRange,
|
||||||
arbitraryTimeRange
|
arbitraryTimeRange
|
||||||
} = timeConfig.value
|
} = timeConfig.value
|
||||||
if (!defaultValueCheck) {
|
if (!defaultValueCheck) {
|
||||||
@ -120,6 +126,11 @@ const init = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (relativeToCurrentRange !== 'custom') {
|
||||||
|
selectValue.value = getCustomRange(relativeToCurrentRange)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const startTime = getCustomTime(
|
const startTime = getCustomTime(
|
||||||
timeNum,
|
timeNum,
|
||||||
relativeToCurrentType,
|
relativeToCurrentType,
|
||||||
|
@ -996,6 +996,7 @@ const parameterCompletion = () => {
|
|||||||
parametersEnd: null,
|
parametersEnd: null,
|
||||||
relativeToCurrent: 'custom',
|
relativeToCurrent: 'custom',
|
||||||
timeNum: 0,
|
timeNum: 0,
|
||||||
|
relativeToCurrentRange: 'custom',
|
||||||
relativeToCurrentType: 'year',
|
relativeToCurrentType: 'year',
|
||||||
around: 'f',
|
around: 'f',
|
||||||
arbitraryTime: new Date(),
|
arbitraryTime: new Date(),
|
||||||
@ -1209,6 +1210,85 @@ const relativeToCurrentList = computed(() => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const relativeToCurrentListRange = computed(() => {
|
||||||
|
let list = []
|
||||||
|
if (!curComponent.value) return list
|
||||||
|
switch (curComponent.value.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'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
const timeGranularityChange = (val: string) => {
|
const timeGranularityChange = (val: string) => {
|
||||||
if (
|
if (
|
||||||
['year', 'month', 'date', 'datetime'].indexOf(val) <
|
['year', 'month', 'date', 'datetime'].indexOf(val) <
|
||||||
@ -1236,6 +1316,10 @@ const timeGranularityMultipleChange = (val: string) => {
|
|||||||
curComponent.value.relativeToCurrentTypeRange = 'year'
|
curComponent.value.relativeToCurrentTypeRange = 'year'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curComponent.value.relativeToCurrentRange !== 'custom') {
|
||||||
|
curComponent.value.relativeToCurrentRange = relativeToCurrentListRange.value[0]?.value
|
||||||
|
}
|
||||||
|
|
||||||
curComponent.value.timeRange = {
|
curComponent.value.timeRange = {
|
||||||
intervalType: 'none',
|
intervalType: 'none',
|
||||||
dynamicWindow: false,
|
dynamicWindow: false,
|
||||||
@ -1243,6 +1327,7 @@ const timeGranularityMultipleChange = (val: string) => {
|
|||||||
regularOrTrends: 'fixed',
|
regularOrTrends: 'fixed',
|
||||||
regularOrTrendsValue: '',
|
regularOrTrendsValue: '',
|
||||||
relativeToCurrent: 'custom',
|
relativeToCurrent: 'custom',
|
||||||
|
relativeToCurrentRange: 'custom',
|
||||||
timeNum: 0,
|
timeNum: 0,
|
||||||
relativeToCurrentType: 'year',
|
relativeToCurrentType: 'year',
|
||||||
around: 'f',
|
around: 'f',
|
||||||
|
@ -20,4 +20,46 @@ function getAround(val = 'month' as ManipulateType, type = 'add', num = 0) {
|
|||||||
return new Date(dayjs()[type](num, val).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'))
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getThisStart, getThisEnd, getLastStart, getLastEnd, getAround }
|
function getCustomRange(relativeToCurrentRange: string): [Date, Date] {
|
||||||
|
switch (relativeToCurrentRange) {
|
||||||
|
case 'thisYear':
|
||||||
|
return [getThisStart('year'), getThisEnd('year')]
|
||||||
|
case 'lastYear':
|
||||||
|
return [getLastStart('year'), getLastEnd('year')]
|
||||||
|
case 'thisMonth':
|
||||||
|
return [getThisStart('month'), getThisEnd('month')]
|
||||||
|
case 'lastMonth':
|
||||||
|
return [getLastStart('month'), getLastEnd('month')]
|
||||||
|
case 'LastThreeMonths':
|
||||||
|
return [
|
||||||
|
new Date(dayjs().subtract(3, 'month').startOf('month').format('YYYY/MM/DD HH:mm:ss')),
|
||||||
|
getThisEnd('day')
|
||||||
|
]
|
||||||
|
case 'LastSixMonths':
|
||||||
|
return [
|
||||||
|
new Date(dayjs().subtract(6, 'month').startOf('month').format('YYYY/MM/DD HH:mm:ss')),
|
||||||
|
getThisEnd('day')
|
||||||
|
]
|
||||||
|
case 'LastTwelveMonths':
|
||||||
|
return [
|
||||||
|
new Date(dayjs().subtract(12, 'month').startOf('month').format('YYYY/MM/DD HH:mm:ss')),
|
||||||
|
getThisEnd('day')
|
||||||
|
]
|
||||||
|
case 'today':
|
||||||
|
return [getThisStart('day'), getThisEnd('day')]
|
||||||
|
case 'yesterday':
|
||||||
|
return [getLastStart('day'), getLastEnd('day')]
|
||||||
|
case 'LastThreeDays':
|
||||||
|
return [
|
||||||
|
new Date(dayjs().subtract(3, 'day').startOf('day').format('YYYY/MM/DD HH:mm:ss')),
|
||||||
|
getThisEnd('day')
|
||||||
|
]
|
||||||
|
case 'monthBeginning':
|
||||||
|
return [getThisStart('month'), getThisEnd('day')]
|
||||||
|
case 'yearBeginning':
|
||||||
|
return [getThisStart('year'), getThisEnd('day')]
|
||||||
|
default:
|
||||||
|
return [new Date(), new Date()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export { getThisStart, getThisEnd, getLastStart, getLastEnd, getAround, getCustomRange }
|
||||||
|
Loading…
Reference in New Issue
Block a user