云设备录入

This commit is contained in:
sjl
2025-10-11 10:35:25 +08:00
parent 2e58e58c73
commit a3b6a5c0be
23 changed files with 9302 additions and 3827 deletions

View File

@@ -0,0 +1,250 @@
<template>
<div class="mac-address-input" :class="{ disabled: disabled }">
<template v-for="n in 6" :key="n">
<el-input
ref="inputRefs"
v-model="segments[n - 1]"
type="text"
maxlength="2"
:disabled="disabled"
@input="handleInput(n - 1)"
@keydown="handleKeydown(n - 1,$event)"
@focus="handleFocus(n - 1)"
@blur="handleBlur"
@paste="handlePaste(n - 1, $event)"
/>
<span v-if="n < 6" class="separator">:</span>
</template>
</div>
</template>
<script setup lang="ts">
import { ref, watch, nextTick } from 'vue'
interface Props {
modelValue?: string
disabled?: boolean
}
interface Emits {
(e: 'update:modelValue', value: string): void
}
const props = withDefaults(defineProps<Props>(), {
modelValue: '',
disabled: false
})
const emit = defineEmits<Emits>()
// 创建6个输入框的引用
const inputRefs = ref<InstanceType<typeof import('element-plus').ElInput>[]>([])
// MAC地址的6个段
const segments = ref<string[]>(Array(6).fill(''))
// 解析传入的MAC地址
const parseMacAddress = (mac: string): string[] => {
if (!mac) return Array(6).fill('')
// 移除非十六进制字符并转为大写
const cleanMac = mac.replace(/[^0-9a-fA-F]/g, '').toUpperCase()
// 分割成6段每段2个字符
const result: string[] = []
for (let i = 0; i < 6; i++) {
result.push(cleanMac.substr(i * 2, 2))
}
return result
}
// 格式化MAC地址段
const formatSegment = (value: string): string => {
// 只保留前两个十六进制字符并转为大写
return value.replace(/[^0-9a-fA-F]/g, '').toUpperCase().substr(0, 2)
}
// 当前聚焦的输入框索引
const focusedIndex = ref<number | null>(null)
// 处理输入事件
const handleInput = (index: number) => {
// 格式化输入值
const formatted = formatSegment(segments.value[index])
segments.value[index] = formatted
// 如果当前段已满2个字符且不是最后一段自动跳转到下一个输入框
if (formatted.length === 2 && index < 5) {
// 获取下一个输入框的DOM元素
setTimeout(() => {
const nextInput = inputRefs.value[index + 1]
if (nextInput) {
const inputEl = nextInput.$el.querySelector('input')
if (inputEl) {
inputEl.focus()
inputEl.select()
}
}
}, 0)
}
// 更新v-model值
updateModelValue()
}
// 处理键盘事件
const handleKeydown = (index: number, event: KeyboardEvent) => {
const target = event.target as HTMLInputElement
// 处理退格键
if (event.key === 'Backspace' && target.selectionStart === 0 && target.selectionEnd === 0) {
if (segments.value[index] === '' && index > 0) {
// 如果当前段为空,跳转到前一个输入框
event.preventDefault()
const prevInput = inputRefs.value[index - 1]
if (prevInput) {
const inputEl = prevInput.$el.querySelector('input')
if (inputEl) {
inputEl.focus()
// 将光标移到末尾
setTimeout(() => {
inputEl.selectionStart = inputEl.value.length
inputEl.selectionEnd = inputEl.value.length
}, 0)
}
}
}
}
// 处理左箭头键
if (event.key === 'ArrowLeft' && target.selectionStart === 0) {
if (index > 0) {
event.preventDefault()
const prevInput = inputRefs.value[index - 1]
if (prevInput) {
const inputEl = prevInput.$el.querySelector('input')
if (inputEl) {
inputEl.focus()
}
}
}
}
// 处理右箭头键和制表符
if ((event.key === 'ArrowRight' && target.selectionStart === target.value.length) || event.key === 'Tab') {
if (index < 5) {
event.preventDefault()
const nextInput = inputRefs.value[index + 1]
if (nextInput) {
const inputEl = nextInput.$el.querySelector('input')
if (inputEl) {
inputEl.focus()
}
}
}
}
}
// 处理焦点事件
const handleFocus = (index: number) => {
focusedIndex.value = index
}
// 处理失焦事件
const handleBlur = () => {
focusedIndex.value = null
}
// 处理粘贴事件
const handlePaste = (index: number, event: ClipboardEvent) => {
event.preventDefault()
const pastedText = event.clipboardData?.getData('text') || ''
// 清理粘贴的文本
const cleanText = parseMacAddress(pastedText)
// 填充各段
for (let i = 0; i < 6; i++) {
segments.value[i] = cleanText[i] || ''
}
// 更新v-model值
updateModelValue()
// 聚焦到最后一个非空段或最后一个段
setTimeout(() => {
let focusIndex = 5
for (let i = 5; i >= 0; i--) {
if (segments.value[i] !== '') {
focusIndex = i
break
}
}
const inputToFocus = inputRefs.value[focusIndex]
if (inputToFocus) {
const inputEl = inputToFocus.$el.querySelector('input')
if (inputEl) {
inputEl.focus()
inputEl.select()
}
}
}, 0)
}
// 更新v-model值
const updateModelValue = () => {
// 过滤掉空段,然后用冒号连接
const nonEmptySegments = segments.value.filter(s => s !== '')
const mac = nonEmptySegments.join(':')
emit('update:modelValue', mac)
}
// 监听modelValue变化
watch(
() => props.modelValue,
(newVal) => {
if (newVal !== segments.value.filter(s => s !== '').join(':')) {
segments.value = parseMacAddress(newVal || '')
}
},
{ immediate: true }
)
</script>
<style scoped lang="scss">
.mac-address-input {
display: flex;
align-items: center;
gap: 4px;
&.disabled {
opacity: 0.7;
}
input {
width: 40px;
height: 32px;
text-align: center;
border: 1px solid #dcdfe6;
border-radius: 4px;
outline: none;
font-size: 14px;
text-transform: uppercase;
&:focus {
border-color: #409eff;
}
&:disabled {
background-color: #f5f7fa;
cursor: not-allowed;
}
}
.separator {
user-select: none;
font-weight: 500;
}
}
</style>

View 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>

View File

@@ -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(() => {

View 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>

View File

@@ -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
}

View File

@@ -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
}
})
})

View File

@@ -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) {

View File

@@ -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>