| New file |
| | |
| | | /* |
| | | * @Author: shuishen 1109946754@qq.com |
| | | * @Date: 2025-04-10 18:28:40 |
| | | * @LastEditors: shuishen 1109946754@qq.com |
| | | * @LastEditTime: 2025-04-10 18:52:25 |
| | | * @FilePath: \drone-web-manage\src\utils\disposeData.js |
| | | * @Description: |
| | | * |
| | | * Copyright (c) 2025 by shuishen, All Rights Reserved. |
| | | */ |
| | | |
| | | /** |
| | | * 递归查找指定adcode值的对象 |
| | | * @param {string} property - 要匹配的属性名(如'adcode') |
| | | * @param {*} value - 要匹配的属性值(如22223) |
| | | * @returns {Object|null} 找到的对象或null |
| | | */ |
| | | export const getAdcodeObj = (data, property, value) => { |
| | | // 检查当前对象是否直接匹配 |
| | | if (data && typeof data === 'object') { |
| | | // 检查payload.properties中的adcode |
| | | if (data.payload?.objects?.collection?.geometries?.[0]?.properties?.[property] == value) { |
| | | return data |
| | | } |
| | | |
| | | // 检查当前对象的直接属性 |
| | | if (data[property] == value) { |
| | | return data |
| | | } |
| | | |
| | | // 递归检查children |
| | | if (data.children) { |
| | | for (const key in data.children) { |
| | | const found = getAdcodeObj(data.children[key], property, value) |
| | | if (found) return found |
| | | } |
| | | } |
| | | |
| | | // 递归检查数组或对象属性 |
| | | for (const key in data) { |
| | | if (key !== 'children' && data[key] && typeof data[key] === 'object') { |
| | | const found = getAdcodeObj(data[key], property, value) |
| | | if (found) return found |
| | | } |
| | | } |
| | | } |
| | | |
| | | return null |
| | | } |