diff --git a/core/core-frontend/src/store/modules/data-visualization/copy.ts b/core/core-frontend/src/store/modules/data-visualization/copy.ts index f4d984b12a..c8c3ed4aaa 100644 --- a/core/core-frontend/src/store/modules/data-visualization/copy.ts +++ b/core/core-frontend/src/store/modules/data-visualization/copy.ts @@ -85,9 +85,6 @@ export const copyStore = defineStore('copy', { return } const dataArray = this.copyData.data - - console.log('past=' + JSON.stringify(dataArray)) - let i = 0 const copyDataTemp = this.copyData const moveTime = dataArray.length > 1 ? 300 : 10 diff --git a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts index 652178e9bd..6b223fbcd0 100644 --- a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts +++ b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts @@ -20,6 +20,7 @@ import { findBaseDeFaultAttr } from '@/custom-component/component-list' import { get, set } from 'lodash-es' +import { viewFieldTimeTrans } from '@/utils/viewUtils' export const dvMainStore = defineStore('dataVisualization', { state: () => { @@ -845,6 +846,8 @@ export const dvMainStore = defineStore('dataVisualization', { addViewTrackFilter(data) { const viewId = data.viewId let trackInfo + // 维度日期类型转换 + viewFieldTimeTrans(this.canvasViewDataInfo[viewId], data) if (data.option === 'linkage') { trackInfo = this.nowPanelTrackInfo } else { @@ -1006,12 +1009,24 @@ export const dvMainStore = defineStore('dataVisualization', { if (element.component === 'UserView' && element.id === targetViewId) { // 如果目标图表 和 当前循环组件id相等 则进行条件增减 const targetFieldId = targetInfoArray[1] // 目标图表列ID - const condition = { - fieldId: targetFieldId, - operator: 'eq', - value: [QDItem.value], - viewIds: [targetViewId], - sourceViewId: viewId + let condition + if (QDItem.timeValue && Array.isArray(QDItem.timeValue)) { + // 如果dimension.timeValue存在值且是数组 目前判断为是时间组件 + condition = { + fieldId: targetFieldId, + operator: 'between', + value: QDItem.timeValue, + viewIds: [targetViewId], + sourceViewId: viewId + } + } else { + condition = { + fieldId: targetFieldId, + operator: 'eq', + value: [QDItem.value], + viewIds: [targetViewId], + sourceViewId: viewId + } } let j = currentFilters.length while (j--) { diff --git a/core/core-frontend/src/utils/timeUitils.ts b/core/core-frontend/src/utils/timeUitils.ts new file mode 100644 index 0000000000..1acf5a2732 --- /dev/null +++ b/core/core-frontend/src/utils/timeUitils.ts @@ -0,0 +1,109 @@ +export const getRange = (outerTimeValue, timeGranularity) => { + const selectValue = timeGranularity === 'y_M_d_H' ? outerTimeValue + ':' : outerTimeValue + if (new Date(selectValue).toString() === 'Invalid Date') { + return selectValue + } + 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 'y_M_d_H_m_s': + return getSecondEnd(selectValue) + case 'datetime': + return [+new Date(selectValue), +new Date(selectValue)] + default: + return selectValue + } +} + +export const getTimeBegin = (selectValue, timeGranularity) => { + switch (timeGranularity) { + case 'year': + return getYearEnd(selectValue) + case 'month': + return getMonthEnd(selectValue) + case 'date': + return getDayEnd(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 => { + const utcTime = getUtcTime(timestamp) + return [+utcTime, +utcTime + 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] +} + +const getSecondEnd = timestamp => { + return [+new Date(timestamp), +new Date(timestamp) + 999] +} + +const getYearBegin = timestamp => { + const time = new Date(timestamp) + return +new Date(time.getFullYear(), 0, 1) +} + +const getMonthBegin = 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) +} + +const getDayBegin = timestamp => { + return +new Date(timestamp) +} + +const getUtcTime = timestamp => { + if (timestamp) { + const time = new Date(timestamp) + const utcDate = new Date( + time.getUTCFullYear(), + time.getUTCMonth(), + time.getUTCDate(), + time.getUTCHours(), + time.getUTCMinutes(), + time.getUTCSeconds() + ) + return utcDate + } else { + return timestamp + } +} diff --git a/core/core-frontend/src/utils/viewUtils.ts b/core/core-frontend/src/utils/viewUtils.ts new file mode 100644 index 0000000000..7dde471796 --- /dev/null +++ b/core/core-frontend/src/utils/viewUtils.ts @@ -0,0 +1,28 @@ +import { getRange } from '@/utils/timeUitils' + +export function viewFieldTimeTrans(viewDataInfo, params) { + if (viewDataInfo && params && params.dimensionList) { + const idNameMap = viewDataInfo.fields.reduce((pre, next) => { + pre[next['id']] = next['dataeaseName'] + return pre + }, {}) + + const nameTypeMap = viewDataInfo.fields.reduce((pre, next) => { + pre[next['dataeaseName']] = next['deType'] + return pre + }, {}) + + const nameDateStyleMap = viewDataInfo.fields.reduce((pre, next) => { + pre[next['dataeaseName']] = next['dateStyle'] + return pre + }, {}) + + params.dimensionList.forEach(dimension => { + const dataeaseName = idNameMap[dimension.id] + // deType === 1 表示是时间类型 + if (nameTypeMap[dataeaseName] === 1) { + dimension['timeValue'] = getRange(dimension.value, nameDateStyleMap[dataeaseName]) + } + }) + } +} diff --git a/core/core-frontend/src/views/chart/components/views/index.vue b/core/core-frontend/src/views/chart/components/views/index.vue index 04482459a4..26e90401be 100644 --- a/core/core-frontend/src/views/chart/components/views/index.vue +++ b/core/core-frontend/src/views/chart/components/views/index.vue @@ -469,7 +469,7 @@ const calcData = params => { dvMainStore.setLastViewRequestInfo(params.id, params.chartExtRequest) if (chartComponent?.value) { loading.value = true - chartComponent?.value?.calcData?.(params, () => { + chartComponent?.value?.calcData?.(params, res => { loading.value = false }) }