forked from github/dataease
Merge pull request #9299 from dataease/pr@dev@feat_linkage-time
feat(图表): 图表支持时间字段联动
This commit is contained in:
commit
77e973191a
@ -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--) {
|
||||
|
52
core/frontend/src/utils/timeUitils.js
Normal file
52
core/frontend/src/utils/timeUitils.js
Normal 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]
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user