From 094826aa52f4e483de34847a0ae3015ea1d82bc9 Mon Sep 17 00:00:00 2001 From: hwj Date: Tue, 17 Mar 2026 17:04:15 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E8=AE=BE=E5=A4=87=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=8F=82=E6=95=B0=E5=88=86=E6=9E=90-=E6=A0=91?= =?UTF-8?q?=E7=8A=B6=E7=BB=93=E6=9E=9C=E9=BB=98=E8=AE=A4=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=88=B0pipeline=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/iot/deviceParamAnalysis/index.vue | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/views/iot/deviceParamAnalysis/index.vue b/src/views/iot/deviceParamAnalysis/index.vue index 8608816c..fdd2326a 100644 --- a/src/views/iot/deviceParamAnalysis/index.vue +++ b/src/views/iot/deviceParamAnalysis/index.vue @@ -15,6 +15,7 @@ v-loading="treeLoading" :data="treeData" :props="treeProps" + :default-expanded-keys="defaultExpandedKeys" node-key="id" show-checkbox check-strictly @@ -98,6 +99,7 @@ type DeviceTreeNode = { label: string type: TreeNodeType children?: DeviceTreeNode[] + orgClass?: string deviceId?: number modelId?: number paramKey?: string @@ -135,6 +137,7 @@ const treeLoading = ref(false) const keyword = ref('') const treeProps = { children: 'children', label: 'label', disabled: 'disabled' } const treeData = ref([]) +const defaultExpandedKeys = ref([]) const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' const MAX_DATE_RANGE_HOURS = 8 @@ -309,6 +312,7 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => { id: `org-${org.id}`, label: org?.name ?? String(org?.id ?? ''), type: 'device', + orgClass: org?.orgClass ? String(org.orgClass) : undefined, children: children.length ? children : undefined, disabled: true } @@ -317,6 +321,32 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => { 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[] => { if (Array.isArray(res)) return res as ApiTreeOrg[] if (Array.isArray(res?.data)) return res.data as ApiTreeOrg[] @@ -330,6 +360,9 @@ const loadTree = async () => { try { const res = await OrganizationApi.deviceParameterAnalysis({ keyword: keyword.value || undefined, showDevices: 1 }) treeData.value = buildTreeFromApi(extractApiOrgs(res)) + defaultExpandedKeys.value = buildDefaultExpandedKeys(treeData.value, 'pipeline') + await nextTick() + treeRef.value?.setExpandedKeys?.(defaultExpandedKeys.value) if (keyword.value) { treeRef.value?.setCurrentKey?.(undefined) treeRef.value?.setCheckedKeys?.([])