From 99715c27fc6713e8d0ca14f2f28f0d7d8ccee057 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 24 Apr 2024 14:16:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E8=A1=A8):=20=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=97=B6=E9=97=B4=E5=AD=97=E6=AE=B5=E8=81=94?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/frontend/src/store/index.js | 16 +++++- core/frontend/src/utils/timeUitils.js | 52 +++++++++++++++++++ .../chart/components/ChartComponentS2.vue | 17 +++++- 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 core/frontend/src/utils/timeUitils.js diff --git a/core/frontend/src/store/index.js b/core/frontend/src/store/index.js index e2a6bcd487..dcc237eb76 100644 --- a/core/frontend/src/store/index.js +++ b/core/frontend/src/store/index.js @@ -410,7 +410,13 @@ const data = { const targetViewId = targetInfoArray[0] // 目标视图 if (ele.propValue.viewId === targetViewId) { // 如果目标视图 和 当前循环组件id相等 则进行条件增减 const targetFieldId = targetInfoArray[1] // 目标视图列ID - const condition = new Condition('', targetFieldId, 'eq', [dimension.value], [targetViewId]) + let condition + if (Array.isArray(dimension.value)) { + // 如果dimension.value是数组 目前判断为是时间组件 + condition = new Condition('', targetFieldId, 'between', dimension.value, [targetViewId]) + } else { + condition = new Condition('', targetFieldId, 'eq', [dimension.value], [targetViewId]) + } condition.sourceViewId = viewId let j = currentFilters.length while (j--) { @@ -445,7 +451,13 @@ const data = { const targetViewId = targetInfoArray[0] // 目标视图 if (element.type === 'view' && element.propValue.viewId === targetViewId) { // 如果目标视图 和 当前循环组件id相等 则进行条件增减 const targetFieldId = targetInfoArray[1] // 目标视图列ID - const condition = new Condition('', targetFieldId, 'eq', [dimension.value], [targetViewId]) + let condition + if (Array.isArray(dimension.value)) { + // 如果dimension.value是数组 目前判断为是时间组件 + condition = new Condition('', targetFieldId, 'between', dimension.value, [targetViewId]) + } else { + condition = new Condition('', targetFieldId, 'eq', [dimension.value], [targetViewId]) + } condition.sourceViewId = viewId let j = currentFilters.length while (j--) { diff --git a/core/frontend/src/utils/timeUitils.js b/core/frontend/src/utils/timeUitils.js new file mode 100644 index 0000000000..1e28837e2f --- /dev/null +++ b/core/frontend/src/utils/timeUitils.js @@ -0,0 +1,52 @@ +export const getRange = (selectValue, timeGranularity) => { + switch (timeGranularity) { + case 'year': + case 'y': + return getYearEnd(selectValue) + case 'month': + case 'y_M': + return getMonthEnd(selectValue) + case 'date': + case 'y_M_d': + return getDayEnd(selectValue) + case 'hour': + case 'y_M_d_H': + return getHourEnd(selectValue) + case 'minute': + case 'y_M_d_H_m': + return getMinuteEnd(selectValue) + case 'datetime': + return [+new Date(selectValue), +new Date(selectValue)] + default: + return selectValue + } +} + +const getYearEnd = timestamp => { + const time = new Date(timestamp) + return [ + +new Date(time.getFullYear(), 0, 1), + +new Date(time.getFullYear(), 11, 31) + 60 * 1000 * 60 * 24 - 1000 + ] +} + +const getMonthEnd = timestamp => { + const time = new Date(timestamp) + const date = new Date(time.getFullYear(), time.getMonth(), 1) + date.setDate(1) + date.setMonth(date.getMonth() + 1) + return [+new Date(time.getFullYear(), time.getMonth(), 1), +new Date(date.getTime() - 1000)] +} + +const getDayEnd = timestamp => { + return [+new Date(timestamp), +new Date(timestamp) + 60 * 1000 * 60 * 24 - 1000] +} + +const getHourEnd = timestamp => { + return [+new Date(timestamp), +new Date(timestamp) + 60 * 1000 * 60 - 1000] +} + +const getMinuteEnd = timestamp => { + return [+new Date(timestamp), +new Date(timestamp) + 60 * 1000 - 1000] +} + diff --git a/core/frontend/src/views/chart/components/ChartComponentS2.vue b/core/frontend/src/views/chart/components/ChartComponentS2.vue index 40818d5376..5ea2806826 100644 --- a/core/frontend/src/views/chart/components/ChartComponentS2.vue +++ b/core/frontend/src/views/chart/components/ChartComponentS2.vue @@ -103,6 +103,7 @@ import ChartTitleUpdate from './ChartTitleUpdate.vue' import { mapState } from 'vuex' import DePagination from '@/components/deCustomCm/pagination.js' import bus from '@/utils/bus' +import { getRange } from '@/utils/timeUitils' export default { name: 'ChartComponentS2', @@ -326,6 +327,15 @@ export default { pre[next['dataeaseName']] = next['id'] return pre }, {}) + const nameTypeMap = this.chart.data.fields.reduce((pre, next) => { + pre[next['dataeaseName']] = next['deType'] + return pre + }, {}) + + const nameDateStyleMap = this.chart.data.fields.reduce((pre, next) => { + pre[next['dataeaseName']] = next['dateStyle'] + return pre + }, {}) let rowData if (this.chart.type === 'table-pivot') { @@ -337,7 +347,12 @@ export default { const dimensionList = [] for (const key in rowData) { if (nameIdMap[key]) { - dimensionList.push({ id: nameIdMap[key], value: rowData[key] }) + let value = rowData[key] + // deType === 1 表示是时间类型 + if (nameTypeMap[key] === 1) { + value = getRange(value, nameDateStyleMap[key]) + } + dimensionList.push({ id: nameIdMap[key], value: value }) } } this.antVActionPost(dimensionList, nameIdMap[meta.valueField] || 'null', param)