From 56b4777dbd45c123d6500063600ce93ff08343c5 Mon Sep 17 00:00:00 2001 From: Huarch Date: Fri, 3 Apr 2026 13:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96queryFeaturesByIds=20ID=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat/GlobalChatbox.tsx | 17 ++++++++++++++++- src/utils/mapQueryService.ts | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/chat/GlobalChatbox.tsx b/src/components/chat/GlobalChatbox.tsx index 9d1ee1b..c7e8d1f 100644 --- a/src/components/chat/GlobalChatbox.tsx +++ b/src/components/chat/GlobalChatbox.tsx @@ -789,12 +789,27 @@ export const GlobalChatbox: React.FC = ({ open, onClose }) => { } // Other frontend tools → dispatch to chatToolStore immediately + const normalizeIds = (): string[] => { + const rawIds = params.ids; + if (Array.isArray(rawIds)) { + return rawIds + .map((id) => String(id).trim()) + .filter(Boolean); + } + if (typeof rawIds === "string") { + return rawIds + .split(",") + .map((id) => id.trim()) + .filter(Boolean); + } + return []; + }; const buildLocateFeaturesAction = ( layer: string, geometryKind: "point" | "line", ): ChatToolAction => ({ type: "locate_features" as const, - ids: (params.ids as string[]) ?? [], + ids: normalizeIds(), layer, geometryKind, }); diff --git a/src/utils/mapQueryService.ts b/src/utils/mapQueryService.ts index 71db93b..7822b5e 100644 --- a/src/utils/mapQueryService.ts +++ b/src/utils/mapQueryService.ts @@ -224,11 +224,16 @@ const queryFeaturesByIds = async ( ids: string[], layer?: string ): Promise => { - if (!ids.length) { + const normalizedIds = ids + .map((id) => String(id).trim()) + .filter((id) => id.length > 0); + + if (!normalizedIds.length) { return []; } - const orFilter = ids.map((id) => `id='${id}'`).join(" OR "); + const escapedIds = normalizedIds.map((id) => id.replace(/'/g, "''")); + const orFilter = escapedIds.map((id) => `id='${id}'`).join(" OR "); try { if (!layer) {