@heycar/heycars-map 2.13.0-relay2 → 2.14.0-walkOptimize2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/v2/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v2/api/contants.d.ts +3 -0
- package/dist/v2/api/contants.js +6 -0
- package/dist/v2/business-components/AuxiliaryPassanger/AuxiliaryPassanger.d.ts +6 -0
- package/dist/v2/business-components/AuxiliaryPassanger/AuxiliaryPassanger.js +50 -0
- package/dist/v2/business-components/AuxiliaryPassanger/index.d.ts +1 -0
- package/dist/v2/business-components/AuxiliaryPassanger/index.js +4 -0
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/useCacheCenterPlace.d.ts +2 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/useCacheCenterPlace.js +14 -6
- package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
- package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +6 -0
- package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +1 -3
- package/dist/v2/chunks/{BusinessRecomendPlaceMap.e9166e7d.js → BusinessRecomendPlaceMap.8a4a1015.js} +5 -3
- package/dist/v2/hooks/useMapGeometry.d.ts +3 -3
- package/dist/v2/hooks/useMapGeometry.js +3 -3
- package/dist/v2/hooks/useMapLoader.js +3 -3
- package/dist/v2/hooks/useWalkingRoute.js +46 -4
- package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- package/dist/v2/index.js +1 -1
- package/dist/v2/utils/geometry.d.ts +1 -0
- package/dist/v2/utils/geometry.js +4 -2
- package/dist/v2/utils/geometryPolygon.d.ts +5 -0
- package/dist/v2/utils/geometryPolygon.js +27 -0
- package/dist/v2/utils/log.js +11 -3
- package/dist/v2/utils/ttlCache.d.ts +34 -0
- package/dist/v2/utils/ttlCache.js +64 -0
- package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v3/api/contants.d.ts +3 -0
- package/dist/v3/api/contants.js +6 -0
- package/dist/v3/business-components/AuxiliaryPassanger/AuxiliaryPassanger.d.ts +8 -0
- package/dist/v3/business-components/AuxiliaryPassanger/AuxiliaryPassanger.js +46 -0
- package/dist/v3/business-components/AuxiliaryPassanger/index.d.ts +1 -0
- package/dist/v3/business-components/AuxiliaryPassanger/index.js +4 -0
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/useCacheCenterPlace.d.ts +2 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/useCacheCenterPlace.js +14 -6
- package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
- package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +4 -0
- package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +1 -3
- package/dist/v3/chunks/{BusinessRecomendPlaceMap.c71d0b97.js → BusinessRecomendPlaceMap.b30ca4e4.js} +5 -3
- package/dist/v3/hooks/useMapGeometry.d.ts +3 -3
- package/dist/v3/hooks/useMapGeometry.js +3 -3
- package/dist/v3/hooks/useMapLoader.js +3 -3
- package/dist/v3/hooks/useWalkingRoute.js +46 -4
- package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- package/dist/v3/index.js +1 -1
- package/dist/v3/utils/geometry.d.ts +1 -0
- package/dist/v3/utils/geometry.js +4 -2
- package/dist/v3/utils/geometryPolygon.d.ts +5 -0
- package/dist/v3/utils/geometryPolygon.js +27 -0
- package/dist/v3/utils/log.js +11 -3
- package/dist/v3/utils/ttlCache.d.ts +34 -0
- package/dist/v3/utils/ttlCache.js +64 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -358,6 +358,17 @@ export default defineComponent({
|
|
|
358
358
|
displayName: "default place displayName",
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
+
// 可选,应用启动时是否跳过等待 GPS,默认 false
|
|
362
|
+
skipWaitGeo={
|
|
363
|
+
false ||
|
|
364
|
+
true || {
|
|
365
|
+
lng: 139.55555,
|
|
366
|
+
lat: 35.5555,
|
|
367
|
+
type: "wgs84",
|
|
368
|
+
name: "skip geo place name",
|
|
369
|
+
displayName: "skip geo place displayName",
|
|
370
|
+
}
|
|
371
|
+
}
|
|
361
372
|
getAvailable={() => Promise.resolve(true)}
|
|
362
373
|
getRecomendPlace={getRecomendPlace}
|
|
363
374
|
getDefaultCenterPlace={getDefaultCenterPlace}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h } from "vue";
|
|
2
|
-
import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.
|
|
2
|
+
import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
3
3
|
import { useBusinessRecomendPlaceMap } from "../hooks-business/useBusinessRecomendPlaceMap.js";
|
|
4
4
|
import { defineSetup } from "../types/helper.js";
|
|
5
5
|
import { d as demo } from "../chunks/Demo.css.e921a2f6.js";
|
|
@@ -5,7 +5,10 @@ export declare const ANIMATION_DURATION_FOR_100VW = 100;
|
|
|
5
5
|
export declare const ANIMATION_DURATION_PER_ZOOM = 200;
|
|
6
6
|
export declare const BEIJIN_POINT: Point;
|
|
7
7
|
export declare const MAX_DEVIATION_DISTANCE = 30;
|
|
8
|
+
export declare const MAX_DEVIATION_DISTANCE_WALKING = 5;
|
|
8
9
|
export declare const CAR_DISTANCE_MIN = 20;
|
|
10
|
+
export declare const PASSENGER_DISTANCE_MAX = 2000;
|
|
11
|
+
export declare const PASSENGER_DISTANCE_MIN = 20;
|
|
9
12
|
export declare const ZINDEX_BUBBLE_LAYER = 50;
|
|
10
13
|
export declare const ZINDEX_START_END_LOGO_LAYER = 40;
|
|
11
14
|
export declare const ZINDEX_PLACE_LAYER = 30;
|
package/dist/v2/api/contants.js
CHANGED
|
@@ -4,7 +4,10 @@ const ANIMATION_DURATION_FOR_100VW = 100;
|
|
|
4
4
|
const ANIMATION_DURATION_PER_ZOOM = 200;
|
|
5
5
|
const BEIJIN_POINT = [116.2317, 39.5427];
|
|
6
6
|
const MAX_DEVIATION_DISTANCE = 30;
|
|
7
|
+
const MAX_DEVIATION_DISTANCE_WALKING = 5;
|
|
7
8
|
const CAR_DISTANCE_MIN = 20;
|
|
9
|
+
const PASSENGER_DISTANCE_MAX = 2e3;
|
|
10
|
+
const PASSENGER_DISTANCE_MIN = 20;
|
|
8
11
|
const ZINDEX_BUBBLE_LAYER = 50;
|
|
9
12
|
const ZINDEX_START_END_LOGO_LAYER = 40;
|
|
10
13
|
const ZINDEX_PLACE_LAYER = 30;
|
|
@@ -30,7 +33,10 @@ export {
|
|
|
30
33
|
GET_RECOMMEND_PLACE_TIMEOUT,
|
|
31
34
|
MAX_ANIMATION_DISTANCE_VW,
|
|
32
35
|
MAX_DEVIATION_DISTANCE,
|
|
36
|
+
MAX_DEVIATION_DISTANCE_WALKING,
|
|
33
37
|
MIN_ANIMATION_DURATION,
|
|
38
|
+
PASSENGER_DISTANCE_MAX,
|
|
39
|
+
PASSENGER_DISTANCE_MIN,
|
|
34
40
|
REGEO_TIMEOUT,
|
|
35
41
|
TRACKS_MATCH_MAX_LENGTH,
|
|
36
42
|
ZINDEX_AUXILIARY_GRASP,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DriverStatus, Point } from "../../types/interface";
|
|
2
|
+
export interface AuxiliaryPassangerProps {
|
|
3
|
+
status: DriverStatus;
|
|
4
|
+
passengerPosition?: Point;
|
|
5
|
+
}
|
|
6
|
+
export declare const AuxiliaryPassanger: import("vue-demi").DefineComponent<import("vue3").ComponentObjectPropsOptions<AuxiliaryPassangerProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<AuxiliaryPassangerProps, Required<AuxiliaryPassangerProps>>, never, AuxiliaryPassangerProps>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { h } from "vue";
|
|
2
|
+
import { ref } from "vue-demi";
|
|
3
|
+
import { MAX_DEVIATION_DISTANCE_WALKING } from "../../api/contants.js";
|
|
4
|
+
import { defineSetup } from "../../types/helper.js";
|
|
5
|
+
import { watchEffectForDeepOption } from "../../utils/compare.js";
|
|
6
|
+
import { AuxiliaryCircle } from "../AuxiliaryCircle/AuxiliaryCircle.js";
|
|
7
|
+
import { AuxiliaryLine } from "../AuxiliaryLine/AuxiliaryLine.js";
|
|
8
|
+
const usePositionHistory = (source, capacity) => {
|
|
9
|
+
const history = ref([]);
|
|
10
|
+
watchEffectForDeepOption(source, (point) => {
|
|
11
|
+
if (!point)
|
|
12
|
+
return;
|
|
13
|
+
history.value.push([...point]);
|
|
14
|
+
if (history.value.length > capacity) {
|
|
15
|
+
history.value.shift();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return history;
|
|
19
|
+
};
|
|
20
|
+
const AuxiliaryPassanger = defineSetup("AuxiliaryPassanger", function(props) {
|
|
21
|
+
const passengerPositionHistory = usePositionHistory(() => props.passengerPosition, 20);
|
|
22
|
+
return () => {
|
|
23
|
+
const {
|
|
24
|
+
status,
|
|
25
|
+
passengerPosition
|
|
26
|
+
} = props;
|
|
27
|
+
console.log("passengerPositionHistory = ", passengerPositionHistory.value);
|
|
28
|
+
const prevPositions = passengerPositionHistory.value.slice(0, -1);
|
|
29
|
+
if (status !== "assign" && status !== "confirmed" && status !== "driverStartRelayService" && status !== "dispatched" && status !== "driverStartService" && status !== "book-driverStartService" && status !== "book-dispatched" && status !== "driverArrived")
|
|
30
|
+
return;
|
|
31
|
+
return h("div", [!!passengerPosition && h(AuxiliaryCircle, {
|
|
32
|
+
"attrs": {
|
|
33
|
+
"center": passengerPosition,
|
|
34
|
+
"radius": MAX_DEVIATION_DISTANCE_WALKING,
|
|
35
|
+
"opacity": 0.2
|
|
36
|
+
}
|
|
37
|
+
}), prevPositions.length > 0 && h(AuxiliaryLine, {
|
|
38
|
+
"attrs": {
|
|
39
|
+
"path": prevPositions,
|
|
40
|
+
"type": "circle",
|
|
41
|
+
"color": "purple",
|
|
42
|
+
"scale": MAX_DEVIATION_DISTANCE_WALKING,
|
|
43
|
+
"opacity": 0.2
|
|
44
|
+
}
|
|
45
|
+
})]);
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
export {
|
|
49
|
+
AuxiliaryPassanger
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AuxiliaryPassanger";
|
|
@@ -5,7 +5,7 @@ import { type UseMapDragProps } from "../../hooks/useMapDrag";
|
|
|
5
5
|
import type { UseMapPlaceProps } from "../../hooks/useMapPlace";
|
|
6
6
|
import { type UseMapRecomendPlaceProps } from "../../hooks/useMapRecomendPlace";
|
|
7
7
|
import type { Coordinatify, CoordinatifyProps } from "../../types/coordinatify";
|
|
8
|
-
import { type BusinessGeolocationPositionError, type CoordinatePlace } from "../../types/interface";
|
|
8
|
+
import { type BusinessGeolocationPositionError, type CoordinatePlace, type CoordinatePoint } from "../../types/interface";
|
|
9
9
|
import { type AbsoluteAddressBoxProps } from "../AbsoluteAddressBox";
|
|
10
10
|
import { type PickupPointsProps } from "../PickupPoints";
|
|
11
11
|
export declare const RECOMMEND_PLACE_DRAG_LIMIT = 10;
|
|
@@ -33,6 +33,7 @@ export interface BusinessRecomendPlaceMapProps extends CoordinatifyProps<Omit<He
|
|
|
33
33
|
geoErrorOnceNotificationKey?: string;
|
|
34
34
|
mapContext: CoordinatifyProps<BusinessRecomendPlaceContext>;
|
|
35
35
|
defaultCenterPlace?: CoordinatePlace | ((place?: CoordinatePlace) => CoordinatePlace | undefined);
|
|
36
|
+
skipWaitGeo?: boolean | CoordinatePlace | CoordinatePoint;
|
|
36
37
|
renderPlacePhoto?: (place: CoordinatePlace) => undefined | {
|
|
37
38
|
src: string;
|
|
38
39
|
title?: string;
|
|
@@ -27,7 +27,7 @@ import "../GreenZone/GreenZone.js";
|
|
|
27
27
|
import "../PassengerCircle/PassengerCircle.js";
|
|
28
28
|
import "../PickupPoints/PickupPoints.js";
|
|
29
29
|
import "./useCacheCenterPlace.js";
|
|
30
|
-
import { B, f, D, E, R, c, a, e, b, d, Z } from "../../chunks/BusinessRecomendPlaceMap.
|
|
30
|
+
import { B, f, D, E, R, c, a, e, b, d, Z } from "../../chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
31
31
|
export {
|
|
32
32
|
B as BusinessRecomendPlaceMap,
|
|
33
33
|
f as BusinessRecomendPlaceMapInner,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B, f, D, E, R, c, a, e, b, d, Z } from "../../chunks/BusinessRecomendPlaceMap.
|
|
1
|
+
import { B, f, D, E, R, c, a, e, b, d, Z } from "../../chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
2
2
|
export {
|
|
3
3
|
B as BusinessRecomendPlaceMap,
|
|
4
4
|
f as BusinessRecomendPlaceMapInner,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { CoordinatePlace, Point } from "../../types/interface";
|
|
1
|
+
import type { CoordinatePlace, CoordinatePoint, Point } from "../../types/interface";
|
|
2
2
|
interface UseDefaultCenterPlaceProps {
|
|
3
3
|
emptyTitle: string;
|
|
4
4
|
geoLoadingTitle: string;
|
|
5
|
+
skipWaitGeo?: boolean | CoordinatePlace | CoordinatePoint;
|
|
5
6
|
defaultCenterPlace?: CoordinatePlace | ((place?: CoordinatePlace) => CoordinatePlace | undefined);
|
|
6
7
|
}
|
|
7
8
|
export declare const useCacheCenterPlace: (props: UseDefaultCenterPlaceProps) => {
|
|
@@ -3,13 +3,21 @@ import { apiGetCenterPlaceFromCache } from "../../api/browser.js";
|
|
|
3
3
|
import { apiMemoryShouldSkipByKey } from "../../api/memory.js";
|
|
4
4
|
import { useMapCoordinatify } from "../../hooks/useMapCoordinatify.js";
|
|
5
5
|
import { maybeFunctionToFunction, lnglat2point } from "../../utils/transform.js";
|
|
6
|
+
import { t as throttle } from "../../chunks/throttle.8bdd8d3b.js";
|
|
6
7
|
const IS_FIRST_LOAD_KEY = "IS_FIRST_LOAD_KEY";
|
|
8
|
+
const THROTTLE_TIME = 3e3;
|
|
9
|
+
const throttledApiMemoryShouldSkipByKey = throttle(apiMemoryShouldSkipByKey, THROTTLE_TIME, {
|
|
10
|
+
trailing: false
|
|
11
|
+
});
|
|
7
12
|
const useCacheCenterPlace = (props) => {
|
|
8
|
-
|
|
9
|
-
const
|
|
13
|
+
var _a;
|
|
14
|
+
const { geoLoadingTitle, emptyTitle, skipWaitGeo } = props;
|
|
15
|
+
const isAppFirstLoad = !throttledApiMemoryShouldSkipByKey(IS_FIRST_LOAD_KEY);
|
|
16
|
+
const isFirstLoadWithGps = isAppFirstLoad && !skipWaitGeo;
|
|
10
17
|
const getDefaultCenterPlace = maybeFunctionToFunction(props.defaultCenterPlace);
|
|
11
18
|
const { unCoordinatifyPlace } = useMapCoordinatify();
|
|
12
|
-
const
|
|
19
|
+
const inputSkipGeoPlace = typeof skipWaitGeo === "object" ? skipWaitGeo : void 0;
|
|
20
|
+
const inputDefaultCenterPlace = (_a = isAppFirstLoad ? inputSkipGeoPlace : void 0) != null ? _a : getDefaultCenterPlace == null ? void 0 : getDefaultCenterPlace(apiGetCenterPlaceFromCache());
|
|
13
21
|
const defaultCenterPlace = {
|
|
14
22
|
lng: 0,
|
|
15
23
|
lat: 0,
|
|
@@ -21,10 +29,10 @@ const useCacheCenterPlace = (props) => {
|
|
|
21
29
|
const centerPlace = reactive({
|
|
22
30
|
lng: defaultCenterPlace.lng,
|
|
23
31
|
lat: defaultCenterPlace.lat,
|
|
24
|
-
name:
|
|
25
|
-
displayName:
|
|
32
|
+
name: isFirstLoadWithGps ? geoLoadingTitle : defaultCenterPlace.name,
|
|
33
|
+
displayName: isFirstLoadWithGps ? geoLoadingTitle : defaultCenterPlace.displayName
|
|
26
34
|
});
|
|
27
|
-
return { isFirstLoad, centerPlace, geoDefaultPosition, defaultCenterPlace };
|
|
35
|
+
return { isFirstLoad: isFirstLoadWithGps, centerPlace, geoDefaultPosition, defaultCenterPlace };
|
|
28
36
|
};
|
|
29
37
|
export {
|
|
30
38
|
useCacheCenterPlace
|
|
@@ -21,7 +21,7 @@ import { detectBrowserPlatform } from "../../utils/platform.js";
|
|
|
21
21
|
import { place2point, isPlaceEqual, isZoneEqual, geoPositionError2businessTimeout, pipeDefer } from "../../utils/transform.js";
|
|
22
22
|
import { toCoordinatePlaceType, toCoordinatePointType, toCoordinateRecommendZonePlacesType } from "../../utils/typeChecking.js";
|
|
23
23
|
import { AbsoluteAddressBox } from "../AbsoluteAddressBox/AbsoluteAddressBox.js";
|
|
24
|
-
import { E as EMPTY_PLACE, m as memoize, R as RECOMMEND_PLACE_DRAG_LIMIT, a as RECOMMEND_PLACE_LARGE_LIMIT, b as RECOMMEND_PLACE_ZONE_ICON_MIN, c as RECOMMEND_PLACE_ICON_ZOOM_MIN, d as RECOMMEND_PLACE_ZONE_TEXT_MIN, e as RECOMMEND_PLACE_TEXT_ZOOM_MIN, D as DEFAULT_ZOOM, Z as ZONE_FITVIEW_PANDING } from "../../chunks/BusinessRecomendPlaceMap.
|
|
24
|
+
import { E as EMPTY_PLACE, m as memoize, R as RECOMMEND_PLACE_DRAG_LIMIT, a as RECOMMEND_PLACE_LARGE_LIMIT, b as RECOMMEND_PLACE_ZONE_ICON_MIN, c as RECOMMEND_PLACE_ICON_ZOOM_MIN, d as RECOMMEND_PLACE_ZONE_TEXT_MIN, e as RECOMMEND_PLACE_TEXT_ZOOM_MIN, D as DEFAULT_ZOOM, Z as ZONE_FITVIEW_PANDING } from "../../chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
25
25
|
import { DeviceOrientation } from "../DeviceOrientation/DeviceOrientation.js";
|
|
26
26
|
import { GreenZone } from "../GreenZone/GreenZone.js";
|
|
27
27
|
import { PassengerCircle } from "../PassengerCircle/PassengerCircle.js";
|
|
@@ -14,6 +14,7 @@ import { createAbortable, assertNotEmptyArray } from "../../utils/helper.js";
|
|
|
14
14
|
import { place2point, pipeDefer, lnglat2point } from "../../utils/transform.js";
|
|
15
15
|
import { toCoordinatePlaceType, toCoordinateTrackPoint } from "../../utils/typeChecking.js";
|
|
16
16
|
import { AuxiliaryGraspRoad } from "../AuxiliaryGraspRoad/AuxiliaryGraspRoad.js";
|
|
17
|
+
import { AuxiliaryPassanger } from "../AuxiliaryPassanger/AuxiliaryPassanger.js";
|
|
17
18
|
import { DeviceOrientation } from "../DeviceOrientation/DeviceOrientation.js";
|
|
18
19
|
import { SectionDispatching, SectionConfirmed, SectionDriverStartRelayService, SectionDriverStartService, SectionBookDispatched, SectionInService, SectionDriverArrived, SectionCanceled, SectionEndService } from "./BusinessTaxiServiceSection.js";
|
|
19
20
|
const STATUS_NEED_CAR_POSITION = ["book-driverStartService", "dispatched", "driverStartService", "driverStartRelayService", "inService", "driverArrived"];
|
|
@@ -247,6 +248,11 @@ const BusinessTaxiServiceMapInner = defineSetup("BusinessTaxiServiceMapInner", f
|
|
|
247
248
|
"from": from,
|
|
248
249
|
"to": to
|
|
249
250
|
}
|
|
251
|
+
}), IS_ENABLE_AUXILIARY_GRASP_ROAD && h(AuxiliaryPassanger, {
|
|
252
|
+
"attrs": {
|
|
253
|
+
"status": driverStatus,
|
|
254
|
+
"passengerPosition": passengerPosition
|
|
255
|
+
}
|
|
250
256
|
})]);
|
|
251
257
|
};
|
|
252
258
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h } from "vue";
|
|
2
2
|
import { apiGetAuxiliaryGrapStatus } from "../../api/browser.js";
|
|
3
|
-
import { MAX_DEVIATION_DISTANCE, CAR_DISTANCE_MIN } from "../../api/contants.js";
|
|
3
|
+
import { PASSENGER_DISTANCE_MAX, MAX_DEVIATION_DISTANCE, PASSENGER_DISTANCE_MIN, CAR_DISTANCE_MIN } from "../../api/contants.js";
|
|
4
4
|
import { useMapGeometry } from "../../hooks/useMapGeometry.js";
|
|
5
5
|
import { useMapSupplier } from "../../hooks/useMapSupplier.js";
|
|
6
6
|
import { defineSetup } from "../../types/helper.js";
|
|
@@ -19,8 +19,6 @@ import { WalkingLine } from "../WalkingLine/WalkingLine.js";
|
|
|
19
19
|
import { WalkingRoute } from "../WalkingRoute/WalkingRoute.js";
|
|
20
20
|
import { WaveCircle } from "../WaveCircle/WaveCircle.js";
|
|
21
21
|
const IS_ENABLE_AUXILIARY_GRASP_ROAD = apiGetAuxiliaryGrapStatus();
|
|
22
|
-
const PASSENGER_DISTANCE_MAX = 2e3;
|
|
23
|
-
const PASSENGER_DISTANCE_MIN = 20;
|
|
24
22
|
const AUTO_FIT_VIEW_INTERVAL = IS_ENABLE_AUXILIARY_GRASP_ROAD ? 24 * 3600 * 1e3 : 15e3;
|
|
25
23
|
const carDurationWithinMinDistance = (distance) => Math.floor(distance / 5);
|
|
26
24
|
const SectionDispatching = defineSetup("SectionDispatching", function(props) {
|
package/dist/v2/chunks/{BusinessRecomendPlaceMap.e9166e7d.js → BusinessRecomendPlaceMap.8a4a1015.js}
RENAMED
|
@@ -286,7 +286,8 @@ const BusinessRecomendPlaceMapInner = defineSetup("BusinessRecomendPlaceMapInner
|
|
|
286
286
|
geoErrorOnceNotificationKey = `BusinessRecomendPlaceMap_${Date.now()}`,
|
|
287
287
|
getAvailable: inputGetAvailable,
|
|
288
288
|
getRecomendPlace: inputGetRecomendPlace,
|
|
289
|
-
mapContext
|
|
289
|
+
mapContext,
|
|
290
|
+
skipWaitGeo
|
|
290
291
|
} = props;
|
|
291
292
|
const abortController = new AbortController();
|
|
292
293
|
const {
|
|
@@ -336,7 +337,8 @@ const BusinessRecomendPlaceMapInner = defineSetup("BusinessRecomendPlaceMapInner
|
|
|
336
337
|
} = useCacheCenterPlace({
|
|
337
338
|
defaultCenterPlace: props.defaultCenterPlace,
|
|
338
339
|
emptyTitle,
|
|
339
|
-
geoLoadingTitle
|
|
340
|
+
geoLoadingTitle,
|
|
341
|
+
skipWaitGeo
|
|
340
342
|
});
|
|
341
343
|
const centerSource = {
|
|
342
344
|
source: "default"
|
|
@@ -640,7 +642,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup("BusinessRecomendPlaceMap", f
|
|
|
640
642
|
key: `${payload.supplier}${instanceNo}`,
|
|
641
643
|
on: generateCreateElementV2PropsOn(props, emit, ["loadGeoLocation", "loadDefaultGeoLocation", "changeByDrag", "changeGeoLocation", "changePlace", "changeRecomandPlace", "geoError", "geoErrorOnce", "clickLocatorText", "clickLocatorPhoto"])
|
|
642
644
|
});
|
|
643
|
-
}).props(["log", "geoLoadingTitle", "emptyTitle", "queryingTitle", "defaultCenterPlace", "geoErrorOnceNotificationKey", "unavailableTitle", "forbiddenTitle", "recomendDescription", "disableLocator", "fallback", "getRecomendPlace", "getAvailable", "renderPlacePhoto", "renderPlaceTag", "loading", "mapContext"]);
|
|
645
|
+
}).props(["log", "geoLoadingTitle", "emptyTitle", "queryingTitle", "defaultCenterPlace", "skipWaitGeo", "geoErrorOnceNotificationKey", "unavailableTitle", "forbiddenTitle", "recomendDescription", "disableLocator", "fallback", "getRecomendPlace", "getAvailable", "renderPlacePhoto", "renderPlaceTag", "loading", "mapContext"]);
|
|
644
646
|
export {
|
|
645
647
|
BusinessRecomendPlaceMap as B,
|
|
646
648
|
DEFAULT_ZOOM as D,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Point } from "../types/interface";
|
|
2
2
|
export declare const apiLocalIsPointInRing: (point: Point, path: Point[]) => boolean;
|
|
3
3
|
export declare const useAmapGeometry: () => {
|
|
4
|
-
apiMapDistance: (from: Point, to: Point) => number
|
|
4
|
+
apiMapDistance: (from: Point, to: Point) => number;
|
|
5
5
|
apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
|
|
6
6
|
apiMapDistanceOfLine: (line: Point[]) => number | undefined;
|
|
7
7
|
};
|
|
8
8
|
export declare const useGmapGeometry: () => {
|
|
9
|
-
apiMapDistance: (from: Point, to: Point) => number
|
|
9
|
+
apiMapDistance: (from: Point, to: Point) => number;
|
|
10
10
|
apiMapDistanceToLine: (from: Point, line: Point[]) => 0 | undefined;
|
|
11
11
|
apiMapDistanceOfLine: (line: Point[]) => number | undefined;
|
|
12
12
|
};
|
|
13
13
|
export declare const useMapGeometry: () => {
|
|
14
|
-
apiMapDistance: (from: Point, to: Point) => number
|
|
14
|
+
apiMapDistance: (from: Point, to: Point) => number;
|
|
15
15
|
apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
|
|
16
16
|
apiMapDistanceOfLine: (line: Point[]) => number | undefined;
|
|
17
17
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pointInPolygon } from "../utils/geometryPolygon.js";
|
|
1
|
+
import { pointInPolygon, distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
|
|
2
2
|
import { vec2lnglat } from "../utils/transform.js";
|
|
3
3
|
import { Status } from "./useMapLoader.js";
|
|
4
4
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
@@ -7,7 +7,7 @@ const useAmapGeometry = () => {
|
|
|
7
7
|
const payload = useMapSupplier();
|
|
8
8
|
const apiMapDistance = (from, to) => {
|
|
9
9
|
if (payload.status !== Status.SUCCESS)
|
|
10
|
-
return
|
|
10
|
+
return distanceBetweenTwoPoints(from, to);
|
|
11
11
|
return AMap.GeometryUtil.distance(from, to);
|
|
12
12
|
};
|
|
13
13
|
const apiMapDistanceToLine = (from, line) => {
|
|
@@ -26,7 +26,7 @@ const useGmapGeometry = () => {
|
|
|
26
26
|
const payload = useMapSupplier();
|
|
27
27
|
const apiMapDistance = (from, to) => {
|
|
28
28
|
if (payload.status !== Status.SUCCESS)
|
|
29
|
-
return
|
|
29
|
+
return distanceBetweenTwoPoints(from, to);
|
|
30
30
|
return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
|
|
31
31
|
};
|
|
32
32
|
const apiMapDistanceToLine = (from, line) => {
|
|
@@ -549,7 +549,7 @@ var dist = {
|
|
|
549
549
|
});
|
|
550
550
|
})(dist);
|
|
551
551
|
const MIN_MAP_RELOAD_INTERVAL = 5e3;
|
|
552
|
-
const
|
|
552
|
+
const MIN_MAP_LOAD_RESET_THRESHOLD = 1e3;
|
|
553
553
|
const DEFAULT_AMAP_PLUGINS = [
|
|
554
554
|
"AMap.Geocoder",
|
|
555
555
|
"AMap.Driving",
|
|
@@ -608,7 +608,7 @@ const useAmapLoader = (props) => {
|
|
|
608
608
|
if (statusRef.value === "SUCCESS")
|
|
609
609
|
return Promise.resolve();
|
|
610
610
|
defineSecurityOnce();
|
|
611
|
-
distExports.reset();
|
|
611
|
+
throttledExecute(() => distExports.reset());
|
|
612
612
|
statusRef.value = "LOADING";
|
|
613
613
|
setTimeout(preloadAmapStyleOnce);
|
|
614
614
|
const startTime = Date.now();
|
|
@@ -651,7 +651,7 @@ const useAmapLoader = (props) => {
|
|
|
651
651
|
watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
|
|
652
652
|
return { statusRef, pingStatusRef, readyPromise };
|
|
653
653
|
};
|
|
654
|
-
const throttledExecute = throttle((fn) => fn(),
|
|
654
|
+
const throttledExecute = throttle((fn) => fn(), MIN_MAP_LOAD_RESET_THRESHOLD, {
|
|
655
655
|
trailing: false
|
|
656
656
|
});
|
|
657
657
|
const useGmapLoader = (props) => {
|
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
import { shallowRef } from "vue-demi";
|
|
2
|
+
import { MAX_DEVIATION_DISTANCE_WALKING } from "../api/contants.js";
|
|
2
3
|
import { watchPostEffectForDeepOption } from "../utils/compare.js";
|
|
3
4
|
import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
|
|
5
|
+
import { findClosestPointInLine } from "../utils/geometry.js";
|
|
6
|
+
import { distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
|
|
7
|
+
import { spaceLog } from "../utils/log.js";
|
|
8
|
+
import { createMemoizeWithTTL } from "../utils/ttlCache.js";
|
|
4
9
|
import { inTaiwan, inKorean } from "./useMapInChina.js";
|
|
5
10
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
11
|
+
const WALKING_ROUTE_CACHE_TTL = 30 * 60 * 1e3;
|
|
12
|
+
const findBestContinuation = (args, cacheEntries) => {
|
|
13
|
+
const [from, to] = args;
|
|
14
|
+
let bestPath;
|
|
15
|
+
for (const [[cacheFrom, cacheTo], path] of cacheEntries) {
|
|
16
|
+
if (!path || path.length < 2)
|
|
17
|
+
continue;
|
|
18
|
+
const deviationOfEndPoint = distanceBetweenTwoPoints(cacheTo, to);
|
|
19
|
+
if (deviationOfEndPoint > MAX_DEVIATION_DISTANCE_WALKING)
|
|
20
|
+
continue;
|
|
21
|
+
{
|
|
22
|
+
const { distance: deviationOfStartPoint } = findClosestPointInLine(
|
|
23
|
+
from,
|
|
24
|
+
[cacheFrom, ...path],
|
|
25
|
+
distanceBetweenTwoPoints
|
|
26
|
+
);
|
|
27
|
+
if (deviationOfStartPoint > MAX_DEVIATION_DISTANCE_WALKING)
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const { point: projectedPoint, index } = findClosestPointInLine(
|
|
31
|
+
from,
|
|
32
|
+
path,
|
|
33
|
+
distanceBetweenTwoPoints
|
|
34
|
+
);
|
|
35
|
+
const trimmedPath = [projectedPoint, ...path.slice(index + 1)];
|
|
36
|
+
if (trimmedPath.length < 2)
|
|
37
|
+
continue;
|
|
38
|
+
if (!bestPath || trimmedPath.length < bestPath.length) {
|
|
39
|
+
bestPath = trimmedPath;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return bestPath;
|
|
43
|
+
};
|
|
44
|
+
const memoizeAmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
|
|
45
|
+
const memoizeGmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
|
|
6
46
|
const useAWalkingRoute = (props) => {
|
|
7
47
|
const { googleRoutesProxyUrl } = useMapSupplier();
|
|
8
48
|
const pathRef = shallowRef([]);
|
|
9
49
|
const amapWalking = new AMap.Walking({});
|
|
10
|
-
const apiMapWalkingRoute = (from, to) => {
|
|
50
|
+
const apiMapWalkingRoute = memoizeAmapWalkingRoute((from, to) => {
|
|
51
|
+
spaceLog("apiMapWalkingRoute", `amap from = ${from} to = ${to}`);
|
|
11
52
|
return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
|
|
12
|
-
};
|
|
53
|
+
});
|
|
13
54
|
watchPostEffectForDeepOption(
|
|
14
55
|
() => {
|
|
15
56
|
const { from, to } = props;
|
|
@@ -27,11 +68,12 @@ const useGWalkingRoute = (props) => {
|
|
|
27
68
|
const { gaodeDirectionWalkingProxyUrl, googleRoutesProxyUrl } = useMapSupplier();
|
|
28
69
|
const pathRef = shallowRef([]);
|
|
29
70
|
const gmapDirectionsService = new google.maps.DirectionsService();
|
|
30
|
-
const apiMapWalkingRoute = (from, to) => {
|
|
71
|
+
const apiMapWalkingRoute = memoizeGmapWalkingRoute((from, to) => {
|
|
72
|
+
spaceLog("apiMapWalkingRoute", `gmap from = ${from} to = ${to}`);
|
|
31
73
|
if (inKorean(from))
|
|
32
74
|
return Promise.resolve([]);
|
|
33
75
|
return gaodeDirectionWalkingProxyUrl && inKorean(from) ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : googleRoutesProxyUrl ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : gmapJsApiWalkingRoute(from, to, gmapDirectionsService);
|
|
34
|
-
};
|
|
76
|
+
});
|
|
35
77
|
watchPostEffectForDeepOption(
|
|
36
78
|
() => {
|
|
37
79
|
const { from, to } = props;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reactive, ref, readonly } from "vue-demi";
|
|
2
|
-
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.
|
|
2
|
+
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
3
3
|
import { CenterPlaceStatus } from "../types/interface.js";
|
|
4
4
|
import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
|
|
5
5
|
const useBusinessRecomendPlaceMap = () => {
|
package/dist/v2/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import "./utils/alipayPolyfill.js";
|
|
|
2
2
|
import { isCoordinatePointEqual } from "./api/geometry.js";
|
|
3
3
|
import { AbsoluteAddressBox } from "./business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
|
|
4
4
|
import { BusinessQuotingMap } from "./business-components/BusinessQuotingMap/BusinessQuotingMap.js";
|
|
5
|
-
import { B } from "./chunks/BusinessRecomendPlaceMap.
|
|
5
|
+
import { B } from "./chunks/BusinessRecomendPlaceMap.8a4a1015.js";
|
|
6
6
|
import { BusinessReselectPlaceMap } from "./business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js";
|
|
7
7
|
import { BusinessTaxiEndMap } from "./business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js";
|
|
8
8
|
import { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js";
|
|
@@ -4,6 +4,7 @@ export declare const findClosestPointInSegment: (point: Point, segment: [Point,
|
|
|
4
4
|
export declare const findClosestPointInLine: (point: Point, path: Point[], distanceFn: DistanceFn) => {
|
|
5
5
|
point: Point;
|
|
6
6
|
distance: number;
|
|
7
|
+
index: number;
|
|
7
8
|
};
|
|
8
9
|
export declare const isPointInSegment: (point: Point, segment: [Point, Point]) => boolean;
|
|
9
10
|
export declare const isPointInHalfOpenSegment: (point: Point, segment: [Point, Point]) => boolean;
|
|
@@ -23,9 +23,10 @@ const findClosestPointInLine = (point, path, distanceFn) => {
|
|
|
23
23
|
var _a, _b;
|
|
24
24
|
let min = Infinity;
|
|
25
25
|
let target;
|
|
26
|
+
let idx;
|
|
26
27
|
assertPropNoEmptyArray(path, "findClosestPointInLine", "path");
|
|
27
28
|
if (path.length === 1)
|
|
28
|
-
return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0 };
|
|
29
|
+
return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0, index: 0 };
|
|
29
30
|
for (let index = 0; index < path.length - 1; index++) {
|
|
30
31
|
const closestPoint = findClosestPointInSegment(point, [path[index], path[index + 1]]);
|
|
31
32
|
const distance = (_b = distanceFn(point, closestPoint)) != null ? _b : 0;
|
|
@@ -33,8 +34,9 @@ const findClosestPointInLine = (point, path, distanceFn) => {
|
|
|
33
34
|
continue;
|
|
34
35
|
target = closestPoint;
|
|
35
36
|
min = distance;
|
|
37
|
+
idx = index;
|
|
36
38
|
}
|
|
37
|
-
return { point: target, distance: min };
|
|
39
|
+
return { point: target, distance: min, index: idx };
|
|
38
40
|
};
|
|
39
41
|
const floatEqual = (x1, x2) => {
|
|
40
42
|
return Math.abs(x1 - x2) < 1e4 * Number.EPSILON;
|
|
@@ -4,3 +4,8 @@ import type { Point } from "../types/interface";
|
|
|
4
4
|
* @returns 1 在内部, 0 边界上 , -1 在外部
|
|
5
5
|
*/
|
|
6
6
|
export declare function pointInPolygon(point: Point, polygon: Point[]): 1 | 0 | -1;
|
|
7
|
+
export declare const distanceBetweenTwoPoints: (from: Point, to: Point) => number;
|
|
8
|
+
/**
|
|
9
|
+
* 计算折线(按顺序连接各点)总长度。
|
|
10
|
+
*/
|
|
11
|
+
export declare const computeLineLength: (line: Point[]) => number;
|
|
@@ -22,6 +22,33 @@ function pointInPolygon(point, polygon) {
|
|
|
22
22
|
}
|
|
23
23
|
return inside ? 1 : -1;
|
|
24
24
|
}
|
|
25
|
+
const distanceBetweenTwoPoints = (from, to) => {
|
|
26
|
+
const [lng1, lat1] = from;
|
|
27
|
+
const [lng2, lat2] = to;
|
|
28
|
+
if (lng1 === lng2 && lat1 === lat2)
|
|
29
|
+
return 0;
|
|
30
|
+
const toRad = (deg) => deg * Math.PI / 180;
|
|
31
|
+
const R = 6378137;
|
|
32
|
+
const phi1 = toRad(lat1);
|
|
33
|
+
const phi2 = toRad(lat2);
|
|
34
|
+
const dPhi = toRad(lat2 - lat1);
|
|
35
|
+
const dLambda = toRad(lng2 - lng1);
|
|
36
|
+
const a = Math.sin(dPhi / 2) * Math.sin(dPhi / 2) + Math.cos(phi1) * Math.cos(phi2) * Math.sin(dLambda / 2) * Math.sin(dLambda / 2);
|
|
37
|
+
const c = 2 * Math.asin(Math.min(1, Math.sqrt(a)));
|
|
38
|
+
return R * c;
|
|
39
|
+
};
|
|
40
|
+
const computeLineLength = (line) => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!Array.isArray(line) || line.length < 2)
|
|
43
|
+
return 0;
|
|
44
|
+
let totalLength = 0;
|
|
45
|
+
for (let i = 1; i < line.length; i++) {
|
|
46
|
+
totalLength += (_a = distanceBetweenTwoPoints(line[i - 1], line[i])) != null ? _a : 0;
|
|
47
|
+
}
|
|
48
|
+
return totalLength;
|
|
49
|
+
};
|
|
25
50
|
export {
|
|
51
|
+
computeLineLength,
|
|
52
|
+
distanceBetweenTwoPoints,
|
|
26
53
|
pointInPolygon
|
|
27
54
|
};
|
package/dist/v2/utils/log.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
const availableLogKeys = /* @__PURE__ */ new Set();
|
|
2
2
|
const pkgName = "@heycar/heycars-map";
|
|
3
|
-
const pkgVersion = "2.
|
|
3
|
+
const pkgVersion = "2.14.0-walkOptimize2";
|
|
4
|
+
const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
|
|
5
|
+
const enableSessionLogKey = (key) => {
|
|
6
|
+
const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
|
|
7
|
+
sessionParam.set(`log-${key}`, "true");
|
|
8
|
+
sessionStorage.setItem(spaceLogSessionKey, sessionParam.toString());
|
|
9
|
+
};
|
|
4
10
|
const isEnableLog = (name) => {
|
|
5
11
|
const searchParam = new URLSearchParams(location.search);
|
|
6
|
-
|
|
12
|
+
const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
|
|
13
|
+
return searchParam.has(`log-${name}`) || sessionParam.has(`log-${name}`);
|
|
7
14
|
};
|
|
8
|
-
window.
|
|
15
|
+
window.heycarMapAvailableLogKeys = availableLogKeys;
|
|
16
|
+
window.heycarMapEnableSessionLogKey = enableSessionLogKey;
|
|
9
17
|
const spaceLog = (logKey, ...args) => {
|
|
10
18
|
availableLogKeys.add(logKey);
|
|
11
19
|
if (!isEnableLog(logKey))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Milliseconds = number;
|
|
2
|
+
export interface TTLCache<K, V> {
|
|
3
|
+
get(key: K): V | undefined;
|
|
4
|
+
set(key: K, value: V): void;
|
|
5
|
+
delete(key: K): boolean;
|
|
6
|
+
clear(): void;
|
|
7
|
+
entries(): IterableIterator<[K, V]>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 高性能 TTL Cache(固定 TTL,不支持动态变更)。
|
|
11
|
+
* - 仅提供最小接口:get/set/delete/clear/entries
|
|
12
|
+
* - 惰性过期:在访问时清理过期项,无额外定时器
|
|
13
|
+
*/
|
|
14
|
+
export declare function createTTLCache<K, V>(ttlMs: Milliseconds): TTLCache<K, V>;
|
|
15
|
+
/**
|
|
16
|
+
* 异步函数的 TTL 记忆化工厂
|
|
17
|
+
*
|
|
18
|
+
* 命中策略(按顺序):
|
|
19
|
+
* 1. 精确命中:用 `computeKey(args)` 查缓存。
|
|
20
|
+
* 2. 近似命中:用 `selectFromCache(args, entries)` 在当前有效条目中挑选。
|
|
21
|
+
* 3. 未命中:执行原函数,结果写入缓存。
|
|
22
|
+
*
|
|
23
|
+
* 过期策略:惰性按 `ttlMs` 过期;`ttlMs <= 0` 表示不缓存;传 `Infinity` 视为永不过期。
|
|
24
|
+
*
|
|
25
|
+
* 参数:
|
|
26
|
+
* - `ttlMs`:缓存有效期(毫秒)。
|
|
27
|
+
* - `selectFromCache`:近似命中选择器,入参为本次 `args` 与有效缓存条目的迭代器,返回命中值或 `undefined`。
|
|
28
|
+
* - `computeKey`:精确命中的 key 生成函数,默认 `JSON.stringify`。
|
|
29
|
+
*
|
|
30
|
+
* 返回:`memoize(fn)`,将异步函数包装为带缓存的版本。
|
|
31
|
+
*
|
|
32
|
+
* 说明:不做并发合并;仅实现 TTL 驱逐(无容量上限);近似匹配会遍历有效条目。
|
|
33
|
+
*/
|
|
34
|
+
export declare function createMemoizeWithTTL<A extends any[], R>(ttlMs: Milliseconds, selectFromCache: (args: A, cacheEntries: IterableIterator<[A, R]>) => R | undefined, computeKey?: (args: A) => string): (fn: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
|