zjk
2026-07-29 429208957f30ab9eedc5533a81aaa284048d09f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import Taro from "@tarojs/taro";
import { useMemo, useRef, useState } from 'react';
 
export const SELECT_SITE_RANGE_STATUS = {
  normal: 'normal',
  outOfOperatingArea: 'out_of_operating_area',
  crossOperatingArea: 'cross_operating_area'
} as const;
 
export type SelectSiteRangeStatus = typeof SELECT_SITE_RANGE_STATUS[keyof typeof SELECT_SITE_RANGE_STATUS];
 
/**
 * 选点页状态容器:仅维护页面状态、refs 与轻量派生数据,不承载业务副作用。
 */
export default function useSelectMapSiteState() {
  type PickupConfirmType = 'click' | 'drag';
 
  const [showCustomerService, setShowCustomerService] = useState(false); // 客服弹窗是否显示
  const [longitude, setLongitude] = useState<number | null>(null); // 经度
  const [latitude, setLatitude] = useState<number | null>(null); // 纬度
  const [mapScale, setMapScale] = useState(14); // 地图缩放等级
  const [showToolTip, setShowToolTip] = useState(true); // 提示是否显示
  const [bounce, setBounce] = useState(false); // 是否弹跳
  const [markers, setMarkers] = useState<any[]>([]); // 标记点列表
  const [pageType, setPageType] = useState('end'); // 起点start 终点end
  const [selectedSite, setSelectedSite] = useState<any>({}); // 选择的站点
  const [selectionMode, setSelectionMode] = useState<'point' | 'station'>('point'); // 当前选择模式
  const [selectedStation, setSelectedStation] = useState<any>(null); // 当前选中的场站
  const [stationSiteList, setStationSiteList] = useState<any[]>([]); // 当前场站下站点列表
  const [showTipPopup, setShowTipPopup] = useState(false); // 提示弹窗是否显示
  const [tipType, setTipType] = useState(''); // 提示类型 1:上下车点近 2:距上车点远
  const [polygons, setPolygons] = useState<any[]>([]); // 地图围栏
  const [isOperatingArea, setIsOperatingArea] = useState(false); // 是否在运营区域内
  const [nearbySites, setNearbySites] = useState<any[]>([]); // 附近站点列表
  const [distanceConfig, setDistanceConfig] = useState<any>({}); // 距离限制配置
  const [polyline, setPolyline] = useState<any[]>([]); // 步行路线
  const [userLongitude, setUserLongitude] = useState<number | null>(null); // 用户经度
  const [userLatitude, setUserLatitude] = useState<number | null>(null); // 用户纬度
  const [rangeStatus, setRangeStatus] = useState<SelectSiteRangeStatus>(SELECT_SITE_RANGE_STATUS.normal); // 当前选点范围状态
  const [walkingDistance, setWalkingDistance] = useState<number | null>(null); // 步行距离
  const [walkingDuration, setWalkingDuration] = useState<number | null>(null); // 步行时长
  const tooltipBgUrl = 'https://s.xiaopeng.com/xp-fe/robot-taxi/imgs/v2/tooltip-bg-20260715.png'; // 提示背景图资源
  const [tooltipBgSrc, setTooltipBgSrc] = useState(tooltipBgUrl); // 提示背景图路径
  const [isAndroid, setIsAndroid] = useState(false); // 是否安卓机型
  const waitingRadarSrc = 'https://s.xiaopeng.com/xp-fe/robot-taxi/imgs/v2/waiting-radar-20260728.webp'; // 加载雷达图
  const [nearbyLoading, setNearbyLoading] = useState(false); // 附近站点加载态
 
  const pendingNearbyRequestCountRef = useRef(0); // 待完成附近站点请求数
  const autoScaleLockedRef = useRef(false); // 自动缩放锁:仅初始化计算一次
  const stationMetaMapRef = useRef<Record<string, any>>({}); // 场站元数据映射(来自围栏)
  const geofenceListRef = useRef<any[]>([]); // 原始围栏数据缓存(用于跨运营区态重算展示围栏)
  const pickupConfirmTypeRef = useRef<PickupConfirmType>('drag'); // 最近一次确认站点来源类型
  const pinLocationRef = useRef<{ lat: number; lng: number }>({ lat: 0, lng: 0 }); // 当前指针确认位置
  const regionSeqRef = useRef(0); // 地图区域变化请求序号,保证仅最新一次拖动的异步结果生效,丢弃乱序返回的过期结果
  const router = Taro.useRouter(); // 路由实例
 
  const mapPolylines = useMemo(() => {
    return polyline;
  }, [polyline]); // 地图折线集合(仅步行路线)
 
  return {
    showCustomerService,
    setShowCustomerService,
    longitude,
    setLongitude,
    latitude,
    setLatitude,
    mapScale,
    setMapScale,
    showToolTip,
    setShowToolTip,
    bounce,
    setBounce,
    markers,
    setMarkers,
    pageType,
    setPageType,
    selectedSite,
    setSelectedSite,
    selectionMode,
    setSelectionMode,
    selectedStation,
    setSelectedStation,
    stationSiteList,
    setStationSiteList,
    showTipPopup,
    setShowTipPopup,
    tipType,
    setTipType,
    polygons,
    setPolygons,
    isOperatingArea,
    setIsOperatingArea,
    nearbySites,
    setNearbySites,
    distanceConfig,
    setDistanceConfig,
    polyline,
    setPolyline,
    userLongitude,
    setUserLongitude,
    userLatitude,
    setUserLatitude,
    rangeStatus,
    setRangeStatus,
    walkingDistance,
    setWalkingDistance,
    walkingDuration,
    setWalkingDuration,
    tooltipBgUrl,
    tooltipBgSrc,
    setTooltipBgSrc,
    isAndroid,
    setIsAndroid,
    waitingRadarSrc,
    nearbyLoading,
    setNearbyLoading,
    pendingNearbyRequestCountRef,
    autoScaleLockedRef,
    stationMetaMapRef,
    geofenceListRef,
    pickupConfirmTypeRef,
    pinLocationRef,
    regionSeqRef,
    router,
    mapPolylines,
  };
}