Merge pull request #9299 from dataease/pr@dev@feat_linkage-time

feat(图表): 图表支持时间字段联动
This commit is contained in:
王嘉豪 2024-04-24 14:24:28 +08:00 committed by GitHub
commit 77e973191a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 82 additions and 3 deletions

View File

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

View File

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

View File

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