云设备录入
This commit is contained in:
138
src/components/tree/cloudDevice.vue
Normal file
138
src/components/tree/cloudDevice.vue
Normal file
@@ -0,0 +1,138 @@
|
||||
<template>
|
||||
<div :style="{ width: menuCollapse ? '40px' : props.width }" style='transition: all 0.3s; overflow: hidden;'>
|
||||
<Icon v-show='menuCollapse' @click='onMenuCollapse' :name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
||||
:class="menuCollapse ? 'unfold' : ''" size='18' class='fold ml10 mt20 menu-collapse'
|
||||
style='cursor: pointer' />
|
||||
<div class='cn-tree' :style='{ opacity: menuCollapse ? 0 : 1 }'>
|
||||
<div style='display: flex; align-items: center' class='mb10'>
|
||||
<el-input maxlength="32" show-word-limit v-model.trim='filterText' placeholder='请输入内容' clearable>
|
||||
<template #prefix>
|
||||
<Icon name='el-icon-Search' style='font-size: 16px' />
|
||||
</template>
|
||||
</el-input>
|
||||
<!-- <Icon @click='onMenuCollapse' :name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
||||
:class="menuCollapse ? 'unfold' : ''" size='18' class='fold ml10 menu-collapse'
|
||||
style='cursor: pointer' v-if='props.canExpand' /> -->
|
||||
</div>
|
||||
<el-tree :style="{ height: 'calc(100vh - 200px)' }"
|
||||
style=' overflow: auto;' ref='treeRef' :props='defaultProps' highlight-current
|
||||
@check-change="checkTreeNodeChange" :filter-node-method='filterNode' node-key='id' v-bind='$attrs'>
|
||||
<template #default='{ node, data }'>
|
||||
<span class='custom-tree-node'>
|
||||
<Icon :name='data.icon' style='font-size: 16px' :style='{ color: data.color }'
|
||||
v-if='data.icon' />
|
||||
<span style='margin-left: 4px'>{{ node.label }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang='ts' setup>
|
||||
import useCurrentInstance from '@/utils/useCurrentInstance'
|
||||
import { ElTree } from 'element-plus'
|
||||
import { emit } from 'process';
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'govern/tree'
|
||||
})
|
||||
|
||||
interface Props {
|
||||
width?: string
|
||||
canExpand?: boolean
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
width: '280px',
|
||||
canExpand: true
|
||||
})
|
||||
const { proxy } = useCurrentInstance()
|
||||
const menuCollapse = ref(false)
|
||||
const filterText = ref('')
|
||||
const defaultProps = {
|
||||
label: 'name',
|
||||
value: 'id'
|
||||
}
|
||||
const emit = defineEmits(['checkTreeNodeChange'])
|
||||
watch(filterText, val => {
|
||||
treeRef.value!.filter(val)
|
||||
|
||||
})
|
||||
const onMenuCollapse = () => {
|
||||
menuCollapse.value = !menuCollapse.value
|
||||
proxy.eventBus.emit('cnTreeCollapse', menuCollapse)
|
||||
}
|
||||
const filterNode = (value: string, data: any, node: any) => {
|
||||
if (!value) return true
|
||||
// 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 checkTreeNodeChange = () => {
|
||||
// console.log(treeRef.value?.getCheckedNodes(), "ikkkkkiisiiisis");
|
||||
emit('checkTreeNodeChange', treeRef.value?.getCheckedNodes())
|
||||
}
|
||||
const treeRef = ref<InstanceType<typeof ElTree>>()
|
||||
defineExpose({ treeRef })
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
.cn-tree {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
:deep(.el-tree) {
|
||||
border: 1px solid var(--el-border-color);
|
||||
}
|
||||
|
||||
:deep(.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content) {
|
||||
background-color: var(--el-color-primary-light-7);
|
||||
}
|
||||
|
||||
.menu-collapse {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.custom-tree-node {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
@@ -99,6 +99,32 @@
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-collapse-item>
|
||||
<el-collapse-item title="云前置设备" name="2" v-if="frontDeviceData.length != 0">
|
||||
<el-tree
|
||||
:style="{ height: zlDeviceData.length != 0 ? 'calc(100vh - 280px)' : 'calc(100vh - 238px)' }"
|
||||
ref="treeRef3"
|
||||
:props="defaultProps"
|
||||
highlight-current
|
||||
default-expand-all
|
||||
:filter-node-method="filterNode"
|
||||
node-key="id"
|
||||
:data="frontDeviceData"
|
||||
v-bind="$attrs"
|
||||
style="overflow: auto"
|
||||
>
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<Icon
|
||||
:name="data.icon"
|
||||
style="font-size: 16px"
|
||||
:style="{ color: data.color }"
|
||||
v-if="data.icon"
|
||||
/>
|
||||
<span style="margin-left: 4px">{{ node.label }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</div>
|
||||
</div>
|
||||
@@ -140,6 +166,8 @@ const zlDeviceData = ref([])
|
||||
const zlDevList = ref<any>([])
|
||||
//便携式设备数据
|
||||
const bxsDeviceData = ref([])
|
||||
//前置设备数据
|
||||
const frontDeviceData = ref([])
|
||||
watch(
|
||||
() => props.data,
|
||||
(val, oldVal) => {
|
||||
@@ -153,6 +181,11 @@ watch(
|
||||
item.children.map((vv: any) => {
|
||||
bxsDeviceData.value.push(vv)
|
||||
})
|
||||
}else if (item.name == '云前置设备') {
|
||||
item.children.map((vv: any) => {
|
||||
frontDeviceData.value.push(vv)
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -166,8 +199,10 @@ watch(
|
||||
watch(filterText, val => {
|
||||
if (activeName.value == '0') {
|
||||
treeRef1.value!.filter(val)
|
||||
} else {
|
||||
} else if(activeName.value == '1'){
|
||||
treeRef2.value!.filter(val)
|
||||
}else {
|
||||
treeRef3.value!.filter(val)
|
||||
}
|
||||
})
|
||||
watch(process, val => {
|
||||
@@ -242,6 +277,7 @@ const chooseNode = (value: string, data: any, node: any) => {
|
||||
}
|
||||
|
||||
const changeDevice = (val: any) => {
|
||||
console.log('changeDevice', val)
|
||||
let arr1: any = []
|
||||
|
||||
//zlDeviceData
|
||||
@@ -258,6 +294,14 @@ const changeDevice = (val: any) => {
|
||||
arr2.push(item)
|
||||
// })
|
||||
})
|
||||
let arr3: any = []
|
||||
frontDeviceData.value.forEach((item: any) => {
|
||||
item.children.forEach((item2: any) => {
|
||||
item2.children.forEach((item3: any) => {
|
||||
arr3.push(item3)
|
||||
})
|
||||
})
|
||||
})
|
||||
if (val == '0') {
|
||||
arr2.map((item: any) => {
|
||||
item.checked = false
|
||||
@@ -272,11 +316,20 @@ const changeDevice = (val: any) => {
|
||||
treeRef2.value && treeRef2.value.setCurrentKey(arr2[0].id)
|
||||
emit('changeDeviceType', activeName.value, arr2[0])
|
||||
}
|
||||
if (val == '2') {
|
||||
arr3.map((item: any) => {
|
||||
item.checked = false
|
||||
})
|
||||
treeRef3.value && treeRef3.value.setCurrentKey(arr3[0].id)
|
||||
emit('changeDeviceType', activeName.value, arr3[0])
|
||||
}
|
||||
}
|
||||
//治理
|
||||
const treeRef1 = ref<InstanceType<typeof ElTree>>()
|
||||
//便携式
|
||||
const treeRef2 = ref<InstanceType<typeof ElTree>>()
|
||||
//前置
|
||||
const treeRef3 = ref<InstanceType<typeof ElTree>>()
|
||||
defineExpose({ treeRef1, treeRef2 })
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
|
||||
171
src/components/tree/govern/cloudDeviceEntryTree.vue
Normal file
171
src/components/tree/govern/cloudDeviceEntryTree.vue
Normal file
@@ -0,0 +1,171 @@
|
||||
<template>
|
||||
<Tree ref="treRef" :width="width" :data="tree" default-expand-all @changePointType="changePointType" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, nextTick, onMounted, defineProps } from 'vue'
|
||||
import Tree from '../index.vue'
|
||||
import { getLineTree,getCldTree } from '@/api/cs-device-boot/csLedger'
|
||||
import { useConfig } from '@/stores/config'
|
||||
import { getTemplateByDept } from '@/api/harmonic-boot/luckyexcel'
|
||||
import { useDictData } from '@/stores/dictData'
|
||||
|
||||
interface Props {
|
||||
template?: boolean
|
||||
}
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
template: false
|
||||
})
|
||||
defineOptions({
|
||||
name: 'govern/deviceTree'
|
||||
})
|
||||
|
||||
const emit = defineEmits(['init', 'checkChange', 'pointTypeChange', 'Policy'])
|
||||
const config = useConfig()
|
||||
const tree = ref()
|
||||
const dictData = useDictData()
|
||||
const treRef = ref()
|
||||
const width = ref('')
|
||||
|
||||
|
||||
const info = (selectedNodeId?: string) => {
|
||||
console.log('tree.value:', selectedNodeId);
|
||||
tree.value = []
|
||||
let arr1: any[] = []
|
||||
getCldTree().then(res => {
|
||||
try {
|
||||
// 检查响应数据结构
|
||||
let rootData = null;
|
||||
if (Array.isArray(res.data)) {
|
||||
// 旧的数据结构 - 数组
|
||||
rootData = res.data.find((item: any) => item.name == '云前置设备');
|
||||
} else if (res.data && res.data.name == '云前置设备') {
|
||||
// 新的数据结构 - 单个对象
|
||||
rootData = res.data;
|
||||
}
|
||||
|
||||
// 治理设备
|
||||
if (rootData) {
|
||||
rootData.icon = 'el-icon-Menu'
|
||||
rootData.level = 0
|
||||
rootData.color = config.getColorVal('elementUiPrimary')
|
||||
// 确保根节点的 children 是数组
|
||||
if (!Array.isArray(rootData.children)) {
|
||||
rootData.children = []
|
||||
}
|
||||
rootData.children.forEach((item: any) => {
|
||||
item.icon = 'el-icon-HomeFilled'
|
||||
item.level = 1
|
||||
item.color = config.getColorVal('elementUiPrimary')
|
||||
// 确保 children 是数组
|
||||
if (!Array.isArray(item.children)) {
|
||||
item.children = []
|
||||
}
|
||||
item.children.forEach((item2: any) => {
|
||||
item2.icon = 'el-icon-List'
|
||||
item2.level = 2
|
||||
item2.color = config.getColorVal('elementUiPrimary')
|
||||
|
||||
// 确保 children 是数组
|
||||
if (!Array.isArray(item2.children)) {
|
||||
item2.children = []
|
||||
}
|
||||
item2.children.forEach((item3: any) => {
|
||||
item3.icon = 'el-icon-Platform'
|
||||
item3.level = 3
|
||||
item3.color =
|
||||
item3.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
||||
|
||||
// 确保 children 是数组
|
||||
if (!Array.isArray(item3.children)) {
|
||||
item3.children = []
|
||||
}
|
||||
|
||||
item3.children.forEach((item4: any) => {
|
||||
item4.icon = 'el-icon-Platform'
|
||||
item4.level = 4
|
||||
item4.color =
|
||||
item4.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
||||
arr1.push(item4)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
tree.value = [rootData] // 确保 tree.value 是数组
|
||||
} else {
|
||||
tree.value = []
|
||||
}
|
||||
nextTick(() => {
|
||||
if (arr1.length) {
|
||||
// 安全检查 treRef 和 treeRef1 是否存在
|
||||
if (treRef.value && treRef.value.treeRef1 && treRef.value.treeRef1.setCurrentKey) {
|
||||
// 如果传入了要选中的节点ID,则选中该节点,否则选中第一个节点
|
||||
console.log('selectedNodeId:', selectedNodeId);
|
||||
if (selectedNodeId) {
|
||||
treRef.value.treeRef1.setCurrentKey(selectedNodeId);
|
||||
// 查找对应的节点数据并触发事件
|
||||
let selectedNode = null;
|
||||
const findNode = (nodes: any[]) => {
|
||||
for (const node of nodes) {
|
||||
if (node.id === selectedNodeId) {
|
||||
selectedNode = node;
|
||||
return true;
|
||||
}
|
||||
if (node.children && findNode(node.children)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
findNode(tree.value);
|
||||
|
||||
if (selectedNode) {
|
||||
emit('init', {
|
||||
level: selectedNode.level,
|
||||
...selectedNode
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 初始化选中第一个节点
|
||||
treRef.value.treeRef1.setCurrentKey(arr1[0].id);
|
||||
emit('init', {
|
||||
level: 2,
|
||||
...arr1[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error in processing getCldTree response:', error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const changePointType = (val: any, obj: any) => {
|
||||
emit('pointTypeChange', val, obj)
|
||||
}
|
||||
if (props.template) {
|
||||
getTemplateByDept({ id: dictData.state.area[0].id })
|
||||
.then((res: any) => {
|
||||
emit('Policy', res.data)
|
||||
info()
|
||||
})
|
||||
.catch(err => {
|
||||
info()
|
||||
})
|
||||
} else {
|
||||
info()
|
||||
}
|
||||
|
||||
// 暴露 info 方法给父组件调用
|
||||
defineExpose({
|
||||
info
|
||||
})
|
||||
|
||||
onMounted(() => {})
|
||||
</script>
|
||||
@@ -38,6 +38,7 @@ const changeDeviceType = (val: any, obj: any) => {
|
||||
getDeviceTree().then(res => {
|
||||
let arr: any[] = []
|
||||
let arr2: any[] = []
|
||||
let arr3: any[] = []
|
||||
//治理设备
|
||||
res.data.map((item: any) => {
|
||||
if (item.name == '治理设备') {
|
||||
@@ -58,7 +59,6 @@ getDeviceTree().then(res => {
|
||||
})
|
||||
})
|
||||
} else if (item.name == '便携式设备') {
|
||||
// console.log(11111)
|
||||
item.children.forEach((item: any) => {
|
||||
item.icon = 'el-icon-Platform'
|
||||
item.color = config.getColorVal('elementUiPrimary')
|
||||
@@ -82,9 +82,28 @@ getDeviceTree().then(res => {
|
||||
// })
|
||||
})
|
||||
})
|
||||
}else if (item.name == '云前置设备') {
|
||||
item.children.forEach((item: any) => {
|
||||
item.icon = 'el-icon-HomeFilled'
|
||||
item.color = config.getColorVal('elementUiPrimary')
|
||||
item.children.forEach((item2: any) => {
|
||||
item2.icon = 'el-icon-List'
|
||||
item2.color = config.getColorVal('elementUiPrimary')
|
||||
item2.children.forEach((item3: any) => {
|
||||
item3.icon = 'el-icon-Platform'
|
||||
item3.color = config.getColorVal('elementUiPrimary')
|
||||
if (item3.comFlag === 1) {
|
||||
item3.color = '#e26257 !important'
|
||||
}
|
||||
arr3.push(item3)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
console.log("🚀 ~ file: deviceTree.vue ~ line 18 ~ getDeviceTree ~ tree:", arr,arr2,arr3)
|
||||
tree.value = res.data
|
||||
|
||||
nextTick(() => {
|
||||
if (arr.length) {
|
||||
treRef.value.treeRef1.setCurrentKey(arr[0].id)
|
||||
@@ -103,7 +122,19 @@ getDeviceTree().then(res => {
|
||||
...arr2[0]
|
||||
})
|
||||
return
|
||||
} else {
|
||||
}
|
||||
console.log("🚀 ~ file: deviceTree.vue ~ line 33 ~ getDeviceTree ~ tree:", arr3.length)
|
||||
if (arr3.length) {
|
||||
console.log("🚀 ~ file: deviceTree.vue ~ line 33 ~ getDeviceTree ~ tree:", arr3)
|
||||
treRef.value.treeRef3.setCurrentKey(arr3[0].id)
|
||||
// 注册父组件事件
|
||||
emit('init', {
|
||||
level: 2,
|
||||
...arr3[0]
|
||||
})
|
||||
return
|
||||
}
|
||||
else {
|
||||
emit('init')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ const info = () => {
|
||||
tree.value = []
|
||||
let arr1: any[] = []
|
||||
let arr2: any[] = []
|
||||
let arr3: any[] = []
|
||||
getLineTree().then(res => {
|
||||
//治理设备
|
||||
res.data.map((item: any) => {
|
||||
@@ -70,10 +71,33 @@ const info = () => {
|
||||
arr2.push(item2)
|
||||
})
|
||||
})
|
||||
} else if (item.name == '云前置设备') {
|
||||
item.children.forEach((item: any) => {
|
||||
item.icon = 'el-icon-HomeFilled'
|
||||
item.level = 1
|
||||
item.color = config.getColorVal('elementUiPrimary')
|
||||
item.children.forEach((item2: any) => {
|
||||
item2.icon = 'el-icon-List'
|
||||
item2.level = 1
|
||||
item2.color = config.getColorVal('elementUiPrimary')
|
||||
item2.children.forEach((item3: any) => {
|
||||
item3.icon = 'el-icon-Platform'
|
||||
item3.level = 1
|
||||
item3.color =
|
||||
item3.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
||||
item3.children.forEach((item4: any) => {
|
||||
item4.icon = 'el-icon-Platform'
|
||||
item4.color =
|
||||
item4.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
||||
// item4.color = '#e26257 !important'
|
||||
arr3.push(item4)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
tree.value = res.data
|
||||
|
||||
nextTick(() => {
|
||||
if (arr1.length) {
|
||||
//初始化选中
|
||||
@@ -83,18 +107,29 @@ const info = () => {
|
||||
level: 2,
|
||||
...arr1[0]
|
||||
})
|
||||
return
|
||||
}
|
||||
if (arr2.length) {
|
||||
//初始化选中
|
||||
treRef.value.treeRef2.setCurrentKey(arr2[0].id)
|
||||
// 注册父组件事件
|
||||
emit('init', {
|
||||
level: 2,
|
||||
...arr2[0]
|
||||
})
|
||||
return
|
||||
}
|
||||
if(arr3.length){
|
||||
treRef.value.treeRef3.setCurrentKey(arr3[0].id)
|
||||
emit('init', {
|
||||
level: 2,
|
||||
...arr3[0]
|
||||
})
|
||||
return
|
||||
}
|
||||
// if (arr2.length) {
|
||||
// //初始化选中
|
||||
// treRef.value.treeRef2.setCurrentKey(arr2[0].id)
|
||||
// // 注册父组件事件
|
||||
// emit('init', {
|
||||
// level: 2,
|
||||
// ...arr2[0]
|
||||
// })
|
||||
// }
|
||||
else {
|
||||
emit('init', arr2[0])
|
||||
emit('init')
|
||||
return
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
<Icon name='el-icon-Search' style='font-size: 16px' />
|
||||
</template>
|
||||
</el-input>
|
||||
<Icon @click='onMenuCollapse' :name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
||||
<!-- <Icon @click='onMenuCollapse' :name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
||||
:class="menuCollapse ? 'unfold' : ''" size='18' class='fold ml10 menu-collapse'
|
||||
style='cursor: pointer' v-if='props.canExpand' />
|
||||
style='cursor: pointer' v-if='props.canExpand' /> -->
|
||||
</div>
|
||||
<el-tree style='flex: 1; overflow: auto;' ref='treeRef' :props='defaultProps' highlight-current
|
||||
<el-tree :style="{ height: 'calc(100vh - 200px)' }"
|
||||
style=' overflow: auto;' ref='treeRef' :props='defaultProps' highlight-current
|
||||
@check-change="checkTreeNodeChange" :filter-node-method='filterNode' node-key='id' v-bind='$attrs'>
|
||||
<template #default='{ node, data }'>
|
||||
<span class='custom-tree-node'>
|
||||
@@ -33,6 +34,7 @@ import useCurrentInstance from '@/utils/useCurrentInstance'
|
||||
import { ElTree } from 'element-plus'
|
||||
import { emit } from 'process';
|
||||
import { ref, watch } from 'vue'
|
||||
import { t } from 'vxe-table';
|
||||
|
||||
defineOptions({
|
||||
name: 'govern/tree'
|
||||
@@ -63,6 +65,7 @@ const onMenuCollapse = () => {
|
||||
proxy.eventBus.emit('cnTreeCollapse', menuCollapse)
|
||||
}
|
||||
const filterNode = (value: string, data: any, node: any) => {
|
||||
console.log(value, data, node, 'filterNode');
|
||||
if (!value) return true
|
||||
// return data.name.includes(value)
|
||||
if (data.name) {
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
</el-collapse-item>
|
||||
<el-collapse-item title="便携式设备" name="1" v-if="bxsDeviceData.length != 0">
|
||||
<el-tree
|
||||
:style="{ height: zlDeviceData.length != 0 ? 'calc(100vh - 280px)' : 'calc(100vh - 238px)' }"
|
||||
:style="{ height: zlDeviceData.length != 0 ? 'calc(100vh - 330px)' : 'calc(100vh - 238px)' }"
|
||||
ref="treeRef2"
|
||||
:props="defaultProps"
|
||||
highlight-current
|
||||
@@ -92,6 +92,32 @@
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-collapse-item>
|
||||
<el-collapse-item title="云前置设备" name="2" v-if="yqfDeviceData.length != 0">
|
||||
<el-tree
|
||||
:style="{ height: zlDeviceData.length != 0 ? 'calc(100vh - 330px)' : 'calc(100vh - 238px)' }"
|
||||
ref="treeRef3"
|
||||
:props="defaultProps"
|
||||
highlight-current
|
||||
default-expand-all
|
||||
:filter-node-method="filterNode"
|
||||
node-key="id"
|
||||
:data="yqfDeviceData"
|
||||
v-bind="$attrs"
|
||||
style="overflow: auto"
|
||||
>
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<Icon
|
||||
:name="data.icon"
|
||||
style="font-size: 16px"
|
||||
:style="{ color: data.color }"
|
||||
v-if="data.icon"
|
||||
/>
|
||||
<span style="margin-left: 4px">{{ node.label }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</div>
|
||||
</div>
|
||||
@@ -100,6 +126,7 @@
|
||||
<script lang="ts" setup>
|
||||
import useCurrentInstance from '@/utils/useCurrentInstance'
|
||||
import { ElTree } from 'element-plus'
|
||||
import { el } from 'element-plus/es/locale'
|
||||
import { ref, watch, defineEmits, onMounted, nextTick, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
defineOptions({
|
||||
@@ -134,6 +161,8 @@ const zlDeviceData = ref<any>([])
|
||||
const zlDevList = ref<any>([])
|
||||
//便携式设备数据
|
||||
const bxsDeviceData = ref<any>([])
|
||||
//云前置设备数据
|
||||
const yqfDeviceData = ref<any>([])
|
||||
watch(
|
||||
() => props.data,
|
||||
(val, oldVal) => {
|
||||
@@ -148,21 +177,13 @@ watch(
|
||||
item.children.map((vv: any) => {
|
||||
bxsDeviceData.value.push(vv)
|
||||
})
|
||||
}else if (item.name == '云前置设备') {
|
||||
item.children.map((vv: any) => {
|
||||
yqfDeviceData.value.push(vv)
|
||||
})
|
||||
}
|
||||
})
|
||||
if (zlDeviceData.value.length != 0) {
|
||||
zlDevList.value = filterProcess(JSON.parse(JSON.stringify(zlDeviceData.value)))
|
||||
activeName.value = '0'
|
||||
}
|
||||
if (zlDeviceData.value.length === 0 && bxsDeviceData.value.length != 0) {
|
||||
activeName.value = '1'
|
||||
}
|
||||
if (!zlDeviceData.value && !bxsDeviceData.value) {
|
||||
activeName.value = ''
|
||||
}
|
||||
nextTick(() => {
|
||||
changeDevice(activeName.value)
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -174,8 +195,10 @@ watch(
|
||||
watch(filterText, val => {
|
||||
if (activeName.value == '0') {
|
||||
treeRef1.value!.filter(val)
|
||||
} else {
|
||||
} else if(activeName.value == '1') {
|
||||
treeRef2.value!.filter(val)
|
||||
}else {
|
||||
treeRef3.value!.filter(val)
|
||||
}
|
||||
})
|
||||
watch(process, val => {
|
||||
@@ -190,6 +213,7 @@ watch(process, val => {
|
||||
})
|
||||
|
||||
const changeDevice = (val: any) => {
|
||||
console.log('changeDevice', val)
|
||||
let arr1: any = []
|
||||
//zlDeviceData
|
||||
zlDevList.value.forEach((item: any) => {
|
||||
@@ -207,6 +231,16 @@ const changeDevice = (val: any) => {
|
||||
arr2.push(item2)
|
||||
})
|
||||
})
|
||||
let arr3: any = []
|
||||
yqfDeviceData.value.forEach((item: any) => {
|
||||
item.children.forEach((item2: any) => {
|
||||
item2.children.forEach((item3: any) => {
|
||||
item3.children.forEach((item4: any) => {
|
||||
arr3.push(item4)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
activeName.value = val
|
||||
if (val == '0') {
|
||||
arr2.map((item: any) => {
|
||||
@@ -222,6 +256,13 @@ const changeDevice = (val: any) => {
|
||||
treeRef2?.value && treeRef2.value.setCurrentKey(arr2[0]?.id)
|
||||
emit('changePointType', activeName.value, arr2[0])
|
||||
}
|
||||
if(val == '2'){
|
||||
arr3.map((item: any) => {
|
||||
item.checked = false
|
||||
})
|
||||
treeRef3?.value && treeRef3.value.setCurrentKey(arr3[0]?.id)
|
||||
emit('changePointType', activeName.value, arr3[0])
|
||||
}
|
||||
// if(activeName.value){
|
||||
// emit('changePointType', activeName.value)
|
||||
// }
|
||||
@@ -290,12 +331,25 @@ const chooseNode = (value: string, data: any, node: any) => {
|
||||
const treeRef1 = ref<InstanceType<typeof ElTree>>()
|
||||
//便携式
|
||||
const treeRef2 = ref<InstanceType<typeof ElTree>>()
|
||||
//云前置
|
||||
const treeRef3 = ref<InstanceType<typeof ElTree>>()
|
||||
defineExpose({ treeRef1, treeRef2 })
|
||||
onMounted(() => {
|
||||
// nextTick(() => {
|
||||
// // setTimeout(() => {
|
||||
// // }, 500)
|
||||
// })
|
||||
setTimeout(() => {
|
||||
if (zlDeviceData.value.length != 0) {
|
||||
zlDevList.value = filterProcess(JSON.parse(JSON.stringify(zlDeviceData.value)))
|
||||
activeName.value = '0'
|
||||
}
|
||||
if (zlDeviceData.value.length === 0 && bxsDeviceData.value.length != 0) {
|
||||
activeName.value = '1'
|
||||
}
|
||||
if (!zlDeviceData.value && !bxsDeviceData.value) {
|
||||
activeName.value = ''
|
||||
}
|
||||
nextTick(() => {
|
||||
changeDevice(activeName.value)
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -327,4 +381,6 @@ onMounted(() => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user