1、//获取设备点位服务
const getDataPositionTree = async () => {
const res = await http.getDataPositionTree({})
if (res && res.success) {
// console.log('res值', res)
const data = res.data
state.treeData = data.positionList ? data.positionList : [] //点位
state.positionData = data.deviceMap ? data.deviceMap : {} //设备
const arr = []
for (let i in data.deviceMap) {
arr.push(i)
}
state.positionIds = arr
state.defaultChecked = arr
state.positionDataList = data.positionList ? data.positionList : [] //点位list
getEquipmentList()
} else {
utils.message('error', res.info, 3000)
}
}
2、从设备树中选择
const handleCheckChange = (data, checked) => {
// console.log('拉拉选择', checked)
const arr = []
for (let i in checked.checkedNodes) {
if (checked.checkedNodes[i].positionId == null) {
} else {
arr.push(checked.checkedNodes[i].positionId)
}
}
state.positionIds = arr
// console.log('选中的positionIds', state.positionIds)
// console.log('点位list', state.positionDataList)
state.checkedCode = []
//调用方法
treeMethod(state.positionDataList)
}
3、循环树状结构,获取code
const treeMethod = (allPositions) => {
for (let i in allPositions) {
console.log('arr', allPositions[i])
for (let j in state.positionIds) {
if (state.positionIds[j] == allPositions[i].id) {
state.checkedCode.push(allPositions[i].code)
}
}
if (allPositions[i].children) {
treeMethod(allPositions[i].children)
}
}
// console.log('获取到code', state.checkedCode)
}```