diff --git a/src/components/tree/index.vue b/src/components/tree/index.vue index c262380f..b5473a4f 100644 --- a/src/components/tree/index.vue +++ b/src/components/tree/index.vue @@ -86,9 +86,40 @@ const onMenuCollapse = () => { menuCollapse.value = !menuCollapse.value proxy.eventBus.emit('cnTreeCollapse', menuCollapse) } -const filterNode = (value: string, data: any) => { +const filterNode = (value: string, data: any, node: any) => { if (!value) return true - return data.name.includes(value) + // return data.name.includes(value) + if (data.name) { + + return chooseNode(value, data, node) + } +} +// 过滤父节点 / 子节点 (如果输入的参数是父节点且能匹配,则返回该节点以及其下的所有子节点;如果参数是子节点,则返回该节点的父节点。name是中文字符,enName是英文字符. +const chooseNode = (value: string, data: any, node: any) => { + + if (data.name.indexOf(value) !== -1) { + return true + } + const level = node.level + // 如果传入的节点本身就是一级节点就不用校验了 + if (level === 1) { + return false + } + // 先取当前节点的父节点 + let parentData = node.parent + // 遍历当前节点的父节点 + let index = 0 + while (index < level - 1) { + // 如果匹配到直接返回,此处name值是中文字符,enName是英文字符。判断匹配中英文过滤 + if (parentData.data.name.indexOf(value) !== -1) { + return true + } + // 否则的话再往上一层做匹配 + parentData = parentData.parent + index++ + } + // 没匹配到返回false + return false } // 添加树 const onAddTree = () => { diff --git a/src/components/tree/pqs/bearingTree.vue b/src/components/tree/pqs/bearingTree.vue index 748d9c2e..a62ff862 100644 --- a/src/components/tree/pqs/bearingTree.vue +++ b/src/components/tree/pqs/bearingTree.vue @@ -45,7 +45,7 @@ const formData = ref({ loadType: null, manufacturer: null, serverName: 'event-boot', - statisticalType: classificationData[2].id, + statisticalType: classificationData[0].id, scale: null }) const loadData = () => { @@ -68,16 +68,16 @@ const loadData = () => { ] } res.data.forEach((item: any) => { - item.icon = 'fa-solid fa-synagogue' + item.icon = 'el-icon-HomeFilled' item.color = config.getColorVal('elementUiPrimary') item.children.forEach((item2: any) => { - item2.icon = 'fa-solid fa-city' + item2.icon = 'el-icon-CollectionTag' item.color = config.getColorVal('elementUiPrimary') item2.children.forEach((item3: any) => { - item3.icon = 'fa-solid fa-building' + item3.icon = 'el-icon-Flag' item3.color = config.getColorVal('elementUiPrimary') item3.children.forEach((item4: any) => { - item4.icon = 'fa-solid fa-tower-observation' + item4.icon = 'el-icon-OfficeBuilding' item4.color = config.getColorVal('elementUiPrimary') item4.children.forEach((item5: anyObj) => { item5.alias = `${item.name}>${item2.name}>${item3.name}>${item4.name}>${item5.name}` @@ -99,7 +99,7 @@ const loadData = () => { nodeKey = res.data[0].children[0].children[0].children[0].children[0].id emit('init', res.data[0].children[0].children[0].children[0].children[0]) - tree.value = res.data[0].children + tree.value = res.data if (nodeKey) { nextTick(() => { treeRef.value.treeRef.setCurrentKey(nodeKey) diff --git a/src/components/tree/pqs/index.vue b/src/components/tree/pqs/index.vue index a944768d..ed2cce9e 100644 --- a/src/components/tree/pqs/index.vue +++ b/src/components/tree/pqs/index.vue @@ -16,14 +16,7 @@ - + { diff --git a/src/layouts/admin/components/navMenus.vue b/src/layouts/admin/components/navMenus.vue index 2e1484ba..36a05438 100644 --- a/src/layouts/admin/components/navMenus.vue +++ b/src/layouts/admin/components/navMenus.vue @@ -39,14 +39,14 @@ -