无人机管理后台前端(已迁走)
shuishen
2025-04-10 6ce9dcadb38a994de4cd621795c871092b2e8006
获取行政区划对应对象
1 files added
49 ■■■■■ changed files
src/utils/disposeData.js 49 ●●●●● patch | view | raw | blame | history
src/utils/disposeData.js
New file
@@ -0,0 +1,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
}