hejianhao
2026-04-23 f5dc2f4e74ebc427f87c8269b69b37bd862affec
refactor(robotaxi): 提取围栏类型常量并统一收藏删除逻辑

- 新增 geofence.ts 文件,定义围栏类型枚举和常量
- 将 filterRenderableGeofence 函数提取到公共工具模块中
- 统一收藏删除接口的 payload 构建逻辑,根据 itemType 区分站点和场站
1个文件已添加
4个文件已修改
69 ■■■■■ 已修改文件
src/pages/robotaxi/home/hooks/use-navigation.ts 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/robotaxi/home/index.tsx 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/constants/geofence.ts 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/site-search/components/favorite-popup/index.tsx 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/Robotaxi-public-method.ts 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/robotaxi/home/hooks/use-navigation.ts
@@ -1,17 +1,7 @@
import Taro from '@tarojs/taro';
import { formatGeofencePolygons, extractPointsFromPolygons, handleBannerJump, reportEvent } from '../../../../utils/Robotaxi-public-method';
import { formatGeofencePolygons, extractPointsFromPolygons, handleBannerJump, reportEvent, filterRenderableGeofence } from '../../../../utils/Robotaxi-public-method';
import { jumpTo } from '../../../../utils/jump';
import { getGeofence } from '../../../../robotaxi/api/home';
const OPERATING_GEOFENCE_TYPE = 1; // 仅渲染运营区围栏类型
/**
 * 过滤可渲染的围栏数据,仅保留 type=1 的运营区围栏。
 */
const filterRenderableGeofence = (geofenceList: any[]) => {
  if (!Array.isArray(geofenceList)) return [];
  return geofenceList.filter((item) => Number(item?.type) === OPERATING_GEOFENCE_TYPE);
};
type Deps = {
  /** 是否未登录 */
src/pages/robotaxi/home/index.tsx
@@ -17,6 +17,7 @@
import rightIcon from '../../../robotaxi/assets/right-icon.png'
import wsManager from '../../../utils/websocket';
import {
  filterRenderableGeofence,
  formatGeofencePolygons,
  getCityLocation,
  mapOrderStatusToTripStatus,
@@ -62,15 +63,6 @@
import { checkOtp } from '../../../utils/tools';
type HomeTripStatus = TripStatus | 0;
const OPERATING_GEOFENCE_TYPE = 1; // 仅渲染围栏类型 2为场站类型
/**
 * 过滤可渲染的围栏数据,仅保留 type=1 的运营区围栏。
 */
const filterRenderableGeofence = (geofenceList: any[]) => {
  if (!Array.isArray(geofenceList)) return [];
  return geofenceList.filter((item) => Number(item?.type) === OPERATING_GEOFENCE_TYPE);
};
export default function Home() {
  const renderTailPreserveText = (text: string, tailCount = 3) => {
src/robotaxi/constants/geofence.ts
New file
@@ -0,0 +1,10 @@
/**
 * 围栏类型枚举。
 */
export enum GeofenceType {
  OPERATING = 1,
  STATION = 2,
}
export const GEOFENCE_TYPE_OPERATING = GeofenceType.OPERATING; // 运营区围栏类型常量
export const GEOFENCE_TYPE_STATION = GeofenceType.STATION; // 场站围栏类型常量
src/robotaxi/pages/site-search/components/favorite-popup/index.tsx
@@ -52,20 +52,26 @@
  const handleDelete = async (item: any) => {
    try {
      await collectPoint({
        type: 2,
        pointId: item.pointId,
        itemType: item.itemType,
        latitude: item.latitude,
        longitude: item.longitude,
      });
      // 重新拉取数据或从列表中移除
      setList(prev => prev.filter(f => (f.id || f.pointId) !== (item.id || item.pointId)));
      const currentItemType = Number(item?.itemType) === 2 ? 2 : 1; // 删除项类型:1=站点,2=场站
      const payload: any = {
        type: 2, // 收藏接口动作:2=取消收藏
        itemType: currentItemType, // 传删除项 itemType
      };
      if (currentItemType === 2) {
        payload.stationId = item?.stationId; // 场站删除传 stationId
      } else {
        payload.pointId = item?.pointId || item?.id; // 站点删除传 pointId
        payload.latitude = item?.latitude; // 站点删除传纬度
        payload.longitude = item?.longitude; // 站点删除传经度
      }
      await collectPoint(payload);
      setList(prev => prev.filter(f => (f.id || f.pointId || f.stationId) !== (item.id || item.pointId || item.stationId)));
      Taro.showToast({ title: '已取消收藏', icon: 'none' });
    } catch (e) {
      console.log('取消收藏失败', e);
      // 兼容接口失败或格式不对时也能移除(仅供开发时预览效果)
      setList(prev => prev.filter(f => (f.id || f.pointId) !== (item.id || item.pointId)));
      Taro.showToast({ title: '取消收藏失败', icon: 'none' });
    }
  };
src/utils/Robotaxi-public-method.ts
@@ -5,6 +5,7 @@
import { getFenceCheck, getNearestSite } from '../robotaxi/api/home';
import { getOpenCity } from '../robotaxi/api/select-city';
import { getStorage, getOrCreateLocalId } from './tools';
import { GEOFENCE_TYPE_OPERATING } from '../robotaxi/constants/geofence';
/**
 * 安全的 JSON 解析函数
@@ -251,6 +252,14 @@
  });
};
/**
 * 过滤可渲染的围栏数据,仅保留 type=1 的运营区围栏。
 */
export const filterRenderableGeofence = (geofenceList: any[]) => {
  if (!Array.isArray(geofenceList)) return [];
  return geofenceList.filter((item) => Number(item?.type) === GEOFENCE_TYPE_OPERATING);
};
// 格式化电子围栏数据
export const formatGeofencePolygons = (geofenceList: any[]) => {
  if (!geofenceList || !Array.isArray(geofenceList)) {