From 6ce9dcadb38a994de4cd621795c871092b2e8006 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Thu, 10 Apr 2025 18:53:48 +0800
Subject: [PATCH] 获取行政区划对应对象

---
 src/utils/disposeData.js |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/utils/disposeData.js b/src/utils/disposeData.js
new file mode 100644
index 0000000..e915fa0
--- /dev/null
+++ b/src/utils/disposeData.js
@@ -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
+}

--
Gitblit v1.9.3