style:设备运行参数分析-树状结果默认展示到pipeline层

main
黄伟杰 4 days ago
parent 39bfd8a2e9
commit 094826aa52

@ -15,6 +15,7 @@
v-loading="treeLoading" v-loading="treeLoading"
:data="treeData" :data="treeData"
:props="treeProps" :props="treeProps"
:default-expanded-keys="defaultExpandedKeys"
node-key="id" node-key="id"
show-checkbox show-checkbox
check-strictly check-strictly
@ -98,6 +99,7 @@ type DeviceTreeNode = {
label: string label: string
type: TreeNodeType type: TreeNodeType
children?: DeviceTreeNode[] children?: DeviceTreeNode[]
orgClass?: string
deviceId?: number deviceId?: number
modelId?: number modelId?: number
paramKey?: string paramKey?: string
@ -135,6 +137,7 @@ const treeLoading = ref(false)
const keyword = ref('') const keyword = ref('')
const treeProps = { children: 'children', label: 'label', disabled: 'disabled' } const treeProps = { children: 'children', label: 'label', disabled: 'disabled' }
const treeData = ref<DeviceTreeNode[]>([]) const treeData = ref<DeviceTreeNode[]>([])
const defaultExpandedKeys = ref<string[]>([])
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const MAX_DATE_RANGE_HOURS = 8 const MAX_DATE_RANGE_HOURS = 8
@ -309,6 +312,7 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
id: `org-${org.id}`, id: `org-${org.id}`,
label: org?.name ?? String(org?.id ?? ''), label: org?.name ?? String(org?.id ?? ''),
type: 'device', type: 'device',
orgClass: org?.orgClass ? String(org.orgClass) : undefined,
children: children.length ? children : undefined, children: children.length ? children : undefined,
disabled: true disabled: true
} }
@ -317,6 +321,32 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
return Array.isArray(orgTree) ? orgTree.map(toOrgNode) : [] return Array.isArray(orgTree) ? orgTree.map(toOrgNode) : []
} }
const hasOrgClassInSubtree = (node: DeviceTreeNode, targetOrgClass: string): boolean => {
const children = Array.isArray(node?.children) ? node.children : []
for (const child of children) {
if (child?.orgClass === targetOrgClass) return true
if (hasOrgClassInSubtree(child, targetOrgClass)) return true
}
return false
}
const buildDefaultExpandedKeys = (nodes: DeviceTreeNode[], stopOrgClass: string): string[] => {
const keys: string[] = []
const walk = (list: DeviceTreeNode[]) => {
for (const node of list) {
if (node?.type === 'device' && node?.orgClass && node.orgClass !== stopOrgClass) {
if (hasOrgClassInSubtree(node, stopOrgClass)) {
keys.push(node.id)
}
}
const children = Array.isArray(node?.children) ? node.children : []
if (children.length) walk(children)
}
}
walk(nodes)
return Array.from(new Set(keys))
}
const extractApiOrgs = (res: any): ApiTreeOrg[] => { const extractApiOrgs = (res: any): ApiTreeOrg[] => {
if (Array.isArray(res)) return res as ApiTreeOrg[] if (Array.isArray(res)) return res as ApiTreeOrg[]
if (Array.isArray(res?.data)) return res.data as ApiTreeOrg[] if (Array.isArray(res?.data)) return res.data as ApiTreeOrg[]
@ -330,6 +360,9 @@ const loadTree = async () => {
try { try {
const res = await OrganizationApi.deviceParameterAnalysis({ keyword: keyword.value || undefined, showDevices: 1 }) const res = await OrganizationApi.deviceParameterAnalysis({ keyword: keyword.value || undefined, showDevices: 1 })
treeData.value = buildTreeFromApi(extractApiOrgs(res)) treeData.value = buildTreeFromApi(extractApiOrgs(res))
defaultExpandedKeys.value = buildDefaultExpandedKeys(treeData.value, 'pipeline')
await nextTick()
treeRef.value?.setExpandedKeys?.(defaultExpandedKeys.value)
if (keyword.value) { if (keyword.value) {
treeRef.value?.setCurrentKey?.(undefined) treeRef.value?.setCurrentKey?.(undefined)
treeRef.value?.setCheckedKeys?.([]) treeRef.value?.setCheckedKeys?.([])

Loading…
Cancel
Save