diff --git a/backend/src/main/java/com/taxi/controller/OrderController.java b/backend/src/main/java/com/taxi/controller/OrderController.java index 75554369..cd069900 100644 --- a/backend/src/main/java/com/taxi/controller/OrderController.java +++ b/backend/src/main/java/com/taxi/controller/OrderController.java @@ -46,7 +46,7 @@ public class OrderController { public Result createOrder(@RequestBody CreateOrderRequest request) { System.out.println("=== 订单创建请求到达控制器 ==="); System.out.println("请求参数: " + request); - + try { System.out.println("=== 创建实时订单请求 ==="); System.out.println("接收到的请求数据:"); @@ -56,28 +56,28 @@ public Result createOrder(@RequestBody CreateOrderRequest request) { System.out.println(" 预估距离: " + request.getEstimatedDistance()); System.out.println(" 预估时长: " + request.getEstimatedDuration()); System.out.println(" 预估费用: " + request.getEstimatedFare()); - + Order order = new Order(); order.setOrderNumber(generateOrderNumber()); order.setPassengerId(request.getPassengerId()); order.setPickupAddress(request.getPickupAddress()); order.setPickupLatitude(request.getPickupLatitude()); order.setPickupLongitude(request.getPickupLongitude()); - + order.setDestinationAddress(request.getDestinationAddress()); order.setDestinationLatitude(request.getDestinationLatitude()); order.setDestinationLongitude(request.getDestinationLongitude()); - + // 设置距离、时长和费用信息 order.setEstimatedDistance(request.getEstimatedDistance()); order.setEstimatedDuration(request.getEstimatedDuration()); order.setEstimatedFare(request.getEstimatedFare()); - + System.out.println("设置到Order对象的数据:"); System.out.println(" 预估距离: " + order.getEstimatedDistance()); System.out.println(" 预估时长: " + order.getEstimatedDuration()); System.out.println(" 预估费用: " + order.getEstimatedFare()); - + order.setOrderType("REAL_TIME"); order.setCreatedAt(LocalDateTime.now()); order.setUpdatedAt(LocalDateTime.now()); @@ -85,7 +85,7 @@ public Result createOrder(@RequestBody CreateOrderRequest request) { System.out.println("准备调用 orderService.createOrder"); orderService.createOrder(order); System.out.println("orderService.createOrder 调用成功"); - + // 返回订单ID而不是订单号,前端需要用ID来进行后续操作 return Result.success(order.getId()); } catch (Exception e) { @@ -104,35 +104,35 @@ public Result acceptOrder(@PathVariable Long orderId, @RequestParam Long if (order == null) { return Result.error("订单不存在"); } - + if (!"PENDING".equals(order.getStatus())) { return Result.error("订单状态不允许接单,当前状态: " + order.getStatus()); } - + // 查询司机 Driver driver = driverMapper.selectById(driverId); if (driver == null) { return Result.error("司机不存在"); } - + if (!driver.getIsOnline()) { return Result.error("司机不在线"); } - + // 检查司机是否已有进行中的订单 List driverOrders = orderMapper.selectByDriverId(driverId); boolean hasActiveOrder = driverOrders.stream() - .anyMatch(o -> "ASSIGNED".equals(o.getStatus()) || "PICKUP".equals(o.getStatus()) || "IN_PROGRESS".equals(o.getStatus())); - + .anyMatch(o -> "ASSIGNED".equals(o.getStatus()) || "PICKUP".equals(o.getStatus()) || "IN_PROGRESS".equals(o.getStatus())); + if (hasActiveOrder) { return Result.error("司机正在处理其他订单"); } - + // 分配订单给司机 order.setDriverId(driverId); order.setStatus("ASSIGNED"); orderMapper.updateById(order); - + return Result.success("接单成功"); } catch (Exception e) { return Result.error("接单失败: " + e.getMessage()); @@ -187,48 +187,55 @@ public Result cancelOrderByPassenger(@PathVariable Long orderId) { try { System.out.println("=== 乘客取消订单请求 ==="); System.out.println("订单ID: " + orderId); - + Order order = orderMapper.selectById(orderId); if (order == null) { System.out.println("❌ 订单不存在: " + orderId); return Result.error("订单不存在"); } - + System.out.println("✅ 找到订单: " + order.getOrderNumber() + ", 状态: " + order.getStatus()); - + // 乘客只能在行程开始前取消订单 if ("IN_PROGRESS".equals(order.getStatus()) || "COMPLETED".equals(order.getStatus()) || "CANCELLED".equals(order.getStatus())) { return Result.error("订单已开始行程或已完成,无法取消"); } - + // 更新订单状态 order.setStatus("CANCELLED"); order.setCancelReason("乘客取消"); order.setUpdatedAt(LocalDateTime.now()); orderMapper.updateById(order); - - // 如果订单已分配给司机,需要释放司机 + + // 如果订单已分配给司机,需要释放司机并通知 if (order.getDriverId() != null) { + System.out.println("✅ 订单已分配给司机 " + order.getDriverId() + ",开始释放司机并发送通知"); + + // 释放司机状态 driverRedisService.markDriverFree(order.getDriverId()); - - // 通知司机订单已被乘客取消 + System.out.println("✅ 司机 " + order.getDriverId() + " 状态已释放"); + + // 通知司机订单已被乘客取消(增强版通知) webSocketNotificationService.notifyDriverOrderCancelled( - order.getDriverId(), - orderId, - "乘客已取消订单" + order.getDriverId(), + orderId, + "乘客已取消订单,请清理路线规划" ); + System.out.println("✅ 已通知司机 " + order.getDriverId() + " 订单取消"); + } else { + System.out.println("📋 订单未分配给司机,无需释放司机状态"); } - + // 推送取消状态给乘客 if (order.getPassengerId() != null) { webSocketNotificationService.notifyPassengerOrderStatusChange( - order.getPassengerId(), - orderId, - "CANCELLED", - "订单已取消" + order.getPassengerId(), + orderId, + "CANCELLED", + "订单已取消" ); } - + return Result.success("订单取消成功"); } catch (Exception e) { return Result.error("取消订单失败: " + e.getMessage()); @@ -243,43 +250,43 @@ public Result cancelOrderByDriver(@PathVariable Long orderId, @RequestPa if (order == null) { return Result.error("订单不存在"); } - + // 验证司机权限 if (!driverId.equals(order.getDriverId())) { return Result.error("无权取消此订单"); } - + // 司机只能在行程开始前取消订单 if ("IN_PROGRESS".equals(order.getStatus()) || "COMPLETED".equals(order.getStatus()) || "CANCELLED".equals(order.getStatus())) { return Result.error("订单已开始行程或已完成,无法取消"); } - + // 更新订单状态为待重新分配 order.setDriverId(null); // 清除司机分配 order.setStatus("PENDING"); // 重新设为待分配状态 order.setCancelReason("司机取消,重新分配中"); order.setUpdatedAt(LocalDateTime.now()); orderMapper.updateById(order); - + // 释放司机状态 driverRedisService.markDriverFree(driverId); - + // 将该司机加入此订单的黑名单,避免重复分配 driverRedisService.addDriverToOrderBlacklist(orderId, driverId); - + // 通知乘客订单正在重新分配 if (order.getPassengerId() != null) { webSocketNotificationService.notifyPassengerOrderStatusChange( - order.getPassengerId(), - orderId, - "PENDING", - "司机已取消,正在为您重新寻找司机..." + order.getPassengerId(), + orderId, + "PENDING", + "司机已取消,正在为您重新寻找司机..." ); } - + // 重新进入订单分派队列 orderDispatchService.dispatchOrder(orderId); - + return Result.success("订单已取消并重新分配"); } catch (Exception e) { return Result.error("取消订单失败: " + e.getMessage()); @@ -292,28 +299,28 @@ public Result payOrder(@PathVariable Long orderId, @RequestParam String try { System.out.println("=== 乘客支付订单请求 ==="); System.out.println("订单ID: " + orderId + ", 支付方式: " + paymentMethod); - + Order order = orderMapper.selectById(orderId); if (order == null) { return Result.error("订单不存在"); } - + if (!"COMPLETED".equals(order.getStatus())) { return Result.error("订单未完成,无法支付"); } - + if ("PAID".equals(order.getPaymentStatus())) { return Result.error("订单已支付,请勿重复支付"); } - + // 更新支付状态 order.setPaymentStatus("PAID"); order.setPaymentMethod(paymentMethod); order.setUpdatedAt(LocalDateTime.now()); orderMapper.updateById(order); - + System.out.println("✅ 订单支付成功: " + order.getOrderNumber()); - + return Result.success("支付成功"); } catch (Exception e) { System.err.println("❌ 订单支付失败: " + e.getMessage()); @@ -327,14 +334,14 @@ public Result> getPassengerOrderHistory(@PathVariable Long passenger try { System.out.println("=== 获取乘客历史订单 ==="); System.out.println("乘客ID: " + passengerId); - + List orders = orderMapper.selectByPassengerId(passengerId); - + // 按创建时间倒序排列 orders.sort((o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())); - + System.out.println("✅ 找到 " + orders.size() + " 个历史订单"); - + return Result.success(orders); } catch (Exception e) { System.err.println("❌ 获取历史订单失败: " + e.getMessage()); @@ -347,11 +354,11 @@ public Result> getPassengerOrderHistory(@PathVariable Long passenger public Result checkUnpaidOrders(@PathVariable Long passengerId) { try { List orders = orderMapper.selectByPassengerId(passengerId); - + boolean hasUnpaid = orders.stream() - .anyMatch(order -> "COMPLETED".equals(order.getStatus()) && - !"PAID".equals(order.getPaymentStatus())); - + .anyMatch(order -> "COMPLETED".equals(order.getStatus()) && + !"PAID".equals(order.getPaymentStatus())); + return Result.success(hasUnpaid); } catch (Exception e) { return Result.error("检查未支付订单失败: " + e.getMessage()); @@ -367,11 +374,11 @@ public Result> getUnpaidOrders(HttpServletRequest request) { if (token != null && token.startsWith("Bearer ")) { token = token.substring(7); } - + // 这里应该从token中解析用户ID,简化处理 // 实际项目中需要实现JWT解析 System.out.println("=== 获取未支付订单列表 ==="); - + // 临时方案:从请求参数或header中获取passengerId String passengerIdStr = request.getParameter("passengerId"); if (passengerIdStr == null) { @@ -379,15 +386,15 @@ public Result> getUnpaidOrders(HttpServletRequest request) { // 这里需要根据实际的用户认证机制来获取当前用户ID return Result.error("无法获取用户信息"); } - + Long passengerId = Long.parseLong(passengerIdStr); List allOrders = orderMapper.selectByPassengerId(passengerId); - + List unpaidOrders = allOrders.stream() - .filter(order -> "COMPLETED".equals(order.getStatus()) && - !"PAID".equals(order.getPaymentStatus())) - .collect(Collectors.toList()); - + .filter(order -> "COMPLETED".equals(order.getStatus()) && + !"PAID".equals(order.getPaymentStatus())) + .collect(Collectors.toList()); + System.out.println("找到 " + unpaidOrders.size() + " 个未支付订单"); return Result.success(unpaidOrders); } catch (Exception e) { @@ -403,25 +410,25 @@ public Result getCurrentOrder(@PathVariable Long passengerId) { try { System.out.println("=== 获取乘客当前进行中的订单 ==="); System.out.println("乘客ID: " + passengerId); - + List orders = orderMapper.selectByPassengerId(passengerId); - + // 查找进行中的订单(状态为SCHEDULED, PENDING, ASSIGNED, PICKUP, IN_PROGRESS) Order currentOrder = orders.stream() - .filter(order -> "SCHEDULED".equals(order.getStatus()) || - "PENDING".equals(order.getStatus()) || - "ASSIGNED".equals(order.getStatus()) || - "PICKUP".equals(order.getStatus()) || - "IN_PROGRESS".equals(order.getStatus())) - .findFirst() - .orElse(null); - + .filter(order -> "SCHEDULED".equals(order.getStatus()) || + "PENDING".equals(order.getStatus()) || + "ASSIGNED".equals(order.getStatus()) || + "PICKUP".equals(order.getStatus()) || + "IN_PROGRESS".equals(order.getStatus())) + .findFirst() + .orElse(null); + if (currentOrder != null) { System.out.println("找到进行中的订单: " + currentOrder.getId() + ", 状态: " + currentOrder.getStatus()); } else { System.out.println("没有找到进行中的订单"); } - + return Result.success(currentOrder); } catch (Exception e) { System.err.println("获取当前订单失败: " + e.getMessage()); @@ -438,26 +445,26 @@ public Result confirmPickup(@PathVariable Long orderId) { if (order == null) { return Result.error("订单不存在"); } - + if (!"ASSIGNED".equals(order.getStatus())) { return Result.error("订单状态不正确,当前状态: " + order.getStatus()); } - + order.setStatus("PICKUP"); order.setPickupTime(LocalDateTime.now()); order.setUpdatedAt(LocalDateTime.now()); orderMapper.updateById(order); - + // 推送确认到达状态给乘客 if (order.getPassengerId() != null) { webSocketNotificationService.notifyPassengerOrderStatusChange( - order.getPassengerId(), - orderId, - "PICKUP", - "司机已到达上车点,请准备上车" + order.getPassengerId(), + orderId, + "PICKUP", + "司机已到达上车点,请准备上车" ); } - + return Result.success("确认到达成功"); } catch (Exception e) { return Result.error("确认到达失败: " + e.getMessage()); @@ -472,25 +479,25 @@ public Result startTrip(@PathVariable Long orderId) { if (order == null) { return Result.error("订单不存在"); } - + if (!"PICKUP".equals(order.getStatus())) { return Result.error("订单状态不正确,当前状态: " + order.getStatus()); } - + order.setStatus("IN_PROGRESS"); order.setUpdatedAt(LocalDateTime.now()); orderMapper.updateById(order); - + // 推送行程开始状态给乘客 if (order.getPassengerId() != null) { webSocketNotificationService.notifyPassengerOrderStatusChange( - order.getPassengerId(), - orderId, - "IN_PROGRESS", - "行程已开始,请系好安全带" + order.getPassengerId(), + orderId, + "IN_PROGRESS", + "行程已开始,请系好安全带" ); } - + return Result.success("行程开始成功"); } catch (Exception e) { return Result.error("开始行程失败: " + e.getMessage()); @@ -505,37 +512,37 @@ public Result completeTrip(@PathVariable Long orderId) { if (order == null) { return Result.error("订单不存在"); } - + if (!"IN_PROGRESS".equals(order.getStatus())) { return Result.error("订单状态不正确,当前状态: " + order.getStatus()); } - + order.setStatus("COMPLETED"); order.setCompletionTime(LocalDateTime.now()); order.setUpdatedAt(LocalDateTime.now()); - + // 计算实际费用(这里简化处理,使用预估费用) if (order.getActualFare() == null) { order.setActualFare(order.getEstimatedFare()); } - + orderMapper.updateById(order); - + // 标记司机为空闲状态 if (order.getDriverId() != null) { driverRedisService.markDriverFree(order.getDriverId()); } - + // 推送订单完成状态给乘客,提示需要支付 if (order.getPassengerId() != null) { webSocketNotificationService.notifyPassengerOrderStatusChange( - order.getPassengerId(), - orderId, - "COMPLETED", - "行程已完成,请完成支付" + order.getPassengerId(), + orderId, + "COMPLETED", + "行程已完成,请完成支付" ); } - + return Result.success("订单完成成功"); } catch (Exception e) { return Result.error("完成订单失败: " + e.getMessage()); diff --git a/backend/target/classes/com/taxi/controller/OrderController.class b/backend/target/classes/com/taxi/controller/OrderController.class index 4d438b6b..46408844 100644 Binary files a/backend/target/classes/com/taxi/controller/OrderController.class and b/backend/target/classes/com/taxi/controller/OrderController.class differ diff --git a/backend/uploads/avatars/AliPay.jpg b/backend/uploads/avatars/AliPay.jpg new file mode 100644 index 00000000..8764c426 Binary files /dev/null and b/backend/uploads/avatars/AliPay.jpg differ diff --git a/backend/uploads/avatars/Visa.jpg b/backend/uploads/avatars/Visa.jpg new file mode 100644 index 00000000..6c47082d Binary files /dev/null and b/backend/uploads/avatars/Visa.jpg differ diff --git a/backend/uploads/avatars/WeChat.jpg b/backend/uploads/avatars/WeChat.jpg new file mode 100644 index 00000000..71f8ddfb Binary files /dev/null and b/backend/uploads/avatars/WeChat.jpg differ diff --git a/backend/uploads/avatars/car.png b/backend/uploads/avatars/car.png new file mode 100644 index 00000000..22af165c Binary files /dev/null and b/backend/uploads/avatars/car.png differ diff --git a/frontend/PASSENGER_MAP_FIXES.md b/frontend/PASSENGER_MAP_FIXES.md new file mode 100644 index 00000000..00110d1f --- /dev/null +++ b/frontend/PASSENGER_MAP_FIXES.md @@ -0,0 +1,303 @@ +# 🗺️ 乘客端地图修复总结 + +## 🎯 修复的问题 + +### 1. 页面切换后起始点和终点图标消失 +**问题描述**: 从其他页面切换回乘客地图页面时,上车点和目的地标记消失,只剩下路线。 + +**根本原因**: 页面激活时没有恢复地图标记,只检查了订单状态。 + +**修复方案**: +- 在`initializePassengerMap`函数中添加标记恢复逻辑 +- 新增`restoreMapMarkers`函数来恢复所有地图标记 +- 在页面重新激活时调用标记恢复函数 + +### 2. 取消订单后旧路径没有清除 +**问题描述**: 取消订单后,地图上仍然显示司机路径和乘客路径,没有被清理干净。 + +**根本原因**: `resetOrderState`函数的清理逻辑不够彻底,只清理了部分路径。 + +**修复方案**: +- 增强`resetOrderState`函数,添加完整的路径清理逻辑 +- 清理所有红色司机路径(通过颜色识别) +- 恢复乘客路径为蓝色 + +### 3. 司机位置更新后旧路径没有清除 +**问题描述**: 司机位置更新时,旧的司机路径没有被清除,导致地图上出现多条路径。 + +**根本原因**: `updateDriverLocation`函数在更新位置时没有先清理旧路径。 + +**修复方案**: +- 在`updateDriverLocation`函数开始时调用`clearAllDriverRoutes` +- 新增`clearAllDriverRoutes`函数来彻底清理所有司机路径 +- 确保先清理再规划新路径的顺序 + +## 🔧 修复代码 + +### 1. 标记恢复函数 +```javascript +// 恢复地图标记(修复页面切换后标记消失的问题) +const restoreMapMarkers = () => { + console.log('🔄 恢复地图标记...'); + + if (!map) { + console.log('⚠️ 地图未初始化,跳过标记恢复'); + return; + } + + // 恢复上车点标记 + if (currentPosition.value && !pickupMarker) { + console.log('📍 恢复上车点标记'); + pickupMarker = new window.AMap.Marker({ + position: [currentPosition.value.lng, currentPosition.value.lat], + map, + icon: new window.AMap.Icon({ + image: 'https://webapi.amap.com/theme/v1.3/markers/n/start.png', + size: new window.AMap.Size(25, 34), + imageSize: new window.AMap.Size(25, 34) + }), + title: '上车点', + draggable: !currentOrder.value + }); + + // 重新绑定拖拽事件 + pickupMarker.on("dragend", handlePickupDrag); + } + + // 恢复目的地标记 + if (destinationPosition.value && !destMarker) { + console.log('🎯 恢复目的地标记'); + destMarker = new window.AMap.Marker({ + position: [destinationPosition.value.lng, destinationPosition.value.lat], + map, + icon: new window.AMap.Icon({ + image: 'https://webapi.amap.com/theme/v1.3/markers/n/end.png', + size: new window.AMap.Size(25, 34), + imageSize: new window.AMap.Size(25, 34) + }), + title: '目的地' + }); + } + + // 恢复司机标记(如果有当前订单) + if (currentOrder.value && driverInfo.value && !driverMarker) { + console.log('🚗 恢复司机标记'); + driverMarker = new window.AMap.Marker({ + position: [driverInfo.value.longitude, driverInfo.value.latitude], + map, + icon: new window.AMap.Icon({ + image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png', + size: new window.AMap.Size(25, 34), + imageSize: new window.AMap.Size(25, 34) + }), + title: '司机位置' + }); + } + + console.log('✅ 地图标记恢复完成'); +}; +``` + +### 2. 路径清理函数 +```javascript +// 清理所有司机路径(修复司机位置更新后旧路径没有清除的问题) +const clearAllDriverRoutes = () => { + console.log('🧹 清理所有司机路径...'); + + // 清理全局司机路径变量 + if (window.driverRouteLine) { + map.remove(window.driverRouteLine); + window.driverRouteLine = null; + console.log('🗑️ 清理了全局司机路径变量'); + } + + // 清理所有红色路径(司机路径) + const allOverlays = map.getAllOverlays(); + let cleanedCount = 0; + + allOverlays.forEach(overlay => { + if (overlay.CLASS_NAME === 'AMap.Polyline') { + try { + const options = overlay.getOptions(); + if (options && options.strokeColor === '#FF6B6B') { + map.remove(overlay); + cleanedCount++; + } + } catch (error) { + // 忽略错误 + } + } + }); + + console.log(`🗑️ 清理了 ${cleanedCount} 条红色司机路径`); +}; +``` + +### 3. 增强的订单重置函数 +```javascript +// 重置订单状态(增强版 - 修复取消订单后旧路径没有清除的问题) +const resetOrderState = () => { + console.log("🔄 重置订单状态"); + + orderStore.clearOrderState(); + stopDriverTracking(); + + // 清理司机标记 + if (driverMarker) { + map.remove(driverMarker); + driverMarker = null; + console.log('🗑️ 已清理司机标记'); + } + + // 清理所有司机路径 + clearAllDriverRoutes(); + + // 恢复乘客路径为蓝色 + if (routeLine) { + routeLine.setOptions({ + strokeColor: "#409EFF", + strokeWeight: 6, + strokeOpacity: 0.8, + }); + console.log('🔄 乘客路径已恢复为蓝色'); + } + + // 重置状态 + window.routeInitialized = false; + canOrder.value = true; + isCalling.value = false; + + // 恢复上车点标记的可拖拽状态 + updatePickupMarkerDraggable(); + + // 重新检查未支付订单 + orderStore.checkUnpaidOrders(); + + console.log('✅ 订单状态重置完成'); +}; +``` + +### 4. 增强的司机位置更新函数 +```javascript +const updateDriverLocation = (data) => { + console.log("📍 更新司机位置:", data); + + if (data.driverId === driverInfo.value?.id) { + // 先清理所有旧的司机路径(修复司机位置更新后旧路径没有清除的问题) + clearAllDriverRoutes(); + + // 通过store更新司机位置信息 + if (driverInfo.value) { + const updatedDriver = { + ...driverInfo.value, + latitude: data.latitude, + longitude: data.longitude, + }; + orderStore.setDriverInfo(updatedDriver); + console.log("✅ 司机位置已通过store更新"); + } + + // 更新司机标记位置 + if (driverMarker) { + driverMarker.setPosition([data.longitude, data.latitude]); + driverMarker.setAnimation("AMAP_ANIMATION_BOUNCE"); + setTimeout(() => { + if (driverMarker) { + driverMarker.setAnimation("AMAP_ANIMATION_NONE"); + } + }, 1000); + + // 重新规划路径 + if (orderStatus.value === "IN_PROGRESS") { + currentPosition.value = { + lng: data.longitude, + lat: data.latitude, + }; + showRoute(); + } else { + updateDriverRoute(data.latitude, data.longitude); + } + + updateSharedMapView(false); + } else { + showDriverOnMap(data.latitude, data.longitude); + updateSharedMapView(true); + } + } +}; +``` + +## 🧪 测试验证 + +### 测试工具 +- `frontend/test-passenger-map-fixes.html` - 专门的修复测试页面 + +### 测试场景 + +#### 1. 页面切换测试 +1. 在乘客端创建订单,确保有起始点和终点标记 +2. 切换到其他页面(如个人资料页面) +3. 切换回乘客地图页面 +4. **预期结果**: 所有标记都应该正确显示 + +#### 2. 订单取消测试 +1. 创建订单,等待司机接单 +2. 确保地图上有司机路径(红色)和乘客路径(蓝色) +3. 取消订单 +4. **预期结果**: 司机路径和司机标记被清除,乘客路径恢复为蓝色 + +#### 3. 司机位置更新测试 +1. 有活跃订单时,观察司机路径 +2. 司机移动位置(可以通过禁用/启用位置权限模拟) +3. **预期结果**: 旧的司机路径被清除,新的司机路径被绘制 + +### 调试命令 +```javascript +// 检查地图状态 +console.log('地图状态:', { + mapExists: !!window.map, + pickupMarker: !!window.pickupMarker, + destMarker: !!window.destMarker, + driverMarker: !!window.driverMarker, + routeLine: !!window.routeLine, + driverRouteLine: !!window.driverRouteLine +}); + +// 手动恢复标记 +if (typeof window.restoreMapMarkers === 'function') { + window.restoreMapMarkers(); +} + +// 手动清理司机路径 +if (typeof window.clearAllDriverRoutes === 'function') { + window.clearAllDriverRoutes(); +} + +// 手动重置订单状态 +if (typeof window.resetOrderState === 'function') { + window.resetOrderState(); +} +``` + +## ✅ 修复效果 + +### 修复前的问题 +- ❌ 页面切换后标记消失 +- ❌ 取消订单后路径残留 +- ❌ 司机位置更新后路径累积 + +### 修复后的效果 +- ✅ 页面切换后所有标记正确恢复 +- ✅ 取消订单后所有司机相关元素被清理 +- ✅ 司机位置更新时先清理旧路径再绘制新路径 +- ✅ 路径显示一致性得到保证 +- ✅ 用户体验显著改善 + +## 🔮 后续优化建议 + +1. **性能优化**: 考虑使用防抖机制来减少频繁的路径清理和重绘 +2. **状态管理**: 进一步完善地图状态的统一管理 +3. **错误处理**: 增加更多的错误处理和恢复机制 +4. **用户反馈**: 添加路径更新时的视觉反馈(如加载动画) + +这些修复确保了乘客端地图的稳定性和一致性,解决了用户体验中的关键问题。 \ No newline at end of file diff --git a/frontend/public/avatars/AliPay.jpg b/frontend/public/avatars/AliPay.jpg new file mode 100644 index 00000000..8764c426 Binary files /dev/null and b/frontend/public/avatars/AliPay.jpg differ diff --git a/frontend/public/avatars/Visa.jpg b/frontend/public/avatars/Visa.jpg new file mode 100644 index 00000000..6c47082d Binary files /dev/null and b/frontend/public/avatars/Visa.jpg differ diff --git a/frontend/public/avatars/WeChat.jpg b/frontend/public/avatars/WeChat.jpg new file mode 100644 index 00000000..71f8ddfb Binary files /dev/null and b/frontend/public/avatars/WeChat.jpg differ diff --git a/frontend/src/config/map-fallback.js b/frontend/src/config/map-fallback.js new file mode 100644 index 00000000..e69de29b diff --git a/frontend/src/stores/driver.js b/frontend/src/stores/driver.js index 476ab267..69d27b85 100644 --- a/frontend/src/stores/driver.js +++ b/frontend/src/stores/driver.js @@ -275,6 +275,27 @@ export const useDriverStore = defineStore("driver", () => { console.log("🔄 订单状态已清除"); }; + // 清除当前订单 + const clearCurrentOrder = () => { + currentOrder.value = null; + saveDriverState(); + console.log("🔄 当前订单已清除"); + }; + + // 设置导航信息 + const setNavigationInfo = (navInfo) => { + navigationInfo.value = navInfo; + saveDriverState(); + console.log("🧭 导航信息已设置:", navInfo); + }; + + // 清除导航信息 + const clearNavigationInfo = () => { + navigationInfo.value = null; + saveDriverState(); + console.log("🔄 导航信息已清除"); + }; + // 只清理待处理订单,保留当前订单 const clearPendingOrders = () => { pendingOrders.value = []; @@ -751,6 +772,9 @@ export const useDriverStore = defineStore("driver", () => { restoreDriverState, clearDriverState, clearOrderState, + clearCurrentOrder, + setNavigationInfo, + clearNavigationInfo, clearPendingOrders, initDriverState, getCurrentOrder, diff --git a/frontend/src/views/DriverMap.vue b/frontend/src/views/DriverMap.vue index d6fb40cf..fc70d952 100644 --- a/frontend/src/views/DriverMap.vue +++ b/frontend/src/views/DriverMap.vue @@ -152,15 +152,21 @@ - -