提交 7d9214c2 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 年份、年月组件增加动态时间

上级 7c75816e
...@@ -3,6 +3,10 @@ import { ...@@ -3,6 +3,10 @@ import {
HYPERLINKS HYPERLINKS
} from '@/components/canvas/custom-component/component-list' } from '@/components/canvas/custom-component/component-list'
import {
ApplicationContext
} from '@/utils/ApplicationContext'
export function deepCopy(target) { export function deepCopy(target) {
if (typeof target === 'object') { if (typeof target === 'object') {
const result = Array.isArray(target) ? [] : {} const result = Array.isArray(target) ? [] : {}
...@@ -62,25 +66,10 @@ export function mobile2MainCanvas(mainSource, mobileSource) { ...@@ -62,25 +66,10 @@ export function mobile2MainCanvas(mainSource, mobileSource) {
export function panelInit(componentDatas) { export function panelInit(componentDatas) {
componentDatas.forEach(item => { componentDatas.forEach(item => {
if (item.component && item.component === 'de-date') { if (item.component && item.component === 'de-date') {
if (item.serviceName === 'timeDateWidget' && item.options.attrs && !item.options.attrs.default) { if (item.options.attrs && !item.options.attrs.default) {
item.options.attrs.default = { const widget = ApplicationContext.getService(item.serviceName)
isDynamic: false, if (widget && widget.defaultSetting) {
dkey: 0, item.options.attrs.default = widget.defaultSetting()
dynamicPrefix: 1,
dynamicInfill: 'day',
dynamicSuffix: 'before'
}
}
if (item.serviceName === 'timeDateRangeWidget' && item.options.attrs && !item.options.attrs.default) {
item.options.attrs.default = {
isDynamic: false,
dkey: 0,
sDynamicPrefix: 1,
sDynamicInfill: 'day',
sDynamicSuffix: 'before',
eDynamicPrefix: 1,
eDynamicInfill: 'day',
eDynamicSuffix: 'after'
} }
} }
} }
......
...@@ -72,9 +72,7 @@ export default { ...@@ -72,9 +72,7 @@ export default {
this.setCondition() this.setCondition()
}, },
'defaultValueStr': function(value, old) { 'defaultValueStr': function(value, old) {
if ((this.element.serviceName === 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') && if (this.element.options.attrs.default.isDynamic) {
this.element.options.attrs.default.isDynamic) {
// 如果设置了动态时间 不做任何操作
return return
} }
if (value === old) return if (value === old) return
...@@ -82,13 +80,10 @@ export default { ...@@ -82,13 +80,10 @@ export default {
this.dateChange(value) this.dateChange(value)
}, },
'defaultoptions': function(val, old) { 'defaultoptions': function(val, old) {
// console.log('default chaneg') if (!this.element.options.attrs.default.isDynamic) {
if (this.element.serviceName !== 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') { this.values = this.fillValueDerfault()
if (!this.element.options.attrs.default.isDynamic) { this.dateChange(this.values)
this.values = this.fillValueDerfault() return
this.dateChange(this.values)
return
}
} }
if (val === old) return if (val === old) return
const widget = ApplicationContext.getService(this.element.serviceName) const widget = ApplicationContext.getService(this.element.serviceName)
...@@ -97,9 +92,7 @@ export default { ...@@ -97,9 +92,7 @@ export default {
} }
}, },
created() { created() {
if ((this.element.serviceName === 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') && this if (this.element.options.attrs.default && this.element.options.attrs.default.isDynamic) {
.element.options.attrs.default && this.element.options
.attrs.default.isDynamic) {
if (this.element.options.attrs.default) { if (this.element.options.attrs.default) {
const widget = ApplicationContext.getService(this.element.serviceName) const widget = ApplicationContext.getService(this.element.serviceName)
this.values = widget.dynamicDateFormNow(this.element) this.values = widget.dynamicDateFormNow(this.element)
......
...@@ -80,6 +80,9 @@ class TimeDateRangeServiceImpl extends WidgetService { ...@@ -80,6 +80,9 @@ class TimeDateRangeServiceImpl extends WidgetService {
return field['deType'] === 1 return field['deType'] === 1
}) })
} }
defaultSetting() {
return dialogPanel.options.attrs.default
}
getStartDayOfWeek() { getStartDayOfWeek() {
var now = new Date() // 当前日期 var now = new Date() // 当前日期
var nowDayOfWeek = now.getDay() var nowDayOfWeek = now.getDay()
......
...@@ -21,7 +21,23 @@ const dialogPanel = { ...@@ -21,7 +21,23 @@ const dialogPanel = {
dkey: 0, dkey: 0,
dynamicPrefix: 1, dynamicPrefix: 1,
dynamicInfill: 'day', dynamicInfill: 'day',
dynamicSuffix: 'before' dynamicSuffix: 'before',
radioOptions: [{ value: false, text: 'dynamic_time.fix' }, { value: true, text: 'dynamic_time.dynamic' }],
relativeOptions: [
{ value: 0, text: 'dynamic_time.today' },
{ value: 1, text: 'dynamic_time.yesterday' },
{ value: 2, text: 'dynamic_time.firstOfMonth' },
{ value: 3, text: 'dynamic_time.custom' }
],
custom: {
unitsOptions: [
{ value: 'day', text: 'dynamic_time.date' },
{ value: 'week', text: 'dynamic_time.week' },
{ value: 'month', text: 'dynamic_time.month' },
{ value: 'year', text: 'dynamic_time.year' }
],
limits: [1, 12]
}
} }
}, },
value: '' value: ''
...@@ -75,6 +91,9 @@ class TimeDateServiceImpl extends WidgetService { ...@@ -75,6 +91,9 @@ class TimeDateServiceImpl extends WidgetService {
return field['deType'] === 1 return field['deType'] === 1
}) })
} }
defaultSetting() {
return dialogPanel.options.attrs.default
}
dynamicDateFormNow(element) { dynamicDateFormNow(element) {
if (element.options.attrs.default === null || typeof element.options.attrs.default === 'undefined' || !element.options.attrs.default.isDynamic) return null if (element.options.attrs.default === null || typeof element.options.attrs.default === 'undefined' || !element.options.attrs.default.isDynamic) return null
......
...@@ -13,7 +13,27 @@ const dialogPanel = { ...@@ -13,7 +13,27 @@ const dialogPanel = {
placeholder: 'deyearmonth.placeholder', placeholder: 'deyearmonth.placeholder',
viewIds: [], viewIds: [],
fieldId: '', fieldId: '',
dragItems: [] dragItems: [],
default: {
isDynamic: false,
dkey: 0,
dynamicPrefix: 1,
dynamicInfill: 'month',
dynamicSuffix: 'before',
radioOptions: [{ value: false, text: 'dynamic_month.fix' }, { value: true, text: 'dynamic_month.dynamic' }],
relativeOptions: [
{ value: 0, text: 'dynamic_month.current' },
{ value: 1, text: 'dynamic_month.last' },
{ value: 2, text: 'dynamic_month.firstOfYear' },
{ value: 3, text: 'dynamic_time.custom' }
],
custom: {
unitsOptions: [
{ value: 'month', text: 'dynamic_time.month' }
],
limits: [0, 10]
}
}
}, },
value: '' value: ''
}, },
...@@ -64,6 +84,39 @@ class TimeMonthServiceImpl extends WidgetService { ...@@ -64,6 +84,39 @@ class TimeMonthServiceImpl extends WidgetService {
return field['deType'] === 1 return field['deType'] === 1
}) })
} }
defaultSetting() {
return dialogPanel.options.attrs.default
}
dynamicDateFormNow(element) {
const now = new Date()
const nowMonth = now.getMonth()
const nowYear = now.getFullYear()
const nowDate = now.getDate()
if (element.options.attrs.default === null || typeof element.options.attrs.default === 'undefined' || !element.options.attrs.default.isDynamic) return null
if (element.options.attrs.default.dkey === 0) {
return Date.now()
}
if (element.options.attrs.default.dkey === 1) {
return new Date(nowYear, nowMonth - 1, nowDate).getTime()
}
if (element.options.attrs.default.dkey === 2) {
return new Date(nowYear, 0, 1).getTime()
}
if (element.options.attrs.default.dkey === 3) {
const dynamicPrefix = parseInt(element.options.attrs.default.dynamicPrefix)
const dynamicSuffix = element.options.attrs.default.dynamicSuffix
if (dynamicSuffix === 'before') {
return new Date(nowYear, nowMonth - dynamicPrefix, nowDate).getTime()
} else {
return new Date(nowYear, nowMonth + dynamicPrefix, nowDate).getTime()
}
}
}
} }
const timeMonthServiceImpl = new TimeMonthServiceImpl() const timeMonthServiceImpl = new TimeMonthServiceImpl()
export default timeMonthServiceImpl export default timeMonthServiceImpl
...@@ -13,7 +13,26 @@ const dialogPanel = { ...@@ -13,7 +13,26 @@ const dialogPanel = {
placeholder: 'deyear.placeholder', placeholder: 'deyear.placeholder',
viewIds: [], viewIds: [],
fieldId: '', fieldId: '',
dragItems: [] dragItems: [],
default: {
isDynamic: false,
dkey: 0,
dynamicPrefix: 1,
dynamicInfill: 'year',
dynamicSuffix: 'before',
radioOptions: [{ value: false, text: 'dynamic_year.fix' }, { value: true, text: 'dynamic_year.dynamic' }],
relativeOptions: [
{ value: 0, text: 'dynamic_year.current' },
{ value: 1, text: 'dynamic_year.last' },
{ value: 2, text: 'dynamic_time.custom' }
],
custom: {
unitsOptions: [
{ value: 'year', text: 'dynamic_time.year' }
],
limits: [0, 10]
}
}
}, },
value: '' value: ''
}, },
...@@ -65,6 +84,36 @@ class TimeYearServiceImpl extends WidgetService { ...@@ -65,6 +84,36 @@ class TimeYearServiceImpl extends WidgetService {
return field['deType'] === 1 return field['deType'] === 1
}) })
} }
defaultSetting() {
return dialogPanel.options.attrs.default
}
dynamicDateFormNow(element) {
if (element.options.attrs.default === null || typeof element.options.attrs.default === 'undefined' || !element.options.attrs.default.isDynamic) return null
if (element.options.attrs.default.dkey === 0) {
return Date.now()
}
if (element.options.attrs.default.dkey === 1) {
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth()
const nowDate = now.getDate()
return new Date(nowYear - 1, nowMonth, nowDate).getTime()
}
if (element.options.attrs.default.dkey === 2) {
const dynamicPrefix = parseInt(element.options.attrs.default.dynamicPrefix)
const dynamicSuffix = element.options.attrs.default.dynamicSuffix
const now = new Date()
const nowMonth = now.getMonth()
const nowYear = now.getFullYear()
const nowDate = now.getDate()
return new Date(dynamicSuffix === 'before' ? (nowYear - dynamicPrefix) : (nowYear + dynamicPrefix), nowMonth, nowDate).getTime()
}
}
} }
const timeYearServiceImpl = new TimeYearServiceImpl() const timeYearServiceImpl = new TimeYearServiceImpl()
export default timeYearServiceImpl export default timeYearServiceImpl
...@@ -1758,5 +1758,18 @@ export default { ...@@ -1758,5 +1758,18 @@ export default {
cmonth: 'This Month', cmonth: 'This Month',
cquarter: 'This Quarter', cquarter: 'This Quarter',
cyear: 'This Year' cyear: 'This Year'
},
dynamic_year: {
fix: 'Fixed Year',
dynamic: 'Dynamic Year',
current: 'This Year',
last: 'Last Year'
},
dynamic_month: {
fix: 'Fixed Month',
dynamic: 'Dynamic Month',
current: 'This Month',
last: 'Last Month',
firstOfYear: 'First month of this year'
} }
} }
...@@ -1770,5 +1770,18 @@ export default { ...@@ -1770,5 +1770,18 @@ export default {
cmonth: '本月', cmonth: '本月',
cquarter: '本季', cquarter: '本季',
cyear: '本年' cyear: '本年'
},
dynamic_year: {
fix: '固定年份',
dynamic: '動態年份',
current: '當年',
last: '去年'
},
dynamic_month: {
fix: '固定年月',
dynamic: '動態年月',
current: '本月',
last: '上月',
firstOfYear: '當年首月'
} }
} }
...@@ -1780,5 +1780,19 @@ export default { ...@@ -1780,5 +1780,19 @@ export default {
cmonth: '本月', cmonth: '本月',
cquarter: '本季', cquarter: '本季',
cyear: '本年' cyear: '本年'
},
dynamic_year: {
fix: '固定年份',
dynamic: '动态年份',
current: '当年',
last: '去年'
},
dynamic_month: {
fix: '固定年月',
dynamic: '动态年月',
current: '当月',
last: '上月',
firstOfYear: '当年首月'
} }
} }
...@@ -4,8 +4,14 @@ ...@@ -4,8 +4,14 @@
<el-form-item :label="$t('dynamic_time.set_default')"> <el-form-item :label="$t('dynamic_time.set_default')">
<el-radio-group v-model="element.options.attrs.default.isDynamic" @change="dynamicChange"> <el-radio-group v-model="element.options.attrs.default.isDynamic" @change="dynamicChange">
<el-radio :label="false">{{ $t('dynamic_time.fix') }}</el-radio>
<el-radio :label="true">{{ $t('dynamic_time.dynamic') }}</el-radio> <el-radio
v-for="(item, index) in defaultSetting.radioOptions"
:key="index"
:label="item.value"
>
{{ $t(item.text) }}
</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
...@@ -17,10 +23,13 @@ ...@@ -17,10 +23,13 @@
class="relative-time" class="relative-time"
@change="dkeyChange" @change="dkeyChange"
> >
<el-option :label="$t('dynamic_time.today')" :value="0" /> <el-option
<el-option :label="$t('dynamic_time.yesterday')" :value="1" /> v-for="(item, index) in defaultSetting.relativeOptions"
<el-option :label="$t('dynamic_time.firstOfMonth')" :value="2" /> :key="item.value + index"
<el-option :label="$t('dynamic_time.custom')" :value="3" /> :label="$t(item.text)"
:value="item.value"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
...@@ -28,7 +37,7 @@ ...@@ -28,7 +37,7 @@
<div class="inline"> <div class="inline">
<el-form-item <el-form-item
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === (defaultSetting.relativeOptions.length - 1)"
label="" label=""
> >
<el-input <el-input
...@@ -42,7 +51,7 @@ ...@@ -42,7 +51,7 @@
</el-form-item> </el-form-item>
<el-form-item <el-form-item
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === (defaultSetting.relativeOptions.length - 1)"
label="" label=""
class="no-label-item" class="no-label-item"
> >
...@@ -50,17 +59,21 @@ ...@@ -50,17 +59,21 @@
v-model="element.options.attrs.default.dynamicInfill" v-model="element.options.attrs.default.dynamicInfill"
size="mini" size="mini"
placeholder="" placeholder=""
:disabled="defaultSetting.custom && defaultSetting.custom.unitsOptions && defaultSetting.custom.unitsOptions.length === 1"
@change="dynamicInfillChange" @change="dynamicInfillChange"
> >
<el-option :label="$t('dynamic_time.date')" value="day" /> <el-option
<el-option :label="$t('dynamic_time.week')" value="week" /> v-for="(item, index) in defaultSetting.custom.unitsOptions"
<el-option :label="$t('dynamic_time.month')" value="month" /> :key="item.value + index"
<el-option :label="$t('dynamic_time.year')" value="year" /> :label="$t(item.text)"
:value="item.value"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item
v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === 3" v-if="element.options.attrs.default.isDynamic && element.options.attrs.default.dkey === (defaultSetting.relativeOptions.length - 1)"
label="" label=""
class="no-label-item" class="no-label-item"
> >
...@@ -79,7 +92,13 @@ ...@@ -79,7 +92,13 @@
</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 v-model="dval" type="date" disabled placeholder="" class="relative-time" /> <el-date-picker
v-model="dval"
:type="element.options.attrs.type"
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')">
...@@ -115,6 +134,13 @@ export default { ...@@ -115,6 +134,13 @@ export default {
dval: null dval: null
} }
}, },
computed: {
defaultSetting() {
const widget = ApplicationContext.getService(this.element.serviceName)
const setting = widget.defaultSetting()
return setting
}
},
created() { created() {
this.setDval() this.setDval()
}, },
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<el-col :span="24"> <el-col :span="24">
<div class="filter-content"> <div class="filter-content">
<el-card <el-card
v-if="element.serviceName && element.serviceName !== 'timeDateWidget' && element.serviceName !== 'timeDateRangeWidget'" v-if="element.component && element.component !== 'de-date'"
class="box-card" class="box-card"
> >
<div style="margin-bottom: 10px;"> <div style="margin-bottom: 10px;">
<span>默认值设置</span> <span>{{ $t('dynamic_time.set_default') }}</span>
</div> </div>
<div class="custom-component-class"> <div class="custom-component-class">
<component <component
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
</el-card> </el-card>
<el-card v-if="element.serviceName && element.serviceName === 'timeDateWidget'" class="box-card"> <el-card v-if="element.component && element.component === 'de-date' && element.serviceName && element.serviceName !== 'timeDateRangeWidget'" class="box-card">
<de-date-default v-if="element.serviceName && element.serviceName === 'timeDateWidget'" :element="element" /> <de-date-default v-if="element.component === 'de-date' && element.serviceName !== 'timeDateRangeWidget'" :element="element" />
</el-card> </el-card>
<el-card v-if="element.serviceName && element.serviceName === 'timeDateRangeWidget'" class="box-card"> <el-card v-if="element.component && element.component === 'de-date' && element.serviceName && element.serviceName === 'timeDateRangeWidget'" class="box-card">
<de-date-range-default <de-date-range-default
v-if="element.serviceName && element.serviceName === 'timeDateRangeWidget'" v-if="element.component === 'de-date' && element.serviceName === 'timeDateRangeWidget'"
:element="element" :element="element"
/> />
</el-card> </el-card>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论