NEZ-2429 feat:dashboard chart repeat显示优化

This commit is contained in:
zhangyu
2022-11-28 18:07:44 +08:00
parent 50b217792d
commit 27ebab5681

View File

@@ -593,47 +593,75 @@ export default {
} }
} }
this.$nextTick(() => { this.$nextTick(() => {
for (let index = 0; index < this.copyDataList.length; index++) { // 先让数组根据 y 排序 之后直接判断顺序 即可判断 Group 是否相邻
const item = this.copyDataList[index] let arr = this.$loadsh.cloneDeep(this.copyDataList)
if (this.$loadsh.get(this.showHidden[item.id], 'visibility') !== 'hidden' && this.$loadsh.get(item.param.enable, 'repeat')) { arr = this.$loadsh.orderBy(arr, function (item) {
this.variablesArr.forEach((variables) => { return item.y
const repeatVariable = this.$loadsh.get(item.param.repeat, 'variable') })
if (item.type === 'group' && variables.name === repeatVariable) { const variablesRepeat = {}
variables.checked.forEach((subItem, subIndex) => { for (let index = 0; index < arr.length; index++) { // 遍历找出所有需要 repeat的group 按照 name进行多次的分组
if (subIndex > 0) { const item = arr[index]
// 复制数据 重新设置id const repeatVariable = this.$loadsh.get(item.param.repeat, 'variable')
const repeatItem = this.$loadsh.cloneDeep(item) if (item.type === 'group' && repeatVariable) {
repeatItem.id = item.id + '-' + 'repeat-' + subIndex const itemPrev = arr[index - 1]
repeatItem.i = repeatItem.id const repeatPrevVariable = this.$loadsh.get(itemPrev.param.repeat, 'variable')
repeatItem.repeatIndex = subIndex if (itemPrev && itemPrev.type === 'group' && repeatPrevVariable === repeatVariable) {
repeatItem.repeatVariable = repeatVariable const arr = variablesRepeat[repeatVariable]
repeatItem.repeatValue = subItem arr[arr.length - 1].repeatArr.push(item)
repeatItem.children.forEach(children => { arr[arr.length - 1].lastGroup = item
children.id = children.id + '-' + 'repeat-' + subIndex } else {
children.repeatIndex = subIndex if (variablesRepeat[repeatVariable]) {
children.repeatVariable = repeatVariable variablesRepeat[repeatVariable].push({
children.repeatValue = subItem repeatArr: [item],
}) lastGroup: item
index += 1
// 复制数据
this.copyDataList.splice(index, 0, repeatItem)
} else {
this.$set(item, 'repeatIndex', 0)
this.$set(item, 'repeatVariable', repeatVariable)
this.$set(item, 'repeatValue', subItem)
item.children.forEach(children => {
this.$set(children, 'repeatIndex', 0)
this.$set(children, 'repeatVariable', repeatVariable)
this.$set(children, 'repeatValue', subItem)
})
this.$refs['chart' + item.id] && this.$refs['chart' + item.id][0] && this.$refs['chart' + item.id][0].getChartData()
}
}) })
} else {
variablesRepeat[repeatVariable] = [{
repeatArr: [item],
lastGroup: item
}]
} }
}) }
} }
} }
this.onScroll(this.scrollTop) Object.keys(variablesRepeat).forEach(key => { // 遍历 variablesRepeat 确定需要插入的数组
const findVariables = this.variablesArr.find(item => item.name == key)
findVariables.checked.forEach((subItem, subIndex) => {
variablesRepeat[key].forEach(group => {
group.repeatArr.forEach(item => {
if (subIndex > 0) {
// 复制数据 重新设置id
const repeatItem = this.$loadsh.cloneDeep(item)
repeatItem.id = item.id + '-' + 'repeat-' + subIndex
repeatItem.i = repeatItem.id
repeatItem.repeatIndex = subIndex
repeatItem.repeatVariable = key
repeatItem.repeatValue = subItem
repeatItem.y = group.lastGroup.y
repeatItem.children.forEach(children => {
children.id = children.id + '-' + 'repeat-' + subIndex
children.repeatIndex = subIndex
children.repeatVariable = key
children.repeatValue = subItem
})
// 复制数据
this.copyDataList.push(repeatItem)
} else {
const findItem = this.copyDataList.find(chart => chart.id === item.id)
this.$set(findItem, 'repeatIndex', 0)
this.$set(findItem, 'repeatVariable', key)
this.$set(findItem, 'repeatValue', subItem)
findItem.children.forEach(children => {
this.$set(children, 'repeatIndex', 0)
this.$set(children, 'repeatVariable', key)
this.$set(children, 'repeatValue', subItem)
})
this.$refs['chart' + findItem.id] && this.$refs['chart' + findItem.id][0] && this.$refs['chart' + findItem.id][0].getChartData()
}
})
})
})
})
}) })
} }