forked from github/dataease
Merge pull request #1610 from dataease/pr@dev@fix_dynamic_filter_date
fix: 动态日期过滤组件月份逻辑
This commit is contained in:
commit
2de66cf8d7
@ -159,18 +159,10 @@ class TimeDateRangeServiceImpl extends WidgetService {
|
|||||||
const nowYear = now.getFullYear()
|
const nowYear = now.getFullYear()
|
||||||
const nowDate = now.getDate()
|
const nowDate = now.getDate()
|
||||||
|
|
||||||
const tarYear = nowYear
|
|
||||||
if (dynamicSuffix === 'before') {
|
if (dynamicSuffix === 'before') {
|
||||||
const deffMonth = nowMonth - dynamicPrefix
|
return new Date(nowYear, nowMonth - dynamicPrefix, nowDate).getTime()
|
||||||
let diffYear = deffMonth / 12
|
|
||||||
if (deffMonth < 0) {
|
|
||||||
diffYear -= 1
|
|
||||||
}
|
|
||||||
return new Date(tarYear + diffYear, nowMonth - dynamicPrefix % 12, nowDate).getTime()
|
|
||||||
} else {
|
} else {
|
||||||
const deffMonth = nowMonth + dynamicPrefix
|
return new Date(nowYear, nowMonth + dynamicPrefix, nowDate).getTime()
|
||||||
const diffYear = deffMonth / 12
|
|
||||||
return new Date(tarYear + diffYear, deffMonth % 12, nowDate).getTime()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dynamicInfill === 'year') {
|
if (dynamicInfill === 'year') {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { WidgetService } from '../service/WidgetService'
|
import {
|
||||||
|
WidgetService
|
||||||
|
} from '../service/WidgetService'
|
||||||
|
|
||||||
const leftPanel = {
|
const leftPanel = {
|
||||||
icon: 'iconfont icon-ri',
|
icon: 'iconfont icon-ri',
|
||||||
@ -45,7 +47,9 @@ const drawPanel = {
|
|||||||
|
|
||||||
class TimeDateServiceImpl extends WidgetService {
|
class TimeDateServiceImpl extends WidgetService {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
Object.assign(options, { name: 'timeDateWidget' })
|
Object.assign(options, {
|
||||||
|
name: 'timeDateWidget'
|
||||||
|
})
|
||||||
super(options)
|
super(options)
|
||||||
this.filterDialog = true
|
this.filterDialog = true
|
||||||
this.showSwitch = false
|
this.showSwitch = false
|
||||||
@ -111,16 +115,10 @@ class TimeDateServiceImpl extends WidgetService {
|
|||||||
const nowYear = now.getFullYear()
|
const nowYear = now.getFullYear()
|
||||||
const nowDate = now.getDate()
|
const nowDate = now.getDate()
|
||||||
|
|
||||||
const tarYear = nowYear
|
|
||||||
if (dynamicSuffix === 'before') {
|
if (dynamicSuffix === 'before') {
|
||||||
const deffMonth = nowMonth - dynamicPrefix
|
return new Date(nowYear, nowMonth - dynamicPrefix, nowDate).getTime()
|
||||||
const diffYear = Math.floor(deffMonth / 12)
|
|
||||||
|
|
||||||
return new Date(tarYear + diffYear, nowMonth - dynamicPrefix % 12, nowDate).getTime()
|
|
||||||
} else {
|
} else {
|
||||||
const deffMonth = nowMonth + dynamicPrefix
|
return new Date(nowYear, nowMonth + dynamicPrefix, nowDate).getTime()
|
||||||
const diffYear = deffMonth / 12
|
|
||||||
return new Date(tarYear + diffYear, deffMonth % 12, nowDate).getTime()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dynamicInfill === 'year') {
|
if (dynamicInfill === 'year') {
|
||||||
@ -134,5 +132,7 @@ class TimeDateServiceImpl extends WidgetService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const timeDateServiceImpl = new TimeDateServiceImpl({ name: 'timeDateWidget' })
|
const timeDateServiceImpl = new TimeDateServiceImpl({
|
||||||
|
name: 'timeDateWidget'
|
||||||
|
})
|
||||||
export default timeDateServiceImpl
|
export default timeDateServiceImpl
|
||||||
|
@ -11,7 +11,12 @@
|
|||||||
|
|
||||||
<el-form-item v-if="element.options.attrs.default.isDynamic" :label="$t('dynamic_time.relative')">
|
<el-form-item v-if="element.options.attrs.default.isDynamic" :label="$t('dynamic_time.relative')">
|
||||||
|
|
||||||
<el-select v-model="element.options.attrs.default.dkey" placeholder="" class="relative-time" @change="dkeyChange">
|
<el-select
|
||||||
|
v-model="element.options.attrs.default.dkey"
|
||||||
|
placeholder=""
|
||||||
|
class="relative-time"
|
||||||
|
@change="dkeyChange"
|
||||||
|
>
|
||||||
<el-option :label="$t('dynamic_time.today')" :value="0" />
|
<el-option :label="$t('dynamic_time.today')" :value="0" />
|
||||||
<el-option :label="$t('dynamic_time.yesterday')" :value="1" />
|
<el-option :label="$t('dynamic_time.yesterday')" :value="1" />
|
||||||
<el-option :label="$t('dynamic_time.firstOfMonth')" :value="2" />
|
<el-option :label="$t('dynamic_time.firstOfMonth')" :value="2" />
|
||||||
@ -22,12 +27,31 @@
|
|||||||
|
|
||||||
<div class="inline">
|
<div class="inline">
|
||||||
|
|
||||||
<el-form-item v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" label="">
|
<el-form-item
|
||||||
<el-input v-model="element.options.attrs.default.dynamicPrefix" type="number" size="mini" :min="1" :max="12" @input="dynamicPrefixChange" />
|
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3"
|
||||||
|
label=""
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-model="element.options.attrs.default.dynamicPrefix"
|
||||||
|
type="number"
|
||||||
|
size="mini"
|
||||||
|
:min="1"
|
||||||
|
:max="12"
|
||||||
|
@input="dynamicPrefixChange"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" label="" class="no-label-item">
|
<el-form-item
|
||||||
<el-select v-model="element.options.attrs.default.dynamicInfill" size="mini" placeholder="" @change="dynamicInfillChange">
|
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3"
|
||||||
|
label=""
|
||||||
|
class="no-label-item"
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
v-model="element.options.attrs.default.dynamicInfill"
|
||||||
|
size="mini"
|
||||||
|
placeholder=""
|
||||||
|
@change="dynamicInfillChange"
|
||||||
|
>
|
||||||
<el-option :label="$t('dynamic_time.date')" value="day" />
|
<el-option :label="$t('dynamic_time.date')" value="day" />
|
||||||
<el-option :label="$t('dynamic_time.week')" value="week" />
|
<el-option :label="$t('dynamic_time.week')" value="week" />
|
||||||
<el-option :label="$t('dynamic_time.month')" value="month" />
|
<el-option :label="$t('dynamic_time.month')" value="month" />
|
||||||
@ -35,9 +59,18 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" label="" class="no-label-item">
|
<el-form-item
|
||||||
|
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3"
|
||||||
|
label=""
|
||||||
|
class="no-label-item"
|
||||||
|
>
|
||||||
|
|
||||||
<el-select v-model="element.options.attrs.default.dynamicSuffix" size="mini" placeholder="" @change="dynamicSuffixChange">
|
<el-select
|
||||||
|
v-model="element.options.attrs.default.dynamicSuffix"
|
||||||
|
size="mini"
|
||||||
|
placeholder=""
|
||||||
|
@change="dynamicSuffixChange"
|
||||||
|
>
|
||||||
<el-option :label="$t('dynamic_time.before')" value="before" />
|
<el-option :label="$t('dynamic_time.before')" value="before" />
|
||||||
<el-option :label="$t('dynamic_time.after')" value="after" />
|
<el-option :label="$t('dynamic_time.after')" value="after" />
|
||||||
</el-select>
|
</el-select>
|
||||||
@ -46,13 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-form-item v-if="element.options.attrs.default.isDynamic" :label="$t('dynamic_time.preview')">
|
<el-form-item v-if="element.options.attrs.default.isDynamic" :label="$t('dynamic_time.preview')">
|
||||||
<el-date-picker
|
<el-date-picker v-model="dval" type="date" disabled placeholder="" class="relative-time" />
|
||||||
v-model="dval"
|
|
||||||
type="date"
|
|
||||||
disabled
|
|
||||||
placeholder=""
|
|
||||||
class="relative-time"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-else :label="$t('dynamic_time.set')">
|
<el-form-item v-else :label="$t('dynamic_time.set')">
|
||||||
@ -71,7 +98,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ApplicationContext } from '@/utils/ApplicationContext'
|
import {
|
||||||
|
ApplicationContext
|
||||||
|
} from '@/utils/ApplicationContext'
|
||||||
export default {
|
export default {
|
||||||
name: 'DeDateDefault',
|
name: 'DeDateDefault',
|
||||||
props: {
|
props: {
|
||||||
@ -117,22 +146,27 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.inline {
|
.inline {
|
||||||
display: flex;
|
display: flex;
|
||||||
>>>.el-input--mini {
|
|
||||||
min-width: 70px;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.inline{
|
.inline {
|
||||||
.el-form-item {
|
.el-form-item {
|
||||||
margin-bottom: 5px !important;
|
margin-bottom: 5px !important;
|
||||||
|
|
||||||
|
.el-form-item__content>.el-input--mini {
|
||||||
|
min-width: 70px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.relative-time {
|
|
||||||
width: 100%;
|
.relative-time {
|
||||||
}
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -223,21 +223,20 @@ export default {
|
|||||||
.inline-first,
|
.inline-first,
|
||||||
.inline {
|
.inline {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
>>>.el-input--mini {
|
|
||||||
min-width: 70px;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.inline-first {
|
.inline-first {
|
||||||
.el-form-item {
|
.el-form-item {
|
||||||
margin-bottom: 5px !important;
|
margin-bottom: 5px !important;
|
||||||
|
|
||||||
|
.el-form-item__content>.el-input--mini {
|
||||||
|
min-width: 70px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.relative-time {
|
.relative-time {
|
||||||
width: 100%;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user