Merge pull request #10376 from dataease/pr@dev-v2@feat_linkage-time2

feat(仪表板): 联动支持根据时间点转为时间区间进行联动
This commit is contained in:
王嘉豪 2024-06-19 15:49:50 +08:00 committed by GitHub
commit 2eaec8ee5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 159 additions and 10 deletions

View File

@ -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

View File

@ -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--) {

View File

@ -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
}
}

View File

@ -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])
}
})
}
}

View File

@ -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
})
}