refactor(robotaxi): 提取围栏类型常量并统一收藏删除逻辑
- 新增 geofence.ts 文件,定义围栏类型枚举和常量
- 将 filterRenderableGeofence 函数提取到公共工具模块中
- 统一收藏删除接口的 payload 构建逻辑,根据 itemType 区分站点和场站
| | |
| | | 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 = { |
| | | /** 是否未登录 */ |
| | |
| | | import rightIcon from '../../../robotaxi/assets/right-icon.png' |
| | | import wsManager from '../../../utils/websocket'; |
| | | import { |
| | | filterRenderableGeofence, |
| | | formatGeofencePolygons, |
| | | getCityLocation, |
| | | mapOrderStatusToTripStatus, |
| | |
| | | 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) => { |
| New file |
| | |
| | | /** |
| | | * 围栏类型枚举。 |
| | | */ |
| | | export enum GeofenceType { |
| | | OPERATING = 1, |
| | | STATION = 2, |
| | | } |
| | | |
| | | export const GEOFENCE_TYPE_OPERATING = GeofenceType.OPERATING; // 运营区围栏类型常量 |
| | | export const GEOFENCE_TYPE_STATION = GeofenceType.STATION; // 场站围栏类型常量 |
| | |
| | | |
| | | 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' }); |
| | | } |
| | | }; |
| | | |
| | |
| | | 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 解析函数 |
| | |
| | | }); |
| | | }; |
| | | |
| | | /** |
| | | * 过滤可渲染的围栏数据,仅保留 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)) { |