无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * @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
}