From 7d9214c2039ee48f9982623ded3e4a1c82dac99a Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 11 Jan 2022 16:30:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B9=B4=E4=BB=BD=E3=80=81=E5=B9=B4?= =?UTF-8?q?=E6=9C=88=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/canvas/utils/utils.js | 27 +++------ .../src/components/widget/DeWidget/DeDate.vue | 19 ++----- .../serviceImpl/TimeDateRangeServiceImpl.js | 3 + .../widget/serviceImpl/TimeDateServiceImpl.js | 21 ++++++- .../serviceImpl/TimeMonthServiceImpl.js | 55 ++++++++++++++++++- .../widget/serviceImpl/TimeYearServiceImpl.js | 51 ++++++++++++++++- frontend/src/lang/en.js | 13 +++++ frontend/src/lang/tw.js | 13 +++++ frontend/src/lang/zh.js | 14 +++++ .../filter/defaultValue/DeDateDefault.vue | 54 +++++++++++++----- .../panel/filter/filterMain/FilterFoot.vue | 12 ++-- 11 files changed, 227 insertions(+), 55 deletions(-) diff --git a/frontend/src/components/canvas/utils/utils.js b/frontend/src/components/canvas/utils/utils.js index d5d4fa84fa..dbc4161bd4 100644 --- a/frontend/src/components/canvas/utils/utils.js +++ b/frontend/src/components/canvas/utils/utils.js @@ -3,6 +3,10 @@ import { HYPERLINKS } from '@/components/canvas/custom-component/component-list' +import { + ApplicationContext +} from '@/utils/ApplicationContext' + export function deepCopy(target) { if (typeof target === 'object') { const result = Array.isArray(target) ? [] : {} @@ -62,25 +66,10 @@ export function mobile2MainCanvas(mainSource, mobileSource) { export function panelInit(componentDatas) { componentDatas.forEach(item => { if (item.component && item.component === 'de-date') { - if (item.serviceName === 'timeDateWidget' && item.options.attrs && !item.options.attrs.default) { - item.options.attrs.default = { - isDynamic: false, - dkey: 0, - 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' + if (item.options.attrs && !item.options.attrs.default) { + const widget = ApplicationContext.getService(item.serviceName) + if (widget && widget.defaultSetting) { + item.options.attrs.default = widget.defaultSetting() } } } diff --git a/frontend/src/components/widget/DeWidget/DeDate.vue b/frontend/src/components/widget/DeWidget/DeDate.vue index 39176372d6..403accd14e 100644 --- a/frontend/src/components/widget/DeWidget/DeDate.vue +++ b/frontend/src/components/widget/DeWidget/DeDate.vue @@ -72,9 +72,7 @@ export default { this.setCondition() }, 'defaultValueStr': function(value, old) { - if ((this.element.serviceName === 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') && - this.element.options.attrs.default.isDynamic) { - // 如果设置了动态时间 不做任何操作 + if (this.element.options.attrs.default.isDynamic) { return } if (value === old) return @@ -82,13 +80,10 @@ export default { this.dateChange(value) }, 'defaultoptions': function(val, old) { - // console.log('default chaneg') - if (this.element.serviceName !== 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') { - if (!this.element.options.attrs.default.isDynamic) { - this.values = this.fillValueDerfault() - this.dateChange(this.values) - return - } + if (!this.element.options.attrs.default.isDynamic) { + this.values = this.fillValueDerfault() + this.dateChange(this.values) + return } if (val === old) return const widget = ApplicationContext.getService(this.element.serviceName) @@ -97,9 +92,7 @@ export default { } }, created() { - if ((this.element.serviceName === 'timeDateWidget' || this.element.serviceName === 'timeDateRangeWidget') && this - .element.options.attrs.default && this.element.options - .attrs.default.isDynamic) { + if (this.element.options.attrs.default && this.element.options.attrs.default.isDynamic) { if (this.element.options.attrs.default) { const widget = ApplicationContext.getService(this.element.serviceName) this.values = widget.dynamicDateFormNow(this.element) diff --git a/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js b/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js index 33ef0d0e05..5e3083c3ee 100644 --- a/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js +++ b/frontend/src/components/widget/serviceImpl/TimeDateRangeServiceImpl.js @@ -80,6 +80,9 @@ class TimeDateRangeServiceImpl extends WidgetService { return field['deType'] === 1 }) } + defaultSetting() { + return dialogPanel.options.attrs.default + } getStartDayOfWeek() { var now = new Date() // 当前日期 var nowDayOfWeek = now.getDay() diff --git a/frontend/src/components/widget/serviceImpl/TimeDateServiceImpl.js b/frontend/src/components/widget/serviceImpl/TimeDateServiceImpl.js index 90c85c6a1b..d7f6725af9 100644 --- a/frontend/src/components/widget/serviceImpl/TimeDateServiceImpl.js +++ b/frontend/src/components/widget/serviceImpl/TimeDateServiceImpl.js @@ -21,7 +21,23 @@ const dialogPanel = { dkey: 0, dynamicPrefix: 1, 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: '' @@ -75,6 +91,9 @@ class TimeDateServiceImpl extends WidgetService { 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 diff --git a/frontend/src/components/widget/serviceImpl/TimeMonthServiceImpl.js b/frontend/src/components/widget/serviceImpl/TimeMonthServiceImpl.js index 45f77dd99d..8a09aafc4f 100644 --- a/frontend/src/components/widget/serviceImpl/TimeMonthServiceImpl.js +++ b/frontend/src/components/widget/serviceImpl/TimeMonthServiceImpl.js @@ -13,7 +13,27 @@ const dialogPanel = { placeholder: 'deyearmonth.placeholder', viewIds: [], 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: '' }, @@ -64,6 +84,39 @@ class TimeMonthServiceImpl extends WidgetService { 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() export default timeMonthServiceImpl diff --git a/frontend/src/components/widget/serviceImpl/TimeYearServiceImpl.js b/frontend/src/components/widget/serviceImpl/TimeYearServiceImpl.js index 2beb3d6935..900b681bcb 100644 --- a/frontend/src/components/widget/serviceImpl/TimeYearServiceImpl.js +++ b/frontend/src/components/widget/serviceImpl/TimeYearServiceImpl.js @@ -13,7 +13,26 @@ const dialogPanel = { placeholder: 'deyear.placeholder', viewIds: [], 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: '' }, @@ -65,6 +84,36 @@ class TimeYearServiceImpl extends WidgetService { 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() export default timeYearServiceImpl diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 94e34aed89..d0c8e5d03a 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1758,5 +1758,18 @@ export default { cmonth: 'This Month', cquarter: 'This Quarter', 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' } } diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index f1f65bab69..e7780a44cd 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1770,5 +1770,18 @@ export default { cmonth: '本月', cquarter: '本季', cyear: '本年' + }, + dynamic_year: { + fix: '固定年份', + dynamic: '動態年份', + current: '當年', + last: '去年' + }, + dynamic_month: { + fix: '固定年月', + dynamic: '動態年月', + current: '本月', + last: '上月', + firstOfYear: '當年首月' } } diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index a9d299de18..0a5a33a417 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1780,5 +1780,19 @@ export default { cmonth: '本月', cquarter: '本季', cyear: '本年' + }, + dynamic_year: { + fix: '固定年份', + dynamic: '动态年份', + current: '当年', + last: '去年' + }, + dynamic_month: { + fix: '固定年月', + dynamic: '动态年月', + current: '当月', + last: '上月', + firstOfYear: '当年首月' } + } diff --git a/frontend/src/views/panel/filter/defaultValue/DeDateDefault.vue b/frontend/src/views/panel/filter/defaultValue/DeDateDefault.vue index 02d0e820af..c83e0ff172 100644 --- a/frontend/src/views/panel/filter/defaultValue/DeDateDefault.vue +++ b/frontend/src/views/panel/filter/defaultValue/DeDateDefault.vue @@ -4,8 +4,14 @@ - {{ $t('dynamic_time.fix') }} - {{ $t('dynamic_time.dynamic') }} + + + {{ $t(item.text) }} + @@ -17,10 +23,13 @@ class="relative-time" @change="dkeyChange" > - - - - + + @@ -28,7 +37,7 @@
@@ -50,17 +59,21 @@ v-model="element.options.attrs.default.dynamicInfill" size="mini" placeholder="" + :disabled="defaultSetting.custom && defaultSetting.custom.unitsOptions && defaultSetting.custom.unitsOptions.length === 1" @change="dynamicInfillChange" > - - - - + + @@ -79,7 +92,13 @@
- + @@ -115,6 +134,13 @@ export default { dval: null } }, + computed: { + defaultSetting() { + const widget = ApplicationContext.getService(this.element.serviceName) + const setting = widget.defaultSetting() + return setting + } + }, created() { this.setDval() }, diff --git a/frontend/src/views/panel/filter/filterMain/FilterFoot.vue b/frontend/src/views/panel/filter/filterMain/FilterFoot.vue index 19a04ccfc0..e95451761c 100644 --- a/frontend/src/views/panel/filter/filterMain/FilterFoot.vue +++ b/frontend/src/views/panel/filter/filterMain/FilterFoot.vue @@ -3,11 +3,11 @@
- 默认值设置 + {{ $t('dynamic_time.set_default') }}
- - + + - +