de/frontend/src/views/chart/components/dragItem/utils.js
2022-12-08 10:12:47 +08:00

84 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function getItemType(dimensionData, quotaData, item) {
// Check whether the current view is in template status
// ( dimensionData and quotaData have no data). If yes, return 'success' directly
if (dimensionData.length === 0 && quotaData.length === 0) {
return 'success'
}
// 将item的字段在数据集维度、指标字段中查询一遍如果遇到id不存在、字段类型不一致、维度指标不一致则提示
const status = item.groupType
let checked = false
if (status === 'd') {
for (let i = 0; i < dimensionData.length; i++) {
const ele = dimensionData[i]
if (item.chartId) {
if (ele.dataeaseName === item.dataeaseName && ele.deType === item.deType && ele.groupType === item.groupType) {
checked = true
break
}
} else {
if (ele.id === item.id && ele.deType === item.deType && ele.groupType === item.groupType) {
checked = true
break
}
}
}
}
if (status === 'q') {
for (let i = 0; i < quotaData.length; i++) {
const ele = quotaData[i]
if (item.chartId) {
if (ele.dataeaseName === item.dataeaseName && ele.deType === item.deType && ele.groupType === item.groupType) {
checked = true
break
}
} else {
if (ele.id === item.id && ele.deType === item.deType && ele.groupType === item.groupType) {
checked = true
break
}
}
}
}
if (checked) {
if (status === 'd') {
return ''
} else if (status === 'q') {
return 'success'
}
} else {
return 'danger'
}
}
export function getOriginFieldName(dimensionList, quotaList, field) {
let originName = ''
for (let i = 0; i < dimensionList.length; i++) {
const item = dimensionList[i]
if (item.id === field.id) {
originName = item.name
break
}
}
for (let i = 0; i < quotaList.length; i++) {
const item = quotaList[i]
if (item.id === field.id) {
originName = item.name
break
}
}
return originName
}
export function resetValueFormatter(item) {
if (item) {
item.formatterCfg = {
type: 'auto', // auto,value,percent
unit: 1, // 换算单位
suffix: '', // 单位后缀
decimalCount: 2, // 小数位数
thousandSeparator: true// 千分符
}
}
}