feat(还车): 拿不到定位时静默兜底,不再弹「三选一」问用户
用户口径:还车/锁车这块不要打断人去选,按地图中心或找个停车点直接还就行。
改法
- getOrderOperationLocation() 改为自动兜底链,全程不问用户:
navigator.geolocation(WGS84,直接用)
→ 页面上的「我」标记(BD09 → GCJ02 → WGS84,位置最贴近用户)
→ 地图中心(BD09 → WGS84)
→ 校园中心(/api/config 的 center_lat/lng,GCJ02 → WGS84)
→ 都没有才返回 null 并中止(仍不伪造 36.67/116.98 这类魔数)
- 走兜底时只给一条 toast:「定位不可用,已用地图中心上报位置」,不阻塞操作
- 删除弹窗相关代码:askOperationLocation / settleOperationLocation /
chooseGeoRetry / chooseGeoMapCenter / cancelGeoChoice 及其状态与超时常量;
templates/map.html 的 #geo-choice-modal 整块、compat/globals.ts 的 3 个 window 挂载
- map/core.ts:校园中心同时镜像到 S.campusCenter(getCampusCenter 会回读 S),
让「地图没加载出来」这条兜底链可测、现场可在控制台看到
测试
- test_ux_p0_rental_return.cjs 的 UX-04 三条改写为新口径:
· 无定位 → 静默用地图中心(校验 BD09→WGS84 数值、source=map-center、toast 有提示)
· 地图没就绪 → 退校园中心(source=campus-center)
· 都没有 → 返回 null 且不发还车请求
- 全量 238 pytest + 43 node 全绿
- 浏览器实测(390px,禁用 geolocation):DOM 里没有 #geo-choice-modal,
window.chooseGeo* 已不存在;取坐标返回 {lat 36.53198, lng 116.77749, source map-center},
toast「定位不可用,已用地图中心上报位置」,JS 异常 0
This commit is contained in:
@@ -14,7 +14,7 @@ import { createFullIcon, getBikeIcon, getBikeKind, getBikeState, makeIconDataURI
|
|||||||
import { bindMarkerDomTouch, bindMarkerTap, bringMarkerToTop, clearHighlight, findMarkerById, rebuildMarkersForZoom, renderMap, setHighlight, setupClusterListener } from "../map/markers";
|
import { bindMarkerDomTouch, bindMarkerTap, bringMarkerToTop, clearHighlight, findMarkerById, rebuildMarkersForZoom, renderMap, setHighlight, setupClusterListener } from "../map/markers";
|
||||||
import { _applyHeading, _applyRoute, _bearing, _bindCompass, _centerOnUser, _clearNavArrow, _clearNavLayers, _destIcon, _ensureCompassPermission, _gpsToGcj, _haversineM, _markProgrammaticMove, _navArrowIcon, _navBanner, _navBtnText, _navGuidance, _navPill, _navTick, _onMapDragEnd, _onMapDragStart, _onMapDragging, _placeNavArrow, _projectOnRoute, _recomputeRoute, _redrawRoute, _requestNavRoute, _rotateByAnimation, _rotateNavArrow, _scheduleResume, _setTurnIcon, _turnKind, _turnSvg, bindNavMapEvents, resumeNavigation, startNavigation, stopNavigation, toggleNavigation } from "../nav/navigation";
|
import { _applyHeading, _applyRoute, _bearing, _bindCompass, _centerOnUser, _clearNavArrow, _clearNavLayers, _destIcon, _ensureCompassPermission, _gpsToGcj, _haversineM, _markProgrammaticMove, _navArrowIcon, _navBanner, _navBtnText, _navGuidance, _navPill, _navTick, _onMapDragEnd, _onMapDragStart, _onMapDragging, _placeNavArrow, _projectOnRoute, _recomputeRoute, _redrawRoute, _requestNavRoute, _rotateByAnimation, _rotateNavArrow, _scheduleResume, _setTurnIcon, _turnKind, _turnSvg, bindNavMapEvents, resumeNavigation, startNavigation, stopNavigation, toggleNavigation } from "../nav/navigation";
|
||||||
import { parseWalkDistance, parseWalkDuration, refineWalkRoute } from "../nav/walk-route";
|
import { parseWalkDistance, parseWalkDuration, refineWalkRoute } from "../nav/walk-route";
|
||||||
import { _doFindBikeRequest, _onPageUnload, _onVisibilityChange, addRoundForCurrent, addRoundFromBanner, cancelGeoChoice, checkRentalStatus, chooseGeoMapCenter, chooseGeoRetry, chooseUnlockSrc, clearRentalState, closeAddRoundModal, closeBellModal, closeLostModal, closeOrderTrajModal, closeOrdersModal, closeRentalSettingsModal, closeReturnConfirm, closeReturnModal, closeUnlockConfirm, closeUnlockSrc, confirmAddRound, confirmReturn, disableLostMode, doReturnBike, doUnlockBike, enableLostMode, findBike, getFilteredBikes, getOrderOperationLocation, handleQuickUnlock, isNativeShell, loadUnlockPreview, loadUnlockSrcShowAll, nativeUnlockBike, openOrderTrajectory, openOrdersModal, openRentalSettingsModal, openUnlockAccountChooser, proceedToUnlockConfirm, quickUnlock, rentalIsRealOrder, renderOrderTrajectory, renderUnlockPreview, renderUnlockSrcList, saveRentalSettings, scanCode, selectRadius, showAddRoundConfirm, showBellPasswordModal, showLostModal, showRentalBar, showRentalReturn, showReturnConfirm, showReturnModal, startRental, startRentalFromServer, submitBellPassword, switchBellTab, syncWechatOrder, tempLockCurrentOrder, tempUnlockCurrentOrder, toggleStatusFilter, tryCardPayOrRedirect, unlockBike, updateFilterInfo, updateRangeCircle, updateRentalCountdown, updateRentalFinalTime, updateStatusCounts, useCenterLocation, useCurrentLocation } from "../order/actions";
|
import { _doFindBikeRequest, _onPageUnload, _onVisibilityChange, addRoundForCurrent, addRoundFromBanner, checkRentalStatus, chooseUnlockSrc, clearRentalState, closeAddRoundModal, closeBellModal, closeLostModal, closeOrderTrajModal, closeOrdersModal, closeRentalSettingsModal, closeReturnConfirm, closeReturnModal, closeUnlockConfirm, closeUnlockSrc, confirmAddRound, confirmReturn, disableLostMode, doReturnBike, doUnlockBike, enableLostMode, findBike, getFilteredBikes, getOrderOperationLocation, handleQuickUnlock, isNativeShell, loadUnlockPreview, loadUnlockSrcShowAll, nativeUnlockBike, openOrderTrajectory, openOrdersModal, openRentalSettingsModal, openUnlockAccountChooser, proceedToUnlockConfirm, quickUnlock, rentalIsRealOrder, renderOrderTrajectory, renderUnlockPreview, renderUnlockSrcList, saveRentalSettings, scanCode, selectRadius, showAddRoundConfirm, showBellPasswordModal, showLostModal, showRentalBar, showRentalReturn, showReturnConfirm, showReturnModal, startRental, startRentalFromServer, submitBellPassword, switchBellTab, syncWechatOrder, tempLockCurrentOrder, tempUnlockCurrentOrder, toggleStatusFilter, tryCardPayOrRedirect, unlockBike, updateFilterInfo, updateRangeCircle, updateRentalCountdown, updateRentalFinalTime, updateStatusCounts, useCenterLocation, useCurrentLocation } from "../order/actions";
|
||||||
import { _alertOrderExpiring, checkOrderStatus, closeOrderActionsModal, fetchOrderCountdown, findCurrentOrderBike, handleOrderBannerClick, handleOrderBannerSurfaceClick, hideOrderBanner, hideOrderCountdown, isOrderActionEligible, orderCardHtml, payCurrentOrderFromModal, returnCurrentOrderFromModal, showOrderActionsModal, showOrderBanner, showOrderCountdown, startOrderCountdown, updateOrderCountdownText } from "../order/status";
|
import { _alertOrderExpiring, checkOrderStatus, closeOrderActionsModal, fetchOrderCountdown, findCurrentOrderBike, handleOrderBannerClick, handleOrderBannerSurfaceClick, hideOrderBanner, hideOrderCountdown, isOrderActionEligible, orderCardHtml, payCurrentOrderFromModal, returnCurrentOrderFromModal, showOrderActionsModal, showOrderBanner, showOrderCountdown, startOrderCountdown, updateOrderCountdownText } from "../order/status";
|
||||||
import { acceptCurrentShareAsk, acceptShareRequest, checkPendingShareRequests, closeShareConfig, closeShareModal, closeShareRemark, closeShareReturnModal, confirmShareReturn, loadShareData, nextShareAskIfQueue, openShareConfig, openShareModal, openShareRemark, openShareReturnByIdx, partnerLabel, refreshShareBanners, rejectCurrentShareAsk, rejectShareRequest, saveShareConfig, saveShareRemark, sendShareRequest, sharePendingHtml, switchShareTab, unbindShare, updateShareCountdowns } from "../share/share";
|
import { acceptCurrentShareAsk, acceptShareRequest, checkPendingShareRequests, closeShareConfig, closeShareModal, closeShareRemark, closeShareReturnModal, confirmShareReturn, loadShareData, nextShareAskIfQueue, openShareConfig, openShareModal, openShareRemark, openShareReturnByIdx, partnerLabel, refreshShareBanners, rejectCurrentShareAsk, rejectShareRequest, saveShareConfig, saveShareRemark, sendShareRequest, sharePendingHtml, switchShareTab, unbindShare, updateShareCountdowns } from "../share/share";
|
||||||
import { addSubscribeRule, closeSubscribeModal, deleteSubscribeRule, loadSubscribeLocations, loadSubscribeRules, openSubscribeModal, subRuleRowHtml, toggleSubAdvanced, toggleSubscribeRule } from "../subscribe/subscribe";
|
import { addSubscribeRule, closeSubscribeModal, deleteSubscribeRule, loadSubscribeLocations, loadSubscribeRules, openSubscribeModal, subRuleRowHtml, toggleSubAdvanced, toggleSubscribeRule } from "../subscribe/subscribe";
|
||||||
@@ -79,10 +79,7 @@ window.checkOrderStatus = checkOrderStatus;
|
|||||||
window.checkPendingShareRequests = checkPendingShareRequests;
|
window.checkPendingShareRequests = checkPendingShareRequests;
|
||||||
window.checkRentalStatus = checkRentalStatus;
|
window.checkRentalStatus = checkRentalStatus;
|
||||||
window.checkStrictGuide = checkStrictGuide;
|
window.checkStrictGuide = checkStrictGuide;
|
||||||
window.chooseGeoMapCenter = chooseGeoMapCenter;
|
|
||||||
window.chooseGeoRetry = chooseGeoRetry;
|
|
||||||
window.chooseUnlockSrc = chooseUnlockSrc;
|
window.chooseUnlockSrc = chooseUnlockSrc;
|
||||||
window.cancelGeoChoice = cancelGeoChoice;
|
|
||||||
window.clearHighlight = clearHighlight;
|
window.clearHighlight = clearHighlight;
|
||||||
window.clearRentalState = clearRentalState;
|
window.clearRentalState = clearRentalState;
|
||||||
window.closeAddRoundModal = closeAddRoundModal;
|
window.closeAddRoundModal = closeAddRoundModal;
|
||||||
|
|||||||
+4
-1
@@ -43,11 +43,14 @@ export function setCampusCenter(lat: any, lng: any) {
|
|||||||
const la = Number(lat), ln = Number(lng);
|
const la = Number(lat), ln = Number(lng);
|
||||||
if (Number.isFinite(la) && Number.isFinite(ln) && la !== 0 && ln !== 0) {
|
if (Number.isFinite(la) && Number.isFinite(ln) && la !== 0 && ln !== 0) {
|
||||||
campusCenter = { lat: la, lng: ln };
|
campusCenter = { lat: la, lng: ln };
|
||||||
|
// 同时镜像到全局 state:迁到 TS 后所有可变状态都该能在 S 里看到,
|
||||||
|
// 也让"地图没加载出来时用校园中心兜底"这条链可测、可现场排查。
|
||||||
|
(S as any).campusCenter = campusCenter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCampusCenter() {
|
export function getCampusCenter() {
|
||||||
return campusCenter;
|
return campusCenter || ((S as any).campusCenter ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 拿校园中心(GCJ02);没有缓存就现取一次 /api/config。拿不到返回 null。 */
|
/** 拿校园中心(GCJ02);没有缓存就现取一次 /api/config。拿不到返回 null。 */
|
||||||
|
|||||||
+37
-61
@@ -477,10 +477,7 @@ export interface OperationLocation {
|
|||||||
|
|
||||||
const GEO_TIMEOUT_MS = 5000;
|
const GEO_TIMEOUT_MS = 5000;
|
||||||
// 弹窗挂着等用户选,最长等这么久;超时按「取消」处理,绝不替用户伪造一个坐标
|
// 弹窗挂着等用户选,最长等这么久;超时按「取消」处理,绝不替用户伪造一个坐标
|
||||||
const GEO_CHOICE_TIMEOUT_MS = 45000;
|
|
||||||
|
|
||||||
let pendingOperationLocation: ((value: OperationLocation | null) => void) | null = null;
|
let pendingOperationLocation: ((value: OperationLocation | null) => void) | null = null;
|
||||||
let pendingLocationTimer: any = null;
|
|
||||||
|
|
||||||
/** 读浏览器当前位置(WGS84)。不支持/拒绝/超时都返回 null,不抛错。 */
|
/** 读浏览器当前位置(WGS84)。不支持/拒绝/超时都返回 null,不抛错。 */
|
||||||
function readBrowserPosition(): Promise<GeolocationPosition | null> {
|
function readBrowserPosition(): Promise<GeolocationPosition | null> {
|
||||||
@@ -563,62 +560,10 @@ export async function locationFromCampusCenter(): Promise<OperationLocation | nu
|
|||||||
return { latitude: w.lat, longitude: w.lng, source: "campus-center" };
|
return { latitude: w.lat, longitude: w.lng, source: "campus-center" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function settleOperationLocation(value: OperationLocation | null) {
|
|
||||||
const modal = document.getElementById("geo-choice-modal");
|
|
||||||
if (modal) modal.classList.remove("show");
|
|
||||||
if (pendingLocationTimer) {
|
|
||||||
clearTimeout(pendingLocationTimer);
|
|
||||||
pendingLocationTimer = null;
|
|
||||||
}
|
|
||||||
const resolve = pendingOperationLocation;
|
|
||||||
pendingOperationLocation = null;
|
|
||||||
if (resolve) resolve(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 拿不到定位时弹「怎么办」三选一,等用户选。关掉/超时 = 放弃(返回 null)。 */
|
|
||||||
function askOperationLocation(): Promise<OperationLocation | null> {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const modal = document.getElementById("geo-choice-modal");
|
|
||||||
if (!modal) { resolve(null); return; } // 模板里没有这个弹窗:直接放弃,不硬发坐标
|
|
||||||
if (pendingOperationLocation) {
|
|
||||||
const stale = pendingOperationLocation;
|
|
||||||
pendingOperationLocation = null;
|
|
||||||
stale(null); // 上一次挂起的请求先结掉,避免按钮卡在「…中」
|
|
||||||
}
|
|
||||||
pendingOperationLocation = resolve;
|
|
||||||
modal.classList.add("show");
|
|
||||||
pendingLocationTimer = setTimeout(() => settleOperationLocation(null), GEO_CHOICE_TIMEOUT_MS);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 弹窗①:去开定位 → 再试一次 */
|
|
||||||
export async function chooseGeoRetry() {
|
|
||||||
showToast("正在重新获取定位…");
|
|
||||||
const pos = await readBrowserPosition();
|
|
||||||
const lat = Number(pos && pos.coords && pos.coords.latitude);
|
|
||||||
const lng = Number(pos && pos.coords && pos.coords.longitude);
|
|
||||||
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
|
||||||
settleOperationLocation({ latitude: lat, longitude: lng, source: "gps" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showToast("还是拿不到定位:请到系统设置里允许本页面获取位置");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 弹窗②:用地图中心(地图没就绪就退到校园中心) */
|
|
||||||
export async function chooseGeoMapCenter() {
|
|
||||||
const loc = locationFromMapCenter() || (await locationFromCampusCenter());
|
|
||||||
if (loc) { settleOperationLocation(loc); return; }
|
|
||||||
showToast("地图还没就绪,稍后再试");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 弹窗③:取消 —— 操作整体中止 */
|
|
||||||
export function cancelGeoChoice() {
|
|
||||||
settleOperationLocation(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取「本次操作要上报的坐标」。拿不到定位时**不伪造**:
|
* 取「本次操作要上报的坐标」。拿不到浏览器定位时**不再问用户**:
|
||||||
* 弹三选一让用户决定,选「取消」返回 null,调用方必须中止本次还车/锁车。
|
* 按 「我」标记 → 地图中心 → 校园中心 的顺序自动兜底(统一转成 WGS84 上报,
|
||||||
|
* 后端还有候选点链兜底),绝不伪造 36.67/116.98 这种魔数。
|
||||||
*/
|
*/
|
||||||
export async function getOrderOperationLocation(): Promise<OperationLocation | null> {
|
export async function getOrderOperationLocation(): Promise<OperationLocation | null> {
|
||||||
const pos = await readBrowserPosition();
|
const pos = await readBrowserPosition();
|
||||||
@@ -629,9 +574,40 @@ export async function getOrderOperationLocation(): Promise<OperationLocation | n
|
|||||||
return { latitude: lat, longitude: lng, source: "gps" };
|
return { latitude: lat, longitude: lng, source: "gps" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const chosen = await askOperationLocation();
|
|
||||||
if (chosen) return chosen;
|
// 1) 页面上的「我」标记(BD09 → WGS84):定位过/导航过就有,位置最贴近用户
|
||||||
console.warn("[定位] 未取得可用坐标,操作中止(不提交伪造坐标)");
|
try {
|
||||||
|
const marker = S.autoLocationMarker
|
||||||
|
&& typeof (S.autoLocationMarker as any).getPosition === "function"
|
||||||
|
? (S.autoLocationMarker as any).getPosition() : null;
|
||||||
|
if (marker) {
|
||||||
|
const w = bd09ToWgs84(marker.lat, marker.lng);
|
||||||
|
if (w) {
|
||||||
|
console.info("[定位] 浏览器定位不可用,用页面上的「我」标记(BD09→WGS84)");
|
||||||
|
return { latitude: w.lat, longitude: w.lng, source: "map-center" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[定位] 读「我」标记失败:", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) 地图中心(BD09 → WGS84)
|
||||||
|
const mapCenter = locationFromMapCenter();
|
||||||
|
if (mapCenter) {
|
||||||
|
console.info("[定位] 浏览器定位不可用,用地图中心上报");
|
||||||
|
showToast("定位不可用,已用地图中心上报位置");
|
||||||
|
return mapCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) 校园中心(GCJ02 → WGS84,来自 /api/config)
|
||||||
|
const campus = await locationFromCampusCenter();
|
||||||
|
if (campus) {
|
||||||
|
console.info("[定位] 地图也没就绪,用校园中心上报");
|
||||||
|
showToast("定位不可用,已用校园中心上报位置");
|
||||||
|
return campus;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn("[定位] 地图与校园中心均不可用,操作中止(不提交伪造坐标)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+28
-60
@@ -2332,9 +2332,6 @@
|
|||||||
var returnLoading = false;
|
var returnLoading = false;
|
||||||
var pendingReturnOrder = null;
|
var pendingReturnOrder = null;
|
||||||
var GEO_TIMEOUT_MS = 5e3;
|
var GEO_TIMEOUT_MS = 5e3;
|
||||||
var GEO_CHOICE_TIMEOUT_MS = 45e3;
|
|
||||||
var pendingOperationLocation = null;
|
|
||||||
var pendingLocationTimer = null;
|
|
||||||
function readBrowserPosition() {
|
function readBrowserPosition() {
|
||||||
if (!navigator.geolocation || !navigator.geolocation.getCurrentPosition) {
|
if (!navigator.geolocation || !navigator.geolocation.getCurrentPosition) {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
@@ -2404,56 +2401,6 @@
|
|||||||
if (!w) return null;
|
if (!w) return null;
|
||||||
return { latitude: w.lat, longitude: w.lng, source: "campus-center" };
|
return { latitude: w.lat, longitude: w.lng, source: "campus-center" };
|
||||||
}
|
}
|
||||||
function settleOperationLocation(value) {
|
|
||||||
const modal = document.getElementById("geo-choice-modal");
|
|
||||||
if (modal) modal.classList.remove("show");
|
|
||||||
if (pendingLocationTimer) {
|
|
||||||
clearTimeout(pendingLocationTimer);
|
|
||||||
pendingLocationTimer = null;
|
|
||||||
}
|
|
||||||
const resolve = pendingOperationLocation;
|
|
||||||
pendingOperationLocation = null;
|
|
||||||
if (resolve) resolve(value);
|
|
||||||
}
|
|
||||||
function askOperationLocation() {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const modal = document.getElementById("geo-choice-modal");
|
|
||||||
if (!modal) {
|
|
||||||
resolve(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pendingOperationLocation) {
|
|
||||||
const stale = pendingOperationLocation;
|
|
||||||
pendingOperationLocation = null;
|
|
||||||
stale(null);
|
|
||||||
}
|
|
||||||
pendingOperationLocation = resolve;
|
|
||||||
modal.classList.add("show");
|
|
||||||
pendingLocationTimer = setTimeout(() => settleOperationLocation(null), GEO_CHOICE_TIMEOUT_MS);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
async function chooseGeoRetry() {
|
|
||||||
showToast("正在重新获取定位…");
|
|
||||||
const pos = await readBrowserPosition();
|
|
||||||
const lat = Number(pos && pos.coords && pos.coords.latitude);
|
|
||||||
const lng = Number(pos && pos.coords && pos.coords.longitude);
|
|
||||||
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
|
||||||
settleOperationLocation({ latitude: lat, longitude: lng, source: "gps" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showToast("还是拿不到定位:请到系统设置里允许本页面获取位置");
|
|
||||||
}
|
|
||||||
async function chooseGeoMapCenter() {
|
|
||||||
const loc = locationFromMapCenter() || await locationFromCampusCenter();
|
|
||||||
if (loc) {
|
|
||||||
settleOperationLocation(loc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showToast("地图还没就绪,稍后再试");
|
|
||||||
}
|
|
||||||
function cancelGeoChoice() {
|
|
||||||
settleOperationLocation(null);
|
|
||||||
}
|
|
||||||
async function getOrderOperationLocation() {
|
async function getOrderOperationLocation() {
|
||||||
const pos = await readBrowserPosition();
|
const pos = await readBrowserPosition();
|
||||||
if (pos) {
|
if (pos) {
|
||||||
@@ -2463,9 +2410,31 @@
|
|||||||
return { latitude: lat, longitude: lng, source: "gps" };
|
return { latitude: lat, longitude: lng, source: "gps" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const chosen = await askOperationLocation();
|
try {
|
||||||
if (chosen) return chosen;
|
const marker = S.autoLocationMarker && typeof S.autoLocationMarker.getPosition === "function" ? S.autoLocationMarker.getPosition() : null;
|
||||||
console.warn("[定位] 未取得可用坐标,操作中止(不提交伪造坐标)");
|
if (marker) {
|
||||||
|
const w = bd09ToWgs84(marker.lat, marker.lng);
|
||||||
|
if (w) {
|
||||||
|
console.info("[定位] 浏览器定位不可用,用页面上的「我」标记(BD09→WGS84)");
|
||||||
|
return { latitude: w.lat, longitude: w.lng, source: "map-center" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[定位] 读「我」标记失败:", err);
|
||||||
|
}
|
||||||
|
const mapCenter = locationFromMapCenter();
|
||||||
|
if (mapCenter) {
|
||||||
|
console.info("[定位] 浏览器定位不可用,用地图中心上报");
|
||||||
|
showToast("定位不可用,已用地图中心上报位置");
|
||||||
|
return mapCenter;
|
||||||
|
}
|
||||||
|
const campus = await locationFromCampusCenter();
|
||||||
|
if (campus) {
|
||||||
|
console.info("[定位] 地图也没就绪,用校园中心上报");
|
||||||
|
showToast("定位不可用,已用校园中心上报位置");
|
||||||
|
return campus;
|
||||||
|
}
|
||||||
|
console.warn("[定位] 地图与校园中心均不可用,操作中止(不提交伪造坐标)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
function showReturnConfirm() {
|
function showReturnConfirm() {
|
||||||
@@ -4722,10 +4691,12 @@
|
|||||||
const la = Number(lat), ln = Number(lng);
|
const la = Number(lat), ln = Number(lng);
|
||||||
if (Number.isFinite(la) && Number.isFinite(ln) && la !== 0 && ln !== 0) {
|
if (Number.isFinite(la) && Number.isFinite(ln) && la !== 0 && ln !== 0) {
|
||||||
campusCenter = { lat: la, lng: ln };
|
campusCenter = { lat: la, lng: ln };
|
||||||
|
S.campusCenter = campusCenter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getCampusCenter() {
|
function getCampusCenter() {
|
||||||
return campusCenter;
|
var _a;
|
||||||
|
return campusCenter || ((_a = S.campusCenter) != null ? _a : null);
|
||||||
}
|
}
|
||||||
async function loadCampusCenter() {
|
async function loadCampusCenter() {
|
||||||
if (campusCenter) return campusCenter;
|
if (campusCenter) return campusCenter;
|
||||||
@@ -5873,10 +5844,7 @@
|
|||||||
window.checkPendingShareRequests = checkPendingShareRequests;
|
window.checkPendingShareRequests = checkPendingShareRequests;
|
||||||
window.checkRentalStatus = checkRentalStatus;
|
window.checkRentalStatus = checkRentalStatus;
|
||||||
window.checkStrictGuide = checkStrictGuide;
|
window.checkStrictGuide = checkStrictGuide;
|
||||||
window.chooseGeoMapCenter = chooseGeoMapCenter;
|
|
||||||
window.chooseGeoRetry = chooseGeoRetry;
|
|
||||||
window.chooseUnlockSrc = chooseUnlockSrc;
|
window.chooseUnlockSrc = chooseUnlockSrc;
|
||||||
window.cancelGeoChoice = cancelGeoChoice;
|
|
||||||
window.clearHighlight = clearHighlight;
|
window.clearHighlight = clearHighlight;
|
||||||
window.clearRentalState = clearRentalState;
|
window.clearRentalState = clearRentalState;
|
||||||
window.closeAddRoundModal = closeAddRoundModal;
|
window.closeAddRoundModal = closeAddRoundModal;
|
||||||
|
|||||||
+1
-20
@@ -729,26 +729,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 拿不到定位时的三选一(UX-04):绝不替用户伪造一个坐标去还车/锁车 -->
|
|
||||||
<div class="auth-modal" id="geo-choice-modal">
|
|
||||||
<div class="auth-overlay" onclick="cancelGeoChoice()"></div>
|
|
||||||
<div class="auth-content">
|
|
||||||
<div class="auth-header">
|
|
||||||
<span>拿不到你的位置</span>
|
|
||||||
<button class="auth-close" onclick="cancelGeoChoice()" aria-label="关闭">✕</button>
|
|
||||||
</div>
|
|
||||||
<div class="share-desc">
|
|
||||||
还车和锁车都要把当前位置报给车辆服务。没有定位就直接提交,服务端多半判「不在停车区」,
|
|
||||||
所以这里不猜位置,交给你选:
|
|
||||||
</div>
|
|
||||||
<button class="auth-submit" onclick="chooseGeoRetry()">① 去开定位,再试一次</button>
|
|
||||||
<button class="auth-submit ghost" style="margin-top:10px;" onclick="chooseGeoMapCenter()">② 用地图中心点代替</button>
|
|
||||||
<button class="auth-submit ghost" style="margin-top:10px;" onclick="cancelGeoChoice()">③ 取消这次操作</button>
|
|
||||||
<div class="devices-tip" style="margin-top:12px;">
|
|
||||||
开启定位:手机「设置」→「隐私 / 位置信息」→ 找到浏览器或微信 → 允许定位,回来点①。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 车辆详情遮罩 -->
|
<!-- 车辆详情遮罩 -->
|
||||||
<div class="card-overlay" id="card-overlay" onclick="closeCard()"></div>
|
<div class="card-overlay" id="card-overlay" onclick="closeCard()"></div>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
* UX-02 startRentalFromServer 之后 #rental-bar 真的带 show 类,且只注册一个倒计时定时器
|
* UX-02 startRentalFromServer 之后 #rental-bar 真的带 show 类,且只注册一个倒计时定时器
|
||||||
* UX-03 真实微信订单:showRentalReturn/doReturnBike 走 /api/order/return,绝不请求 /api/rental/return;
|
* UX-03 真实微信订单:showRentalReturn/doReturnBike 走 /api/order/return,绝不请求 /api/rental/return;
|
||||||
* reminder 纯计时单才走 /api/rental/return;confirmReturn 对真实订单有本地防御
|
* reminder 纯计时单才走 /api/rental/return;confirmReturn 对真实订单有本地防御
|
||||||
* UX-04 geolocation 不可用时不产生 36.67/116.98 坐标:要么弹三选一、要么中止(不发请求)
|
* UX-04 geolocation 不可用时**静默兜底**(「我」标记→地图中心→校园中心,统一转 WGS84),
|
||||||
|
* 不再弹窗问用户;三处都拿不到才返回 null 并中止(绝不发 36.67/116.98 这种魔数)
|
||||||
*/
|
*/
|
||||||
const { test } = require('node:test');
|
const { test } = require('node:test');
|
||||||
const assert = require('node:assert/strict');
|
const assert = require('node:assert/strict');
|
||||||
@@ -115,7 +116,7 @@ function makeEnv({ ids = BASE_IDS, geo = null, fetchImpl = null } = {}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
console: { log() {}, warn() {}, error() {} },
|
console: { log() {}, info() {}, debug() {}, warn() {}, error() {} },
|
||||||
document,
|
document,
|
||||||
navigator: { userAgent: 'node-test', geolocation: geo || undefined },
|
navigator: { userAgent: 'node-test', geolocation: geo || undefined },
|
||||||
localStorage: {
|
localStorage: {
|
||||||
@@ -271,62 +272,58 @@ test('UX-03:confirmReturn 对真实订单有本地防御,不会误发 /api/r
|
|||||||
assert.equal(env.el('return-confirm-modal').classList.contains('show'), true);
|
assert.equal(env.el('return-confirm-modal').classList.contains('show'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('UX-04:geolocation 不可用且没有三选一弹窗时,取坐标返回 null 且不伪造坐标', async () => {
|
test('UX-04:没定位时静默用地图中心,不问用户(也不再弹三选一)', async () => {
|
||||||
const env = makeEnv(); // 没有 geo-choice-modal,也没有 navigator.geolocation
|
const env = makeEnv(); // 没有 navigator.geolocation、模板里也没有 geo-choice 弹窗
|
||||||
const S = env.context.XB.S;
|
|
||||||
S.authToken = 'token-1';
|
|
||||||
|
|
||||||
const loc = await env.XB.getOrderOperationLocation();
|
|
||||||
assert.equal(loc, null, '拿不到定位必须返回 null,而不是 36.67/116.98');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('UX-04:还车时拿不到坐标 → 中止,不发出任何带伪造坐标的请求', async () => {
|
|
||||||
const env = makeEnv();
|
|
||||||
const S = env.context.XB.S;
|
|
||||||
S.authToken = 'token-1';
|
|
||||||
S.currentOrder = { order_id: 'ORD-9', status: 2, code: '51287' };
|
|
||||||
|
|
||||||
await env.XB.showReturnConfirm();
|
|
||||||
await env.XB.doReturnBike();
|
|
||||||
await flush();
|
|
||||||
|
|
||||||
assert.equal(hasPath(env.requests, '/api/order/return'), false, '没有坐标就不该发还车请求');
|
|
||||||
assert.equal(hasPath(env.requests, '/api/rental/return'), false);
|
|
||||||
assert.match(env.el('toast').textContent, /没有可用的位置/, '要给用户一句明确的话: ' + env.el('toast').textContent);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('UX-04:用地图中心兜底时,坐标是转换后的真实位置(不是 36.67)', async () => {
|
|
||||||
const env = makeEnv({ ids: [...BASE_IDS, 'geo-choice-modal'] });
|
|
||||||
const S = env.context.XB.S;
|
const S = env.context.XB.S;
|
||||||
S.authToken = 'token-1';
|
S.authToken = 'token-1';
|
||||||
S.map = { getCenter: () => ({ lat: 36.5363, lng: 116.7863 }) }; // BD09
|
S.map = { getCenter: () => ({ lat: 36.5363, lng: 116.7863 }) }; // BD09
|
||||||
|
|
||||||
const pending = env.XB.getOrderOperationLocation(); // 没定位 → 弹三选一、挂起
|
const loc = await env.XB.getOrderOperationLocation();
|
||||||
await flush(2);
|
|
||||||
assert.equal(env.el('geo-choice-modal').classList.contains('show'), true, '拿不到定位要弹三选一');
|
|
||||||
|
|
||||||
await env.XB.chooseGeoMapCenter();
|
assert.ok(loc, '拿不到定位也要给出兜底坐标,不打断还车');
|
||||||
const loc = await pending;
|
|
||||||
|
|
||||||
assert.ok(loc, '选「用地图中心」之后要拿到坐标');
|
|
||||||
// coordtransform.bd09togcj02 = (-0.006, -0.003),再 gcj02towgs84 = (-0.006, -0.0045)
|
// coordtransform.bd09togcj02 = (-0.006, -0.003),再 gcj02towgs84 = (-0.006, -0.0045)
|
||||||
assert.ok(Math.abs(loc.latitude - (36.5363 - 0.003 - 0.0045)) < 1e-9, '纬度要按 BD09→WGS84 转换: ' + loc.latitude);
|
assert.ok(Math.abs(loc.latitude - (36.5363 - 0.003 - 0.0045)) < 1e-9, '纬度要按 BD09→WGS84 转换: ' + loc.latitude);
|
||||||
assert.ok(Math.abs(loc.longitude - (116.7863 - 0.006 - 0.006)) < 1e-9, '经度要按 BD09→WGS84 转换: ' + loc.longitude);
|
assert.ok(Math.abs(loc.longitude - (116.7863 - 0.006 - 0.006)) < 1e-9, '经度要按 BD09→WGS84 转换: ' + loc.longitude);
|
||||||
assert.notEqual(loc.latitude, 36.67);
|
|
||||||
assert.notEqual(loc.longitude, 116.98);
|
|
||||||
assert.equal(loc.source, 'map-center');
|
assert.equal(loc.source, 'map-center');
|
||||||
|
assert.notEqual(loc.latitude, 36.67, '不能再用 36.67/116.98 这种历史魔数');
|
||||||
|
assert.notEqual(loc.longitude, 116.98);
|
||||||
|
assert.match(env.el('toast').textContent, /地图中心/, '给一句轻提示就够,不需要用户确认: ' + env.el('toast').textContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('UX-04:选「取消」= 操作中止,返回 null', async () => {
|
test('UX-04:地图没就绪时退到校园中心(/api/config 的 center_lat/lng)', async () => {
|
||||||
const env = makeEnv({ ids: [...BASE_IDS, 'geo-choice-modal'] });
|
const env = makeEnv();
|
||||||
env.context.XB.S.authToken = 'token-1';
|
const S = env.context.XB.S;
|
||||||
|
S.authToken = 'token-1';
|
||||||
|
S.map = null; // 地图没就绪
|
||||||
|
S.campusCenter = { lat: 36.531820, lng: 116.780180 }; // GCJ02
|
||||||
|
|
||||||
const pending = env.XB.getOrderOperationLocation();
|
const loc = await env.XB.getOrderOperationLocation();
|
||||||
await flush(2);
|
|
||||||
env.XB.cancelGeoChoice();
|
assert.ok(loc, '地图没就绪时也要能兜底还车');
|
||||||
const loc = await pending;
|
assert.equal(loc.source, 'campus-center');
|
||||||
assert.equal(loc, null);
|
// GCJ02→WGS84 只是几米的偏移,量级必须在原值附近(而不是 36.67)
|
||||||
assert.equal(env.el('geo-choice-modal').classList.contains('show'), false, '取消后弹窗要关掉');
|
assert.ok(Math.abs(loc.latitude - 36.531820) < 0.01, '纬度应在校园中心附近: ' + loc.latitude);
|
||||||
|
assert.ok(Math.abs(loc.longitude - 116.780180) < 0.01, '经度应在校园中心附近: ' + loc.longitude);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('UX-04:地图与校园中心都没有 → 返回 null 且不发带伪造坐标的请求', async () => {
|
||||||
|
const env = makeEnv();
|
||||||
|
const S = env.context.XB.S;
|
||||||
|
S.authToken = 'token-1';
|
||||||
|
S.map = null;
|
||||||
|
S.campusCenter = null;
|
||||||
|
|
||||||
|
const loc = await env.XB.getOrderOperationLocation();
|
||||||
|
assert.equal(loc, null, '什么都没就绪时必须返回 null,而不是 36.67/116.98');
|
||||||
|
|
||||||
|
S.currentOrder = { order_id: 'ORD-9', status: 2, code: '51287' };
|
||||||
|
await env.XB.showReturnConfirm();
|
||||||
|
await env.XB.doReturnBike();
|
||||||
|
await flush();
|
||||||
|
|
||||||
|
assert.equal(hasPath(env.requests, '/api/order/return'), false, '没有坐标时不该发还车请求');
|
||||||
|
assert.equal(hasPath(env.requests, '/api/rental/return'), false);
|
||||||
|
assert.match(env.el('toast').textContent, /没有可用的位置/, '要告诉用户一句: ' + env.el('toast').textContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('UX-01:地图加载失败时遮罩变成可自救的失败卡片(不是一条会消失的 toast)', async () => {
|
test('UX-01:地图加载失败时遮罩变成可自救的失败卡片(不是一条会消失的 toast)', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user