style:设备运行参数分析-优化树状图显示效果

main
黄伟杰 3 weeks ago
parent 4c8759596d
commit 6100765fd1

@ -78,6 +78,7 @@ import dayjs from 'dayjs'
import { Echart as EChart } from '@/components/Echart' import { Echart as EChart } from '@/components/Echart'
import { OrganizationApi } from '@/api/mes/organization' import { OrganizationApi } from '@/api/mes/organization'
import { DeviceModelAttributeApi } from '@/api/iot/devicemodelattribute' import { DeviceModelAttributeApi } from '@/api/iot/devicemodelattribute'
import { handleTree } from '@/utils/tree'
defineOptions({ name: 'DeviceParamAnalysis' }) defineOptions({ name: 'DeviceParamAnalysis' })
@ -110,7 +111,9 @@ type ApiTreeEquipment = {
type ApiTreeOrg = { type ApiTreeOrg = {
id: number id: number
name: string name: string
parentId?: number | null
equipments?: ApiTreeEquipment[] equipments?: ApiTreeEquipment[]
children?: ApiTreeOrg[]
} }
const message = useMessage() const message = useMessage()
@ -215,37 +218,47 @@ const handleKeywordChange = () => {
} }
const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => { const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
return ( const normalizedOrgs: ApiTreeOrg[] = (Array.isArray(orgs) ? orgs : []).map((o) => ({
orgs?.map((org) => { ...o,
const equipments = Array.isArray(org?.equipments) ? org.equipments : [] parentId: typeof o?.parentId === 'number' ? o.parentId : Number(o?.parentId ?? 0) || 0
const equipmentNodes: DeviceTreeNode[] = equipments.map((eq) => { }))
const params = Array.isArray(eq?.parameters) ? eq.parameters : []
const paramNodes: DeviceTreeNode[] = params.map((p) => ({ const orgTree = handleTree(normalizedOrgs, 'id', 'parentId', 'children') as ApiTreeOrg[]
id: `param-${eq.id}-${p.id}`,
label: p?.name ?? p?.code ?? String(p?.id ?? ''), const toOrgNode = (org: ApiTreeOrg): DeviceTreeNode => {
type: 'param', const orgChildren = Array.isArray(org?.children) ? org.children.map(toOrgNode) : []
deviceId: Number(eq.id),
modelId: Number(p.id), const equipments = Array.isArray(org?.equipments) ? org.equipments : []
paramKey: p?.code ? String(p.code) : undefined, const equipmentNodes: DeviceTreeNode[] = equipments.map((eq) => {
unit: p?.unit ? String(p.unit) : undefined const params = Array.isArray(eq?.parameters) ? eq.parameters : []
})) const paramNodes: DeviceTreeNode[] = params.map((p) => ({
id: `param-${eq.id}-${p.id}`,
return { label: p?.name ?? p?.code ?? String(p?.id ?? ''),
id: `equipment-${org.id}-${eq.id}`, type: 'param',
label: eq?.name ?? String(eq?.id ?? ''), deviceId: Number(eq.id),
type: 'device', modelId: Number(p.id),
children: paramNodes.length ? paramNodes : undefined paramKey: p?.code ? String(p.code) : undefined,
} unit: p?.unit ? String(p.unit) : undefined
}) }))
return { return {
id: `org-${org.id}`, id: `equipment-${org.id}-${eq.id}`,
label: org?.name ?? String(org?.id ?? ''), label: eq?.name ?? String(eq?.id ?? ''),
type: 'device', type: 'device',
children: equipmentNodes.length ? equipmentNodes : undefined children: paramNodes.length ? paramNodes : undefined
} }
}) ?? [] })
)
const children = [...orgChildren, ...equipmentNodes]
return {
id: `org-${org.id}`,
label: org?.name ?? String(org?.id ?? ''),
type: 'device',
children: children.length ? children : undefined
}
}
return Array.isArray(orgTree) ? orgTree.map(toOrgNode) : []
} }
const loadTree = async () => { const loadTree = async () => {

Loading…
Cancel
Save