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

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

@ -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<DeviceTreeNode[]>([])
const defaultExpandedKeys = ref<string[]>([])
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?.([])

Loading…
Cancel
Save