设备树折叠面板切换问题修改

This commit is contained in:
zhujiyan
2024-10-09 11:29:20 +08:00
parent 135901d473
commit 6e8987d4ae
2 changed files with 31 additions and 22 deletions

View File

@@ -44,7 +44,7 @@
default-expand-all default-expand-all
v-bind="$attrs" v-bind="$attrs"
:data="zlDeviceData" :data="zlDeviceData"
style="overflow: auto;" style="overflow: auto"
> >
<template #default="{ node, data }"> <template #default="{ node, data }">
<span class="custom-tree-node"> <span class="custom-tree-node">
@@ -70,7 +70,7 @@
node-key="id" node-key="id"
:data="bxsDeviceData" :data="bxsDeviceData"
v-bind="$attrs" v-bind="$attrs"
style="overflow: auto;" style="overflow: auto"
> >
<template #default="{ node, data }"> <template #default="{ node, data }">
<span class="custom-tree-node"> <span class="custom-tree-node">
@@ -139,13 +139,6 @@ watch(
}) })
} }
}) })
if (zlDeviceData.value.length != 0) {
activeName.value = '0'
} else if (bxsDeviceData.value.length != 0) {
activeName.value = '1'
} else {
activeName.value = ''
}
} }
}, },
{ {
@@ -206,7 +199,18 @@ const treeRef1 = ref<InstanceType<typeof ElTree>>()
const treeRef2 = ref<InstanceType<typeof ElTree>>() const treeRef2 = ref<InstanceType<typeof ElTree>>()
defineExpose({ treeRef1, treeRef2 }) defineExpose({ treeRef1, treeRef2 })
onMounted(() => { onMounted(() => {
setTimeout(() => {
if (zlDeviceData.value.length != 0) {
activeName.value = '0'
}
if (zlDeviceData.value.length === 0 && bxsDeviceData.value.length != 0) {
activeName.value = '1'
}
if (!zlDeviceData.value && !bxsDeviceData.value) {
activeName.value = ''
}
changeDevice(activeName.value) changeDevice(activeName.value)
}, 500)
}) })
</script> </script>

View File

@@ -43,7 +43,7 @@
default-expand-all default-expand-all
v-bind="$attrs" v-bind="$attrs"
:data="zlDeviceData" :data="zlDeviceData"
style="overflow: auto;" style="overflow: auto"
> >
<template #default="{ node, data }"> <template #default="{ node, data }">
<span class="custom-tree-node"> <span class="custom-tree-node">
@@ -69,7 +69,7 @@
node-key="id" node-key="id"
:data="bxsDeviceData" :data="bxsDeviceData"
v-bind="$attrs" v-bind="$attrs"
style="overflow: auto;" style="overflow: auto"
> >
<template #default="{ node, data }"> <template #default="{ node, data }">
<span class="custom-tree-node"> <span class="custom-tree-node">
@@ -122,9 +122,9 @@ const defaultProps = {
value: 'id' value: 'id'
} }
//治理设备数据 //治理设备数据
const zlDeviceData = ref([]) const zlDeviceData = ref<any>([])
//便携式设备数据 //便携式设备数据
const bxsDeviceData = ref([]) const bxsDeviceData = ref<any>([])
watch( watch(
() => props.data, () => props.data,
(val, oldVal) => { (val, oldVal) => {
@@ -140,13 +140,6 @@ watch(
}) })
} }
}) })
if (zlDeviceData.value.length != 0) {
activeName.value = '0'
} else if (bxsDeviceData.value.length != 0) {
activeName.value = '1'
} else {
activeName.value = ''
}
} }
}, },
{ {
@@ -179,6 +172,7 @@ const changeDevice = (val: any) => {
arr2.push(item2) arr2.push(item2)
}) })
}) })
activeName.value = val
if (val == '0') { if (val == '0') {
arr2.map((item: any) => { arr2.map((item: any) => {
item.checked = false item.checked = false
@@ -211,7 +205,18 @@ const treeRef1 = ref<InstanceType<typeof ElTree>>()
const treeRef2 = ref<InstanceType<typeof ElTree>>() const treeRef2 = ref<InstanceType<typeof ElTree>>()
defineExpose({ treeRef1, treeRef2 }) defineExpose({ treeRef1, treeRef2 })
onMounted(() => { onMounted(() => {
setTimeout(() => {
if (zlDeviceData.value.length != 0) {
activeName.value = '0'
}
if (zlDeviceData.value.length === 0 && bxsDeviceData.value.length != 0) {
activeName.value = '1'
}
if (!zlDeviceData.value && !bxsDeviceData.value) {
activeName.value = ''
}
changeDevice(activeName.value) changeDevice(activeName.value)
}, 500)
}) })
</script> </script>