From 3dfc1dfc2c073223cbcd3ae00b4dd73a99fd7d3a Mon Sep 17 00:00:00 2001 From: userGyl Date: Thu, 12 Feb 2026 16:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ln_jq_app/assets/html/map.html | 85 ++++++++++++------- .../pages/c_page/reservation/controller.dart | 10 ++- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/ln_jq_app/assets/html/map.html b/ln_jq_app/assets/html/map.html index 4765faf..a4d16d3 100644 --- a/ln_jq_app/assets/html/map.html +++ b/ln_jq_app/assets/html/map.html @@ -195,10 +195,10 @@ @@ -244,6 +244,11 @@ } }); + // 点击地图空白处重置状态 + map.on('click', function() { + resetSearchState(); + }); + // 添加基础控件 map.addControl(new AMap.Scale()); map.addControl(new AMap.ToolBar({ @@ -285,6 +290,19 @@ }); } + /** + * 重置搜索状态,隐藏面板和路线 + */ + function resetSearchState() { + if (document.body.classList.contains('panel-active')) { + console.log("JS->: 重置地图状态"); + document.body.classList.remove('panel-active'); + var panel = document.getElementById('panel'); + panel.style.display = 'none'; + if (driving) driving.clear(); + } + } + /** * 核心功能 1: 接收 Flutter 传来的定位数据 * Flutter 端调用: webViewController.evaluateJavascript("updateMyLocation(...)") @@ -481,24 +499,30 @@ offset: new AMap.Pixel(-16, -32), title: station.name, label: { - content: '
' + station.name + '
', + content: '
' + station.name + + '
', direction: 'top' } }); // 3. 绑定点击事件:选中即为目的地,并开始规划 - sMarker.on('click', function() { - document.getElementById('endInput').value = station.address || station.name; - // 更新当前的 destMarker (如果需要) - if (destMarker) destMarker.setMap(null); + sMarker.on('click', function () { + var stationName = station.name || "目的地"; + document.getElementById('endInput').value = station.address || + stationName; + + // 更新当前的 destMarker + if (destMarker && destMarker !== sMarker) destMarker.setMap(null); destMarker = sMarker; - startRouteSearch(); + // 直接传入坐标对象,避免关键字搜索失败 + var loc = new AMap.LngLat(station.longitude, station.latitude); + startRouteSearch(loc); }); stationMarkers.push(sMarker); }); - + } else { console.log("JS->: 业务报错或无数据:", res.message); } @@ -554,11 +578,12 @@ } } + /** - * 路径规划 + * 路径规划 + * @param {AMap.LngLat} [destLoc] 可选的终点坐标 */ - function startRouteSearch() { - // 获取输入框的文字 + function startRouteSearch(destLoc) { var startKw = document.getElementById('startInput').value; var endKw = document.getElementById('endInput').value; @@ -566,28 +591,21 @@ alert("请输入起点"); return; } - if (!endKw) { alert("请输入终点"); return; } - // 清除旧路线 if (driving) driving.clear(); - - // 收起键盘 document.getElementById('startInput').blur(); document.getElementById('endInput').blur(); - // --- 构造路径规划的点 --- var points = []; - // 1. 处理起点逻辑 + // 1. 起点逻辑 if (!startKw || startKw === '我的位置' || startKw.includes('当前位置')) { if (!currentLng || !currentLat) { - if (window.flutter_inappwebview) { - window.flutter_inappwebview.callHandler('requestLocation'); - } + if (window.flutter_inappwebview) window.flutter_inappwebview.callHandler('requestLocation'); alert("正在获取定位,请稍后..."); return; } @@ -601,10 +619,17 @@ }); } - // 2. 处理终点逻辑 - points.push({ - keyword: endKw - }); + // 2. 终点逻辑:如果有传入坐标,则直接使用坐标导航,成功率最高 + if (destLoc) { + points.push({ + keyword: endKw, + location: destLoc // 关键:使用精确坐标 + }); + } else { + points.push({ + keyword: endKw + }); + } // 3. 发起搜索 driving.search(points, function (status, result) { @@ -613,10 +638,12 @@ var panel = document.getElementById('panel'); panel.style.display = 'block'; document.body.classList.add('panel-active'); - } else { - console.log('JS: 规划失败', result); - alert("规划失败,请检查起终点名称"); } + // else { + // console.error('JS: 规划失败', result); + // // 如果坐标规划都失败了,通常是由于起终点距离过近或政策限制(如货车禁行) + // alert("路径规划未成功,请尝试微调起终点"); + // } }); } @@ -641,4 +668,4 @@ - + \ No newline at end of file diff --git a/ln_jq_app/lib/pages/c_page/reservation/controller.dart b/ln_jq_app/lib/pages/c_page/reservation/controller.dart index 1813f51..6da544e 100644 --- a/ln_jq_app/lib/pages/c_page/reservation/controller.dart +++ b/ln_jq_app/lib/pages/c_page/reservation/controller.dart @@ -253,7 +253,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin { if (_debounce?.isActive ?? false) { return; } - _debounce = Timer(const Duration(seconds: 1), () {}); + _debounce = Timer(const Duration(milliseconds: 200), () {}); showLoading("加载中"); @@ -393,7 +393,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin { // 创建一个每1分钟执行一次的周期性定时器 _refreshTimer = Timer.periodic(const Duration(minutes: 1), (timer) { - getSiteList(); + getSiteList(showloading: false); }); } @@ -521,7 +521,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin { updateUi(); } - void getSiteList() async { + void getSiteList({showloading = true}) async { if (StorageService.to.phone == "13888888888") { //该账号给stationOptions手动添加一个数据 final testStation = StationModel( @@ -546,7 +546,9 @@ class C_ReservationController extends GetxController with BaseControllerMixin { } try { - showLoading("加氢站数据加载中"); + if(showloading){ + showLoading("加氢站数据加载中"); + } var responseData = await HttpService.to.get( "appointment/station/queryHydrogenSiteInfo",