Merge pull request #10376 from dataease/pr@dev-v2@feat_linkage-time2
feat(仪表板): 联动支持根据时间点转为时间区间进行联动
This commit is contained in:
commit
2eaec8ee5a
@ -85,9 +85,6 @@ export const copyStore = defineStore('copy', {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const dataArray = this.copyData.data
|
const dataArray = this.copyData.data
|
||||||
|
|
||||||
console.log('past=' + JSON.stringify(dataArray))
|
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
const copyDataTemp = this.copyData
|
const copyDataTemp = this.copyData
|
||||||
const moveTime = dataArray.length > 1 ? 300 : 10
|
const moveTime = dataArray.length > 1 ? 300 : 10
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
findBaseDeFaultAttr
|
findBaseDeFaultAttr
|
||||||
} from '@/custom-component/component-list'
|
} from '@/custom-component/component-list'
|
||||||
import { get, set } from 'lodash-es'
|
import { get, set } from 'lodash-es'
|
||||||
|
import { viewFieldTimeTrans } from '@/utils/viewUtils'
|
||||||
|
|
||||||
export const dvMainStore = defineStore('dataVisualization', {
|
export const dvMainStore = defineStore('dataVisualization', {
|
||||||
state: () => {
|
state: () => {
|
||||||
@ -845,6 +846,8 @@ export const dvMainStore = defineStore('dataVisualization', {
|
|||||||
addViewTrackFilter(data) {
|
addViewTrackFilter(data) {
|
||||||
const viewId = data.viewId
|
const viewId = data.viewId
|
||||||
let trackInfo
|
let trackInfo
|
||||||
|
// 维度日期类型转换
|
||||||
|
viewFieldTimeTrans(this.canvasViewDataInfo[viewId], data)
|
||||||
if (data.option === 'linkage') {
|
if (data.option === 'linkage') {
|
||||||
trackInfo = this.nowPanelTrackInfo
|
trackInfo = this.nowPanelTrackInfo
|
||||||
} else {
|
} else {
|
||||||
@ -1006,12 +1009,24 @@ export const dvMainStore = defineStore('dataVisualization', {
|
|||||||
if (element.component === 'UserView' && element.id === targetViewId) {
|
if (element.component === 'UserView' && element.id === targetViewId) {
|
||||||
// 如果目标图表 和 当前循环组件id相等 则进行条件增减
|
// 如果目标图表 和 当前循环组件id相等 则进行条件增减
|
||||||
const targetFieldId = targetInfoArray[1] // 目标图表列ID
|
const targetFieldId = targetInfoArray[1] // 目标图表列ID
|
||||||
const condition = {
|
let condition
|
||||||
fieldId: targetFieldId,
|
if (QDItem.timeValue && Array.isArray(QDItem.timeValue)) {
|
||||||
operator: 'eq',
|
// 如果dimension.timeValue存在值且是数组 目前判断为是时间组件
|
||||||
value: [QDItem.value],
|
condition = {
|
||||||
viewIds: [targetViewId],
|
fieldId: targetFieldId,
|
||||||
sourceViewId: viewId
|
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
|
let j = currentFilters.length
|
||||||
while (j--) {
|
while (j--) {
|
||||||
|
|||||||
109
core/core-frontend/src/utils/timeUitils.ts
Normal file
109
core/core-frontend/src/utils/timeUitils.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
28
core/core-frontend/src/utils/viewUtils.ts
Normal file
28
core/core-frontend/src/utils/viewUtils.ts
Normal 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])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -469,7 +469,7 @@ const calcData = params => {
|
|||||||
dvMainStore.setLastViewRequestInfo(params.id, params.chartExtRequest)
|
dvMainStore.setLastViewRequestInfo(params.id, params.chartExtRequest)
|
||||||
if (chartComponent?.value) {
|
if (chartComponent?.value) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
chartComponent?.value?.calcData?.(params, () => {
|
chartComponent?.value?.calcData?.(params, res => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user