hejianhao
2026-02-28 b541e6b67b5a2f7333c81a8e6e150d3bf6727c62
fix(robotaxi): 修复城市搜索和地图定位相关问题

- 城市搜索页面增加搜索值变化监听,优化搜索结果排序
- 修复城市选择时code字段取值逻辑,优先使用adcode
- 调整地图运营区域加载逻辑,移除冗余条件判断
- 新增地图中心点查询功能,优化位置吸附体验
- 修复起点选择页面跳转逻辑,支持地图选点模式
3个文件已修改
91 ■■■■■ 已修改文件
src/pages/robotaxi/home/index.tsx 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/index.tsx 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/select-city/index.tsx 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/robotaxi/home/index.tsx
@@ -171,7 +171,7 @@
      success: (res) => {
        const auth = res.authSetting['scope.userLocation'];
        if (auth === false) {
          setIsLocationAuthDenied(true);
          // setIsLocationAuthDenied(true);
          // 检查是否有选中的城市缓存
          const selectedCity = Taro.getStorageSync('selectedCity');
          if (!selectedCity || !selectedCity.code) {
@@ -234,7 +234,7 @@
                    const cityName = (city && typeof city === 'string' && city.length > 0) ? city : province;
                    const cityCode = convertAdcodeToCityCode(adcode, cityName, province);
                    getCityInfoWithId(cityCode, cityName).then(cityInfo => {
                      skipCityChangeEffectRef.current = true;
                      // skipCityChangeEffectRef.current = true;
                      setSelectedCity(cityInfo);
                      Taro.setStorageSync('selectedCity', cityInfo);
                    });
@@ -351,7 +351,7 @@
      if (res && Array.isArray(res) && res.length > 0) {
        const newPolygons = formatGeofencePolygons(res);
        setPolygons(newPolygons);
        if ((orderData || orderData?.id) && JSON.stringify(orderData) != '{}') return;
        // if ((orderData || orderData?.id) && JSON.stringify(orderData) != '{}') return;
        // 定位到第一个运营区域的第一个点
        const firstPolygon = res[0];
        if (firstPolygon && firstPolygon.points && firstPolygon.points.length > 0) {
@@ -656,6 +656,48 @@
    }
  }
  const queryPointerByCenter = async (lat: number, lng: number) => {
    setBounce(true);
    setShowToolTip(false);
    try {
      const { isInside, newMarkers, sites } = await updateMapData(lat, lng);
      if (!isInside) {
        setBounce(false);
        return;
      }
      const nearestCandidates = sites.length > 0 ? sites : newMarkers;
      const { targetMarker, minDistance } = findNearestMarker(lat, lng, nearestCandidates);
      setTimeout(() => {
        setBounce(false);
        if (minDistance < adsorptionDistance) {
          setIsAdsorbed(true);
          if (targetMarker) {
            setCurrentSite(targetMarker);
          }
          setShowToolTip(true);
        } else {
          setIsAdsorbed(false);
          setCurrentSite({ name: '正在获取位置...' });
          getAddressByLocation(lng, lat)
            .then((data) => {
              const address = data.name || data.desc;
              setCurrentAddress(address);
              setCurrentSite({ name: address, latitude: lat, longitude: lng });
            })
            .catch(() => {
              setCurrentAddress('未知位置');
              setCurrentSite({ name: '未知位置' });
            });
          setShowToolTip(true);
        }
      }, 600);
    } catch (error) {
      setBounce(false);
    }
  }
  const handleTouchStart = (e: any) => {
    isDragging.current = true;
    startY.current = e.touches[0].clientY;
@@ -705,7 +747,7 @@
    })
  }
  const toSeleteSitePage = (type: string) => {
  const toSeleteSitePage = (type: string, isToMapStart: boolean) => {
    if (isLocationAuthDenied) {
      Taro.showToast({
        title: '请先开启定位权限',
@@ -719,6 +761,11 @@
        icon: 'none'
      });
      return;
    }
    if (isToMapStart) {
      Taro.navigateTo({
        url: '/robotaxi/pages/select-map-site/index?pageType=' + type,
      })
    }
    if (type == 'end') {
      Taro.setStorageSync('startSite', currentSite);
@@ -785,6 +832,13 @@
        points: points,
        padding: [100, 100, 100, 100]
      });
      setTimeout(() => {
        mapCtx.getCenterLocation({
          success: (res) => {
            queryPointerByCenter(res.latitude, res.longitude);
          }
        });
      }, 600);
    } else {
      Taro.showToast({
        title: '此城市暂未开通运营区域',
@@ -875,7 +929,7 @@
      {/* 选择站点 */}
      <View
        className="content-box"
        style={{ height: bannerList.length > 0 ? `${boxHeight}px` : `auto`, transition: isDragging.current ? 'none' : 'height 0.3s ease-out' }}
        style={{ height: bannerList.length > 1 ? `${boxHeight}px` : `auto`, transition: isDragging.current ? 'none' : 'height 0.3s ease-out' }}
        onTouchStart={handleTouchStart}
        onTouchMove={handleTouchMove}
        onTouchEnd={handleTouchEnd}
@@ -884,7 +938,7 @@
          <Image className="site-top-bg" src='https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/cab0e5b2-0da0-4d2e-80e6-0fc2da8d2532.png' />
          <View className="site-boarding-point">
            {/* 起点 */}
            <View onClick={() => toSeleteSitePage('start')} className="now-site">
            <View onClick={() => toSeleteSitePage('start', true)} className="now-site">
              <View className="now-site-dot"></View>
              <View className="now-site-address">
                <View className="now-site-address-content">
src/robotaxi/pages/begin-route/index.tsx
@@ -755,7 +755,7 @@
    const originLng = s?.longitude || longitude;
    const originLat = s?.latitude || latitude;
    if (cachedTripStatus === 1 && originLng && originLat && e?.longitude && e?.latitude) {
      requestRouteAndFare(originLat, originLng, e.latitude, e.longitude);
      requestRouteAndFare(originLat, originLng, e.latitude, e.longitude, true);
    }
    // 初始阶段尝试计算步行路线
    if (tripStatus === 1 && s?.latitude && s?.longitude) {
src/robotaxi/pages/select-city/index.tsx
@@ -55,6 +55,14 @@
    });
  }, [])
  useEffect(() => {
    if (!searchValue) {
      setSearchResultList([]);
      return;
    }
    searchCity()
  }, [searchValue])
  const handleScrollTo = (letter) => {
    setScrollIntoView(`city-${letter}`);
  };
@@ -69,7 +77,7 @@
    }
    Taro.setStorageSync('selectedCity', {
      name: city.name,
      code: city.adcode,
      code: city.adcode || city.code,
      id: city.id,
    });
    Taro.navigateBack();
@@ -78,7 +86,14 @@
  const searchCity = () => {
    if (!searchValue) return;
    getCityList({ cityName: searchValue }).then((res: any) => {
      setSearchResultList(res || []);
      const openCity = openCityList.find(city => city.name.includes(searchValue));
      if (openCity) {
        const filteredRes = (res || []).filter(city => city.name !== openCity.name);
        filteredRes.unshift(openCity);
        setSearchResultList(filteredRes);
      } else {
        setSearchResultList(res || []);
      }
    });
  }
@@ -176,8 +191,8 @@
                  searchResultList.map((item, index) => {
                    const isOpen = openCityList.some(open => open.name === item.name);
                    return (
                      <View key={index} className='search-result-item'>
                        <View onClick={() => handleSelectCity(item, isOpen)} className='search-result-city'>{item.name}</View>
                      <View key={index} className='search-result-item' onClick={() => handleSelectCity(item, isOpen)}>
                        <View className='search-result-city'>{item.name}</View>
                        <View className={`search-result-zone ${!isOpen ? 'search-result-zone-disabled' : ''}`}>{isOpen ? '运营区' : '待开放'}</View>
                      </View>
                    )