@heycar/heycars-map 0.9.23-alpha1 → 0.9.23-alpha3
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/dist/index.cjs +151 -110
- package/dist/index.js +151 -110
- package/dist/src/hooks/useMapRecomendPlace.d.ts +0 -1
- package/dist/src/utils/QueryWxSignatureStatus.d.ts +10 -0
- package/dist/src/utils/helper.d.ts +2 -0
- package/dist/src/utils/mockWx.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ if (typeof GeolocationPositionError === "undefined") {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
const name = "@heycar/heycars-map";
|
|
22
|
-
const version = "0.9.23-
|
|
22
|
+
const version = "0.9.23-alpha3";
|
|
23
23
|
const type = "module";
|
|
24
24
|
const bin = {
|
|
25
25
|
checkVersion: "./bin/checkVersion.js"
|
|
@@ -1406,86 +1406,6 @@ createComparator(function() {
|
|
|
1406
1406
|
});
|
|
1407
1407
|
createComparator(createCircularEqualCreator());
|
|
1408
1408
|
createComparator(createCircularEqualCreator(sameValueZeroEqual));
|
|
1409
|
-
const isPlace = (place) => {
|
|
1410
|
-
return place.lng !== void 0 && place.lat !== void 0;
|
|
1411
|
-
};
|
|
1412
|
-
const sleep = (milliSeconds) => new Promise((resolve) => setTimeout(resolve, milliSeconds));
|
|
1413
|
-
function assertNotEmptyArray(value, name2) {
|
|
1414
|
-
if (Array.isArray(value) && value.length > 0)
|
|
1415
|
-
return;
|
|
1416
|
-
throw new Error(
|
|
1417
|
-
`Assertion Error: expect ${name2} to be not empty array, actual is ${JSON.stringify(value)}`
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
const isLatLngLiteral = (value) => {
|
|
1421
|
-
return value != null && typeof value === "object" && Number.isFinite(value.lat) && Number.isFinite(value.lng);
|
|
1422
|
-
};
|
|
1423
|
-
function defered() {
|
|
1424
|
-
const defer = {};
|
|
1425
|
-
const promise = new Promise((resolve, reject) => {
|
|
1426
|
-
defer.state = "pending";
|
|
1427
|
-
defer.resolve = async (value) => {
|
|
1428
|
-
try {
|
|
1429
|
-
const result = await value;
|
|
1430
|
-
defer.state = "fulfilled";
|
|
1431
|
-
return resolve(result);
|
|
1432
|
-
} catch (err) {
|
|
1433
|
-
defer.state = "rejected";
|
|
1434
|
-
reject(err);
|
|
1435
|
-
}
|
|
1436
|
-
};
|
|
1437
|
-
defer.reject = (reason) => {
|
|
1438
|
-
defer.state = "rejected";
|
|
1439
|
-
return reject(reason);
|
|
1440
|
-
};
|
|
1441
|
-
});
|
|
1442
|
-
return Object.assign(promise, defer);
|
|
1443
|
-
}
|
|
1444
|
-
const pausableSleep = (milliSeconds) => {
|
|
1445
|
-
const sleepDefered = defered();
|
|
1446
|
-
let id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1447
|
-
let isPaused = false;
|
|
1448
|
-
const pause = () => {
|
|
1449
|
-
if (isPaused || sleepDefered.state === "fulfilled")
|
|
1450
|
-
return;
|
|
1451
|
-
console.log("pause");
|
|
1452
|
-
isPaused = true;
|
|
1453
|
-
clearTimeout(id);
|
|
1454
|
-
};
|
|
1455
|
-
const restart = () => {
|
|
1456
|
-
if (sleepDefered.state === "fulfilled")
|
|
1457
|
-
return;
|
|
1458
|
-
console.log("restart");
|
|
1459
|
-
isPaused = false;
|
|
1460
|
-
clearTimeout(id);
|
|
1461
|
-
id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1462
|
-
};
|
|
1463
|
-
return { sleepPromise: sleepDefered, pause, restart };
|
|
1464
|
-
};
|
|
1465
|
-
const createRunOnce = (fn) => {
|
|
1466
|
-
let isExcuted = false;
|
|
1467
|
-
let result;
|
|
1468
|
-
return function runOnce(...args) {
|
|
1469
|
-
if (isExcuted)
|
|
1470
|
-
return result;
|
|
1471
|
-
isExcuted = true;
|
|
1472
|
-
result = fn(...args);
|
|
1473
|
-
return result;
|
|
1474
|
-
};
|
|
1475
|
-
};
|
|
1476
|
-
const createAsyncNoFailNonNullable = (fn, defaultValue) => {
|
|
1477
|
-
return function noFailNoNullable(...args) {
|
|
1478
|
-
return fn(...args).then((result) => result != null ? result : defaultValue).catch(() => defaultValue);
|
|
1479
|
-
};
|
|
1480
|
-
};
|
|
1481
|
-
const pipeTimeout = (fn, defaultValue, timeout) => {
|
|
1482
|
-
return function pipedTimeoutedFunction(...args) {
|
|
1483
|
-
return new Promise((resolve, reject) => {
|
|
1484
|
-
setTimeout(() => resolve(defaultValue), timeout);
|
|
1485
|
-
fn(...args).then(resolve).catch(reject);
|
|
1486
|
-
});
|
|
1487
|
-
};
|
|
1488
|
-
};
|
|
1489
1409
|
var BRWOSER_PLATFORM = /* @__PURE__ */ ((BRWOSER_PLATFORM2) => {
|
|
1490
1410
|
BRWOSER_PLATFORM2["WECHAT"] = "WECHAT";
|
|
1491
1411
|
BRWOSER_PLATFORM2["WECHAT_MINIPROGRAM"] = "WECHAT_MINIPROGRAM";
|
|
@@ -1794,6 +1714,89 @@ const geoPositionError2businessTimeout = (error, platform) => {
|
|
|
1794
1714
|
return platform !== BRWOSER_PLATFORM.WECHAT && platform !== BRWOSER_PLATFORM.WECHAT_MINIPROGRAM && error.code === GeolocationPositionError.TIMEOUT;
|
|
1795
1715
|
};
|
|
1796
1716
|
const businessCandidatesToAdsorptionPlace = (places) => places[0];
|
|
1717
|
+
const isPlace = (place) => {
|
|
1718
|
+
return place.lng !== void 0 && place.lat !== void 0;
|
|
1719
|
+
};
|
|
1720
|
+
const sleep = (milliSeconds) => new Promise((resolve) => setTimeout(resolve, milliSeconds));
|
|
1721
|
+
function assertNotEmptyArray(value, name2) {
|
|
1722
|
+
if (Array.isArray(value) && value.length > 0)
|
|
1723
|
+
return;
|
|
1724
|
+
throw new Error(
|
|
1725
|
+
`Assertion Error: expect ${name2} to be not empty array, actual is ${JSON.stringify(value)}`
|
|
1726
|
+
);
|
|
1727
|
+
}
|
|
1728
|
+
const isLatLngLiteral = (value) => {
|
|
1729
|
+
return value != null && typeof value === "object" && Number.isFinite(value.lat) && Number.isFinite(value.lng);
|
|
1730
|
+
};
|
|
1731
|
+
const isPlacesInclude = (places, place) => {
|
|
1732
|
+
return places.some((p) => isPlaceEqual(p, place));
|
|
1733
|
+
};
|
|
1734
|
+
function defered() {
|
|
1735
|
+
const defer = {};
|
|
1736
|
+
const promise = new Promise((resolve, reject) => {
|
|
1737
|
+
defer.state = "pending";
|
|
1738
|
+
defer.resolve = async (value) => {
|
|
1739
|
+
try {
|
|
1740
|
+
const result = await value;
|
|
1741
|
+
defer.state = "fulfilled";
|
|
1742
|
+
return resolve(result);
|
|
1743
|
+
} catch (err) {
|
|
1744
|
+
defer.state = "rejected";
|
|
1745
|
+
reject(err);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
defer.reject = (reason) => {
|
|
1749
|
+
defer.state = "rejected";
|
|
1750
|
+
return reject(reason);
|
|
1751
|
+
};
|
|
1752
|
+
});
|
|
1753
|
+
return Object.assign(promise, defer);
|
|
1754
|
+
}
|
|
1755
|
+
const pausableSleep = (milliSeconds) => {
|
|
1756
|
+
const sleepDefered = defered();
|
|
1757
|
+
let id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1758
|
+
let isPaused = false;
|
|
1759
|
+
const pause = () => {
|
|
1760
|
+
if (isPaused || sleepDefered.state === "fulfilled")
|
|
1761
|
+
return;
|
|
1762
|
+
console.log("pause");
|
|
1763
|
+
isPaused = true;
|
|
1764
|
+
clearTimeout(id);
|
|
1765
|
+
};
|
|
1766
|
+
const restart = () => {
|
|
1767
|
+
if (sleepDefered.state === "fulfilled")
|
|
1768
|
+
return;
|
|
1769
|
+
console.log("restart");
|
|
1770
|
+
isPaused = false;
|
|
1771
|
+
clearTimeout(id);
|
|
1772
|
+
id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1773
|
+
};
|
|
1774
|
+
return { sleepPromise: sleepDefered, pause, restart };
|
|
1775
|
+
};
|
|
1776
|
+
const createRunOnce = (fn) => {
|
|
1777
|
+
let isExcuted = false;
|
|
1778
|
+
let result;
|
|
1779
|
+
return function runOnce(...args) {
|
|
1780
|
+
if (isExcuted)
|
|
1781
|
+
return result;
|
|
1782
|
+
isExcuted = true;
|
|
1783
|
+
result = fn(...args);
|
|
1784
|
+
return result;
|
|
1785
|
+
};
|
|
1786
|
+
};
|
|
1787
|
+
const createAsyncNoFailNonNullable = (fn, defaultValue) => {
|
|
1788
|
+
return function noFailNoNullable(...args) {
|
|
1789
|
+
return fn(...args).then((result) => result != null ? result : defaultValue).catch(() => defaultValue);
|
|
1790
|
+
};
|
|
1791
|
+
};
|
|
1792
|
+
const pipeTimeout = (fn, defaultValue, timeout) => {
|
|
1793
|
+
return function pipedTimeoutedFunction(...args) {
|
|
1794
|
+
return new Promise((resolve, reject) => {
|
|
1795
|
+
setTimeout(() => resolve(defaultValue), timeout);
|
|
1796
|
+
fn(...args).then(resolve).catch(reject);
|
|
1797
|
+
});
|
|
1798
|
+
};
|
|
1799
|
+
};
|
|
1797
1800
|
const deepCompareEqualsForMaps = createComparator((deepEqual) => (a2, b) => {
|
|
1798
1801
|
if (isLatLngLiteral(a2) && isLatLngLiteral(b)) {
|
|
1799
1802
|
const result = isPlaceEqual(a2, b);
|
|
@@ -4444,11 +4447,41 @@ const watchVisibilityState = () => {
|
|
|
4444
4447
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
4445
4448
|
return { visibilityStateRef, unwatchVisibilityState };
|
|
4446
4449
|
};
|
|
4450
|
+
class QueryWxSignatureStatus {
|
|
4451
|
+
constructor(timeout) {
|
|
4452
|
+
__publicField(this, "error");
|
|
4453
|
+
__publicField(this, "timeout");
|
|
4454
|
+
__publicField(this, "status", "PENDING");
|
|
4455
|
+
__publicField(this, "pendingStatusPromise", new Promise((resolve, reject) => {
|
|
4456
|
+
wx == null ? void 0 : wx.ready(() => {
|
|
4457
|
+
this.status = "READY";
|
|
4458
|
+
resolve("READY");
|
|
4459
|
+
});
|
|
4460
|
+
wx == null ? void 0 : wx.error((error) => {
|
|
4461
|
+
this.status = "FAIL";
|
|
4462
|
+
this.error = error;
|
|
4463
|
+
reject(error);
|
|
4464
|
+
});
|
|
4465
|
+
setTimeout(() => {
|
|
4466
|
+
if (this.status !== "PENDING")
|
|
4467
|
+
return;
|
|
4468
|
+
this.status = "TIMEOUT";
|
|
4469
|
+
resolve("TIMEOUT");
|
|
4470
|
+
}, this.timeout);
|
|
4471
|
+
}));
|
|
4472
|
+
__publicField(this, "timoutStatusPromise", Promise.resolve("TIMEOUT"));
|
|
4473
|
+
this.timeout = timeout;
|
|
4474
|
+
}
|
|
4475
|
+
get statusPromise() {
|
|
4476
|
+
return this.status === "TIMEOUT" ? this.timoutStatusPromise : this.pendingStatusPromise;
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4447
4479
|
function createCustomGeolocationPositionError(message, code) {
|
|
4448
4480
|
const error = new Error(message);
|
|
4449
4481
|
error.code = code;
|
|
4450
4482
|
return error;
|
|
4451
4483
|
}
|
|
4484
|
+
const WX_SIGNATURE_TIMEOUT = 5e3;
|
|
4452
4485
|
const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4453
4486
|
const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4454
4487
|
const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
|
|
@@ -4458,10 +4491,6 @@ const takeIsForceBrowserGeo = () => {
|
|
|
4458
4491
|
const searchParam = new URLSearchParams(location.search);
|
|
4459
4492
|
return searchParam.has(`force-browser-geo`);
|
|
4460
4493
|
};
|
|
4461
|
-
const wxReady = () => new Promise((resolve, reject) => {
|
|
4462
|
-
wx.ready(resolve);
|
|
4463
|
-
wx.error(reject);
|
|
4464
|
-
});
|
|
4465
4494
|
function wechatWatchPosition(onSuccess, onError, option) {
|
|
4466
4495
|
const { timeout } = option;
|
|
4467
4496
|
let enable = true;
|
|
@@ -4469,25 +4498,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
4469
4498
|
let lastSuccessfulResponse = void 0;
|
|
4470
4499
|
let geoErrorMessage = void 0;
|
|
4471
4500
|
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
4501
|
+
const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
|
|
4502
|
+
console.warn("警告:微信签名超时");
|
|
4503
|
+
onError(error);
|
|
4504
|
+
});
|
|
4505
|
+
const onWxSignatureErrorOnce = createRunOnce((error) => {
|
|
4506
|
+
console.error("微信签名失败:", error);
|
|
4507
|
+
onError(error);
|
|
4508
|
+
});
|
|
4509
|
+
const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
|
|
4472
4510
|
const startWatch = async () => {
|
|
4473
|
-
try {
|
|
4474
|
-
await wxReady();
|
|
4475
|
-
} catch (err) {
|
|
4476
|
-
console.error(err);
|
|
4477
|
-
onError == null ? void 0 : onError(
|
|
4478
|
-
createCustomGeolocationPositionError(
|
|
4479
|
-
err.errMsg,
|
|
4480
|
-
// 签名失败,也算无权限的一种
|
|
4481
|
-
GeolocationPositionError.PERMISSION_DENIED
|
|
4482
|
-
)
|
|
4483
|
-
);
|
|
4484
|
-
return;
|
|
4485
|
-
}
|
|
4486
4511
|
do {
|
|
4487
4512
|
if (visibilityStateRef.value === "hidden") {
|
|
4488
4513
|
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4489
4514
|
continue;
|
|
4490
4515
|
}
|
|
4516
|
+
try {
|
|
4517
|
+
const status = await queryWxSignatureStatus.statusPromise;
|
|
4518
|
+
if (status === "TIMEOUT") {
|
|
4519
|
+
onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
|
|
4520
|
+
createCustomGeolocationPositionError(
|
|
4521
|
+
"Custom wx ready timeout",
|
|
4522
|
+
GeolocationPositionError.TIMEOUT
|
|
4523
|
+
)
|
|
4524
|
+
);
|
|
4525
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4526
|
+
continue;
|
|
4527
|
+
}
|
|
4528
|
+
} catch (err) {
|
|
4529
|
+
onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
|
|
4530
|
+
createCustomGeolocationPositionError(
|
|
4531
|
+
err.errMsg,
|
|
4532
|
+
// 签名失败,也算无权限的一种
|
|
4533
|
+
GeolocationPositionError.PERMISSION_DENIED
|
|
4534
|
+
)
|
|
4535
|
+
);
|
|
4536
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4537
|
+
continue;
|
|
4538
|
+
}
|
|
4491
4539
|
const geoPosition = await new Promise((resolve) => {
|
|
4492
4540
|
let isHandled = false;
|
|
4493
4541
|
wx.getLocation({
|
|
@@ -7262,12 +7310,6 @@ const useMapRecomendPlace = (props) => {
|
|
|
7262
7310
|
name: "",
|
|
7263
7311
|
displayName: ""
|
|
7264
7312
|
});
|
|
7265
|
-
const isElectedRef = Vue.computed(() => {
|
|
7266
|
-
const recomendPoint = place2point(recomendPlace);
|
|
7267
|
-
return placeCandidatesRef.value.some(
|
|
7268
|
-
(candidate) => isPointEqual(place2point(candidate), recomendPoint)
|
|
7269
|
-
);
|
|
7270
|
-
});
|
|
7271
7313
|
const isQueryingRef = Vue.ref(false);
|
|
7272
7314
|
const getRecomendPlaceNoFail = pipeTimeout(
|
|
7273
7315
|
createAsyncNoFailNonNullable(getRecomendPlace, {}),
|
|
@@ -7453,7 +7495,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
7453
7495
|
}) => {
|
|
7454
7496
|
const placeCandidates = inputPlaceCandidates == null ? void 0 : inputPlaceCandidates.map(toPlaceType);
|
|
7455
7497
|
availableRef.value = true;
|
|
7456
|
-
forceRef.value =
|
|
7498
|
+
forceRef.value = !!zone;
|
|
7457
7499
|
zoneRef.value = zone ? zone : void 0;
|
|
7458
7500
|
placeCandidatesRef.value = placeCandidates != null ? placeCandidates : [];
|
|
7459
7501
|
};
|
|
@@ -7463,7 +7505,6 @@ const useMapRecomendPlace = (props) => {
|
|
|
7463
7505
|
placeCandidates: placeCandidatesRef,
|
|
7464
7506
|
availableRef,
|
|
7465
7507
|
forceRef,
|
|
7466
|
-
isElectedRef,
|
|
7467
7508
|
isQueryingRef,
|
|
7468
7509
|
updateRecommendPlace,
|
|
7469
7510
|
updateRecommendPlaceOnlyInZone,
|
|
@@ -8514,7 +8555,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
8514
8555
|
placeCandidates,
|
|
8515
8556
|
zoneRef,
|
|
8516
8557
|
availableRef,
|
|
8517
|
-
isElectedRef,
|
|
8518
8558
|
isQueryingRef
|
|
8519
8559
|
} = useMapRecomendPlace({
|
|
8520
8560
|
defaultPoint: place2point(centerPlace),
|
|
@@ -8583,8 +8623,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
8583
8623
|
disableLocator,
|
|
8584
8624
|
disableLocatorPhoto
|
|
8585
8625
|
} = props;
|
|
8626
|
+
const isElected = isPlacesInclude(placeCandidates.value, centerPlace);
|
|
8586
8627
|
const title = geoLoading.value ? geoLoadingTitle2 : !availableRef.value ? unavailableTitle : centerPlace.displayName;
|
|
8587
|
-
const description = !availableRef.value ? void 0 :
|
|
8628
|
+
const description = !availableRef.value ? void 0 : isElected ? recomendDescription : void 0;
|
|
8588
8629
|
return Vue.h(HeycarMap, {
|
|
8589
8630
|
"attrs": {
|
|
8590
8631
|
"center": place2point(centerPlace),
|
|
@@ -8769,7 +8810,6 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
|
|
|
8769
8810
|
placeCandidates,
|
|
8770
8811
|
zoneRef,
|
|
8771
8812
|
availableRef,
|
|
8772
|
-
isElectedRef,
|
|
8773
8813
|
isQueryingRef
|
|
8774
8814
|
} = useMapRecomendPlace({
|
|
8775
8815
|
defaultPoint: place2point(centerPlace),
|
|
@@ -8835,8 +8875,9 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
|
|
|
8835
8875
|
unavailableTitle,
|
|
8836
8876
|
disableLocatorPhoto
|
|
8837
8877
|
} = props;
|
|
8878
|
+
const isElected = isPlacesInclude(placeCandidates.value, centerPlace);
|
|
8838
8879
|
const title = !availableRef.value ? unavailableTitle : centerPlace.displayName;
|
|
8839
|
-
const description = !availableRef.value ? void 0 :
|
|
8880
|
+
const description = !availableRef.value ? void 0 : isElected ? recomendDescription : void 0;
|
|
8840
8881
|
return Vue.h(HeycarMap, {
|
|
8841
8882
|
"attrs": {
|
|
8842
8883
|
"center": place2point(centerPlace),
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ if (typeof GeolocationPositionError === "undefined") {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const name = "@heycar/heycars-map";
|
|
20
|
-
const version = "0.9.23-
|
|
20
|
+
const version = "0.9.23-alpha3";
|
|
21
21
|
const type = "module";
|
|
22
22
|
const bin = {
|
|
23
23
|
checkVersion: "./bin/checkVersion.js"
|
|
@@ -1404,86 +1404,6 @@ createComparator(function() {
|
|
|
1404
1404
|
});
|
|
1405
1405
|
createComparator(createCircularEqualCreator());
|
|
1406
1406
|
createComparator(createCircularEqualCreator(sameValueZeroEqual));
|
|
1407
|
-
const isPlace = (place) => {
|
|
1408
|
-
return place.lng !== void 0 && place.lat !== void 0;
|
|
1409
|
-
};
|
|
1410
|
-
const sleep = (milliSeconds) => new Promise((resolve) => setTimeout(resolve, milliSeconds));
|
|
1411
|
-
function assertNotEmptyArray(value, name2) {
|
|
1412
|
-
if (Array.isArray(value) && value.length > 0)
|
|
1413
|
-
return;
|
|
1414
|
-
throw new Error(
|
|
1415
|
-
`Assertion Error: expect ${name2} to be not empty array, actual is ${JSON.stringify(value)}`
|
|
1416
|
-
);
|
|
1417
|
-
}
|
|
1418
|
-
const isLatLngLiteral = (value) => {
|
|
1419
|
-
return value != null && typeof value === "object" && Number.isFinite(value.lat) && Number.isFinite(value.lng);
|
|
1420
|
-
};
|
|
1421
|
-
function defered() {
|
|
1422
|
-
const defer = {};
|
|
1423
|
-
const promise = new Promise((resolve, reject) => {
|
|
1424
|
-
defer.state = "pending";
|
|
1425
|
-
defer.resolve = async (value) => {
|
|
1426
|
-
try {
|
|
1427
|
-
const result = await value;
|
|
1428
|
-
defer.state = "fulfilled";
|
|
1429
|
-
return resolve(result);
|
|
1430
|
-
} catch (err) {
|
|
1431
|
-
defer.state = "rejected";
|
|
1432
|
-
reject(err);
|
|
1433
|
-
}
|
|
1434
|
-
};
|
|
1435
|
-
defer.reject = (reason) => {
|
|
1436
|
-
defer.state = "rejected";
|
|
1437
|
-
return reject(reason);
|
|
1438
|
-
};
|
|
1439
|
-
});
|
|
1440
|
-
return Object.assign(promise, defer);
|
|
1441
|
-
}
|
|
1442
|
-
const pausableSleep = (milliSeconds) => {
|
|
1443
|
-
const sleepDefered = defered();
|
|
1444
|
-
let id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1445
|
-
let isPaused = false;
|
|
1446
|
-
const pause = () => {
|
|
1447
|
-
if (isPaused || sleepDefered.state === "fulfilled")
|
|
1448
|
-
return;
|
|
1449
|
-
console.log("pause");
|
|
1450
|
-
isPaused = true;
|
|
1451
|
-
clearTimeout(id);
|
|
1452
|
-
};
|
|
1453
|
-
const restart = () => {
|
|
1454
|
-
if (sleepDefered.state === "fulfilled")
|
|
1455
|
-
return;
|
|
1456
|
-
console.log("restart");
|
|
1457
|
-
isPaused = false;
|
|
1458
|
-
clearTimeout(id);
|
|
1459
|
-
id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1460
|
-
};
|
|
1461
|
-
return { sleepPromise: sleepDefered, pause, restart };
|
|
1462
|
-
};
|
|
1463
|
-
const createRunOnce = (fn) => {
|
|
1464
|
-
let isExcuted = false;
|
|
1465
|
-
let result;
|
|
1466
|
-
return function runOnce(...args) {
|
|
1467
|
-
if (isExcuted)
|
|
1468
|
-
return result;
|
|
1469
|
-
isExcuted = true;
|
|
1470
|
-
result = fn(...args);
|
|
1471
|
-
return result;
|
|
1472
|
-
};
|
|
1473
|
-
};
|
|
1474
|
-
const createAsyncNoFailNonNullable = (fn, defaultValue) => {
|
|
1475
|
-
return function noFailNoNullable(...args) {
|
|
1476
|
-
return fn(...args).then((result) => result != null ? result : defaultValue).catch(() => defaultValue);
|
|
1477
|
-
};
|
|
1478
|
-
};
|
|
1479
|
-
const pipeTimeout = (fn, defaultValue, timeout) => {
|
|
1480
|
-
return function pipedTimeoutedFunction(...args) {
|
|
1481
|
-
return new Promise((resolve, reject) => {
|
|
1482
|
-
setTimeout(() => resolve(defaultValue), timeout);
|
|
1483
|
-
fn(...args).then(resolve).catch(reject);
|
|
1484
|
-
});
|
|
1485
|
-
};
|
|
1486
|
-
};
|
|
1487
1407
|
var BRWOSER_PLATFORM = /* @__PURE__ */ ((BRWOSER_PLATFORM2) => {
|
|
1488
1408
|
BRWOSER_PLATFORM2["WECHAT"] = "WECHAT";
|
|
1489
1409
|
BRWOSER_PLATFORM2["WECHAT_MINIPROGRAM"] = "WECHAT_MINIPROGRAM";
|
|
@@ -1792,6 +1712,89 @@ const geoPositionError2businessTimeout = (error, platform) => {
|
|
|
1792
1712
|
return platform !== BRWOSER_PLATFORM.WECHAT && platform !== BRWOSER_PLATFORM.WECHAT_MINIPROGRAM && error.code === GeolocationPositionError.TIMEOUT;
|
|
1793
1713
|
};
|
|
1794
1714
|
const businessCandidatesToAdsorptionPlace = (places) => places[0];
|
|
1715
|
+
const isPlace = (place) => {
|
|
1716
|
+
return place.lng !== void 0 && place.lat !== void 0;
|
|
1717
|
+
};
|
|
1718
|
+
const sleep = (milliSeconds) => new Promise((resolve) => setTimeout(resolve, milliSeconds));
|
|
1719
|
+
function assertNotEmptyArray(value, name2) {
|
|
1720
|
+
if (Array.isArray(value) && value.length > 0)
|
|
1721
|
+
return;
|
|
1722
|
+
throw new Error(
|
|
1723
|
+
`Assertion Error: expect ${name2} to be not empty array, actual is ${JSON.stringify(value)}`
|
|
1724
|
+
);
|
|
1725
|
+
}
|
|
1726
|
+
const isLatLngLiteral = (value) => {
|
|
1727
|
+
return value != null && typeof value === "object" && Number.isFinite(value.lat) && Number.isFinite(value.lng);
|
|
1728
|
+
};
|
|
1729
|
+
const isPlacesInclude = (places, place) => {
|
|
1730
|
+
return places.some((p) => isPlaceEqual(p, place));
|
|
1731
|
+
};
|
|
1732
|
+
function defered() {
|
|
1733
|
+
const defer = {};
|
|
1734
|
+
const promise = new Promise((resolve, reject) => {
|
|
1735
|
+
defer.state = "pending";
|
|
1736
|
+
defer.resolve = async (value) => {
|
|
1737
|
+
try {
|
|
1738
|
+
const result = await value;
|
|
1739
|
+
defer.state = "fulfilled";
|
|
1740
|
+
return resolve(result);
|
|
1741
|
+
} catch (err) {
|
|
1742
|
+
defer.state = "rejected";
|
|
1743
|
+
reject(err);
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
defer.reject = (reason) => {
|
|
1747
|
+
defer.state = "rejected";
|
|
1748
|
+
return reject(reason);
|
|
1749
|
+
};
|
|
1750
|
+
});
|
|
1751
|
+
return Object.assign(promise, defer);
|
|
1752
|
+
}
|
|
1753
|
+
const pausableSleep = (milliSeconds) => {
|
|
1754
|
+
const sleepDefered = defered();
|
|
1755
|
+
let id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1756
|
+
let isPaused = false;
|
|
1757
|
+
const pause = () => {
|
|
1758
|
+
if (isPaused || sleepDefered.state === "fulfilled")
|
|
1759
|
+
return;
|
|
1760
|
+
console.log("pause");
|
|
1761
|
+
isPaused = true;
|
|
1762
|
+
clearTimeout(id);
|
|
1763
|
+
};
|
|
1764
|
+
const restart = () => {
|
|
1765
|
+
if (sleepDefered.state === "fulfilled")
|
|
1766
|
+
return;
|
|
1767
|
+
console.log("restart");
|
|
1768
|
+
isPaused = false;
|
|
1769
|
+
clearTimeout(id);
|
|
1770
|
+
id = setTimeout(sleepDefered.resolve, milliSeconds);
|
|
1771
|
+
};
|
|
1772
|
+
return { sleepPromise: sleepDefered, pause, restart };
|
|
1773
|
+
};
|
|
1774
|
+
const createRunOnce = (fn) => {
|
|
1775
|
+
let isExcuted = false;
|
|
1776
|
+
let result;
|
|
1777
|
+
return function runOnce(...args) {
|
|
1778
|
+
if (isExcuted)
|
|
1779
|
+
return result;
|
|
1780
|
+
isExcuted = true;
|
|
1781
|
+
result = fn(...args);
|
|
1782
|
+
return result;
|
|
1783
|
+
};
|
|
1784
|
+
};
|
|
1785
|
+
const createAsyncNoFailNonNullable = (fn, defaultValue) => {
|
|
1786
|
+
return function noFailNoNullable(...args) {
|
|
1787
|
+
return fn(...args).then((result) => result != null ? result : defaultValue).catch(() => defaultValue);
|
|
1788
|
+
};
|
|
1789
|
+
};
|
|
1790
|
+
const pipeTimeout = (fn, defaultValue, timeout) => {
|
|
1791
|
+
return function pipedTimeoutedFunction(...args) {
|
|
1792
|
+
return new Promise((resolve, reject) => {
|
|
1793
|
+
setTimeout(() => resolve(defaultValue), timeout);
|
|
1794
|
+
fn(...args).then(resolve).catch(reject);
|
|
1795
|
+
});
|
|
1796
|
+
};
|
|
1797
|
+
};
|
|
1795
1798
|
const deepCompareEqualsForMaps = createComparator((deepEqual) => (a2, b) => {
|
|
1796
1799
|
if (isLatLngLiteral(a2) && isLatLngLiteral(b)) {
|
|
1797
1800
|
const result = isPlaceEqual(a2, b);
|
|
@@ -4442,11 +4445,41 @@ const watchVisibilityState = () => {
|
|
|
4442
4445
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
4443
4446
|
return { visibilityStateRef, unwatchVisibilityState };
|
|
4444
4447
|
};
|
|
4448
|
+
class QueryWxSignatureStatus {
|
|
4449
|
+
constructor(timeout) {
|
|
4450
|
+
__publicField(this, "error");
|
|
4451
|
+
__publicField(this, "timeout");
|
|
4452
|
+
__publicField(this, "status", "PENDING");
|
|
4453
|
+
__publicField(this, "pendingStatusPromise", new Promise((resolve, reject) => {
|
|
4454
|
+
wx == null ? void 0 : wx.ready(() => {
|
|
4455
|
+
this.status = "READY";
|
|
4456
|
+
resolve("READY");
|
|
4457
|
+
});
|
|
4458
|
+
wx == null ? void 0 : wx.error((error) => {
|
|
4459
|
+
this.status = "FAIL";
|
|
4460
|
+
this.error = error;
|
|
4461
|
+
reject(error);
|
|
4462
|
+
});
|
|
4463
|
+
setTimeout(() => {
|
|
4464
|
+
if (this.status !== "PENDING")
|
|
4465
|
+
return;
|
|
4466
|
+
this.status = "TIMEOUT";
|
|
4467
|
+
resolve("TIMEOUT");
|
|
4468
|
+
}, this.timeout);
|
|
4469
|
+
}));
|
|
4470
|
+
__publicField(this, "timoutStatusPromise", Promise.resolve("TIMEOUT"));
|
|
4471
|
+
this.timeout = timeout;
|
|
4472
|
+
}
|
|
4473
|
+
get statusPromise() {
|
|
4474
|
+
return this.status === "TIMEOUT" ? this.timoutStatusPromise : this.pendingStatusPromise;
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4445
4477
|
function createCustomGeolocationPositionError(message, code) {
|
|
4446
4478
|
const error = new Error(message);
|
|
4447
4479
|
error.code = code;
|
|
4448
4480
|
return error;
|
|
4449
4481
|
}
|
|
4482
|
+
const WX_SIGNATURE_TIMEOUT = 5e3;
|
|
4450
4483
|
const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4451
4484
|
const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4452
4485
|
const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
|
|
@@ -4456,10 +4489,6 @@ const takeIsForceBrowserGeo = () => {
|
|
|
4456
4489
|
const searchParam = new URLSearchParams(location.search);
|
|
4457
4490
|
return searchParam.has(`force-browser-geo`);
|
|
4458
4491
|
};
|
|
4459
|
-
const wxReady = () => new Promise((resolve, reject) => {
|
|
4460
|
-
wx.ready(resolve);
|
|
4461
|
-
wx.error(reject);
|
|
4462
|
-
});
|
|
4463
4492
|
function wechatWatchPosition(onSuccess, onError, option) {
|
|
4464
4493
|
const { timeout } = option;
|
|
4465
4494
|
let enable = true;
|
|
@@ -4467,25 +4496,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
4467
4496
|
let lastSuccessfulResponse = void 0;
|
|
4468
4497
|
let geoErrorMessage = void 0;
|
|
4469
4498
|
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
4499
|
+
const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
|
|
4500
|
+
console.warn("警告:微信签名超时");
|
|
4501
|
+
onError(error);
|
|
4502
|
+
});
|
|
4503
|
+
const onWxSignatureErrorOnce = createRunOnce((error) => {
|
|
4504
|
+
console.error("微信签名失败:", error);
|
|
4505
|
+
onError(error);
|
|
4506
|
+
});
|
|
4507
|
+
const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
|
|
4470
4508
|
const startWatch = async () => {
|
|
4471
|
-
try {
|
|
4472
|
-
await wxReady();
|
|
4473
|
-
} catch (err) {
|
|
4474
|
-
console.error(err);
|
|
4475
|
-
onError == null ? void 0 : onError(
|
|
4476
|
-
createCustomGeolocationPositionError(
|
|
4477
|
-
err.errMsg,
|
|
4478
|
-
// 签名失败,也算无权限的一种
|
|
4479
|
-
GeolocationPositionError.PERMISSION_DENIED
|
|
4480
|
-
)
|
|
4481
|
-
);
|
|
4482
|
-
return;
|
|
4483
|
-
}
|
|
4484
4509
|
do {
|
|
4485
4510
|
if (visibilityStateRef.value === "hidden") {
|
|
4486
4511
|
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4487
4512
|
continue;
|
|
4488
4513
|
}
|
|
4514
|
+
try {
|
|
4515
|
+
const status = await queryWxSignatureStatus.statusPromise;
|
|
4516
|
+
if (status === "TIMEOUT") {
|
|
4517
|
+
onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
|
|
4518
|
+
createCustomGeolocationPositionError(
|
|
4519
|
+
"Custom wx ready timeout",
|
|
4520
|
+
GeolocationPositionError.TIMEOUT
|
|
4521
|
+
)
|
|
4522
|
+
);
|
|
4523
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4524
|
+
continue;
|
|
4525
|
+
}
|
|
4526
|
+
} catch (err) {
|
|
4527
|
+
onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
|
|
4528
|
+
createCustomGeolocationPositionError(
|
|
4529
|
+
err.errMsg,
|
|
4530
|
+
// 签名失败,也算无权限的一种
|
|
4531
|
+
GeolocationPositionError.PERMISSION_DENIED
|
|
4532
|
+
)
|
|
4533
|
+
);
|
|
4534
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4535
|
+
continue;
|
|
4536
|
+
}
|
|
4489
4537
|
const geoPosition = await new Promise((resolve) => {
|
|
4490
4538
|
let isHandled = false;
|
|
4491
4539
|
wx.getLocation({
|
|
@@ -7260,12 +7308,6 @@ const useMapRecomendPlace = (props) => {
|
|
|
7260
7308
|
name: "",
|
|
7261
7309
|
displayName: ""
|
|
7262
7310
|
});
|
|
7263
|
-
const isElectedRef = computed(() => {
|
|
7264
|
-
const recomendPoint = place2point(recomendPlace);
|
|
7265
|
-
return placeCandidatesRef.value.some(
|
|
7266
|
-
(candidate) => isPointEqual(place2point(candidate), recomendPoint)
|
|
7267
|
-
);
|
|
7268
|
-
});
|
|
7269
7311
|
const isQueryingRef = ref(false);
|
|
7270
7312
|
const getRecomendPlaceNoFail = pipeTimeout(
|
|
7271
7313
|
createAsyncNoFailNonNullable(getRecomendPlace, {}),
|
|
@@ -7451,7 +7493,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
7451
7493
|
}) => {
|
|
7452
7494
|
const placeCandidates = inputPlaceCandidates == null ? void 0 : inputPlaceCandidates.map(toPlaceType);
|
|
7453
7495
|
availableRef.value = true;
|
|
7454
|
-
forceRef.value =
|
|
7496
|
+
forceRef.value = !!zone;
|
|
7455
7497
|
zoneRef.value = zone ? zone : void 0;
|
|
7456
7498
|
placeCandidatesRef.value = placeCandidates != null ? placeCandidates : [];
|
|
7457
7499
|
};
|
|
@@ -7461,7 +7503,6 @@ const useMapRecomendPlace = (props) => {
|
|
|
7461
7503
|
placeCandidates: placeCandidatesRef,
|
|
7462
7504
|
availableRef,
|
|
7463
7505
|
forceRef,
|
|
7464
|
-
isElectedRef,
|
|
7465
7506
|
isQueryingRef,
|
|
7466
7507
|
updateRecommendPlace,
|
|
7467
7508
|
updateRecommendPlaceOnlyInZone,
|
|
@@ -8512,7 +8553,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
8512
8553
|
placeCandidates,
|
|
8513
8554
|
zoneRef,
|
|
8514
8555
|
availableRef,
|
|
8515
|
-
isElectedRef,
|
|
8516
8556
|
isQueryingRef
|
|
8517
8557
|
} = useMapRecomendPlace({
|
|
8518
8558
|
defaultPoint: place2point(centerPlace),
|
|
@@ -8581,8 +8621,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
8581
8621
|
disableLocator,
|
|
8582
8622
|
disableLocatorPhoto
|
|
8583
8623
|
} = props;
|
|
8624
|
+
const isElected = isPlacesInclude(placeCandidates.value, centerPlace);
|
|
8584
8625
|
const title = geoLoading.value ? geoLoadingTitle2 : !availableRef.value ? unavailableTitle : centerPlace.displayName;
|
|
8585
|
-
const description = !availableRef.value ? void 0 :
|
|
8626
|
+
const description = !availableRef.value ? void 0 : isElected ? recomendDescription : void 0;
|
|
8586
8627
|
return h(HeycarMap, {
|
|
8587
8628
|
"attrs": {
|
|
8588
8629
|
"center": place2point(centerPlace),
|
|
@@ -8767,7 +8808,6 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
|
|
|
8767
8808
|
placeCandidates,
|
|
8768
8809
|
zoneRef,
|
|
8769
8810
|
availableRef,
|
|
8770
|
-
isElectedRef,
|
|
8771
8811
|
isQueryingRef
|
|
8772
8812
|
} = useMapRecomendPlace({
|
|
8773
8813
|
defaultPoint: place2point(centerPlace),
|
|
@@ -8833,8 +8873,9 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
|
|
|
8833
8873
|
unavailableTitle,
|
|
8834
8874
|
disableLocatorPhoto
|
|
8835
8875
|
} = props;
|
|
8876
|
+
const isElected = isPlacesInclude(placeCandidates.value, centerPlace);
|
|
8836
8877
|
const title = !availableRef.value ? unavailableTitle : centerPlace.displayName;
|
|
8837
|
-
const description = !availableRef.value ? void 0 :
|
|
8878
|
+
const description = !availableRef.value ? void 0 : isElected ? recomendDescription : void 0;
|
|
8838
8879
|
return h(HeycarMap, {
|
|
8839
8880
|
"attrs": {
|
|
8840
8881
|
"center": place2point(centerPlace),
|
|
@@ -35,7 +35,6 @@ export declare const useMapRecomendPlace: <C>(props: UseMapRecomendPlaceProps<C>
|
|
|
35
35
|
}[]>;
|
|
36
36
|
availableRef: import("vue-demi").Ref<boolean>;
|
|
37
37
|
forceRef: import("vue-demi").Ref<boolean>;
|
|
38
|
-
isElectedRef: import("vue-demi").ComputedRef<boolean>;
|
|
39
38
|
isQueryingRef: import("vue-demi").Ref<boolean>;
|
|
40
39
|
updateRecommendPlace: (place: Place) => Promise<void>;
|
|
41
40
|
updateRecommendPlaceOnlyInZone: (place: Place) => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type WxSignatureStatus = "PENDING" | "READY" | "TIMEOUT" | "FAIL";
|
|
2
|
+
export declare class QueryWxSignatureStatus {
|
|
3
|
+
private error;
|
|
4
|
+
private timeout;
|
|
5
|
+
private status;
|
|
6
|
+
private pendingStatusPromise;
|
|
7
|
+
private timoutStatusPromise;
|
|
8
|
+
constructor(timeout: number);
|
|
9
|
+
get statusPromise(): Promise<WxSignatureStatus>;
|
|
10
|
+
}
|
|
@@ -6,6 +6,7 @@ export declare function assertAngle(angle: unknown): asserts angle is number | u
|
|
|
6
6
|
export declare function assertZone(zone: any): asserts zone is Zone;
|
|
7
7
|
export declare function assertNotEmptyArray(value: unknown, name: string): void;
|
|
8
8
|
export declare const isLatLngLiteral: (value: any) => boolean;
|
|
9
|
+
export declare const isPlacesInclude: (places: Place[], place: Place) => boolean;
|
|
9
10
|
interface Defered<T> extends Promise<T> {
|
|
10
11
|
state: "pending" | "fulfilled" | "rejected";
|
|
11
12
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
@@ -24,4 +25,5 @@ export declare const pausableSleep: (milliSeconds: number) => {
|
|
|
24
25
|
export declare const createRunOnce: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => R;
|
|
25
26
|
export declare const createAsyncNoFailNonNullable: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: NonNullable<R>) => (...args: P) => Promise<NonNullable<R>>;
|
|
26
27
|
export declare const pipeTimeout: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: R, timeout: number) => (...args: P) => Promise<R>;
|
|
28
|
+
export declare const retryUntilSuccess: <P extends any[], R>(fn: (...args: P) => Promise<R>) => (...args: P) => Promise<R>;
|
|
27
29
|
export {};
|