refactor: restore acrylic map UI and collapse mobile discovery tools

This commit is contained in:
zzy
2026-11-04 17:07:18 +08:00
parent e9d09db42f
commit 0f47a8b572
7 changed files with 160 additions and 109 deletions
+95 -68
View File
@@ -1,73 +1,100 @@
/* Discovery tools reuse the existing porcelain / charcoal theme. */
.discovery-toolbar { position:absolute; z-index:130; top:12px; left:12px; width:min(400px, calc(100% - 140px)); padding:10px; border:1px solid var(--ui-line-strong); border-radius:16px; background:var(--ui-surface); box-shadow:var(--ui-shadow-md); font-size:13px; }
.place-search-wrap { position:relative; }
.place-search-row { display:flex; align-items:center; gap:6px; }
.place-search-row input { min-width:0; flex:1; width:100%; background:var(--ui-surface-raised); color:var(--ui-ink); border:1px solid var(--ui-line-strong); border-radius:9px; padding:10px; font-size:14px; }
.discovery-toolbar button,.discovery-toolbar summary,.nearby-panel button,.location-status button,.theme-options button,.order-filters button,.order-load-more,.sub-rule button { min-height:44px; border:1px solid var(--ui-line-strong); border-radius:9px; padding:8px 10px; background:var(--ui-surface-raised); color:var(--ui-ink); font:inherit; cursor:pointer; }
.discovery-actions { display:flex; gap:6px; align-items:center; margin-top:6px; }
.discovery-actions > button { flex:1; white-space:nowrap; }
.discovery-actions details > summary { list-style:none; display:flex; align-items:center; justify-content:center; }
.discovery-actions details > summary::-webkit-details-marker { display:none; }
.discovery-filter-fields { position:absolute; left:0; right:0; top:100%; margin-top:7px; padding:14px; background:var(--ui-surface); border:1px solid var(--ui-line-strong); border-radius:14px; box-shadow:var(--ui-shadow-md); display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.discovery-filter-fields label { display:flex; flex-direction:column; gap:7px; color:var(--ui-muted); }
.discovery-filter-fields .checkbox-label { flex-direction:row; align-items:center; grid-column:1/-1; color:var(--ui-ink); min-height:36px; }
.discovery-filter-fields select,.nearby-sort select,.order-filters input,.order-filters select { min-height:44px; width:100%; min-width:0; background:var(--ui-surface-raised); color:var(--ui-ink); border:1px solid var(--ui-line-strong); border-radius:8px; padding:7px; font:inherit; }
.discovery-filter-fields input[type=checkbox] { width:20px; height:20px; }
.discovery-origin { width:100%; text-align:left; border:0!important; background:transparent!important; color:var(--ui-muted)!important; padding:7px 2px 0!important; min-height:30px!important; font-size:12px!important; }
.place-results { position:absolute; z-index:3; top:calc(100% + 6px); width:100%; max-height:280px; overflow-y:auto; border-radius:12px; border:1px solid var(--ui-line-strong); background:var(--ui-surface); box-shadow:var(--ui-shadow-md); }
.place-results button { display:flex; justify-content:space-between; align-items:center; width:100%; border:0; border-radius:0; border-bottom:1px solid var(--ui-line); background:transparent; text-align:left; gap:12px; }
.place-results small,.discovery-muted { color:var(--ui-muted); font-size:12px; }
.favorite-places { display:flex; gap:6px; overflow-x:auto; scrollbar-width:thin; padding-top:6px; }
.favorite-place { display:flex; flex:none; border:1px solid var(--ui-line); border-radius:9px; overflow:hidden; }
.favorite-place button { border:0; border-radius:0; background:transparent; white-space:nowrap; min-height:36px; }
.favorite-place button:last-child { min-width:36px; padding:6px; color:var(--ui-muted); }
.nearby-panel { position:absolute; z-index:155; left:12px; bottom:12px; width:min(400px,calc(100% - 24px)); max-height:52%; display:flex; flex-direction:column; padding:14px; border:1px solid var(--ui-line-strong); border-radius:18px; background:var(--ui-surface); box-shadow:var(--ui-shadow-lg); font-size:13px; }
/* Keep the map clear. Secondary tools open only on demand, in the original acrylic material. */
[hidden] { display:none!important; }
.nearby-heading { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.nearby-heading h2 { font-size:17px; letter-spacing:-.3px; }
.nearby-heading button { min-width:44px; }
.nearby-summary { color:var(--ui-muted); padding:5px 0 10px; font-size:12px; line-height:1.6; }
.nearby-sort { display:flex; align-items:center; gap:10px; padding-bottom:8px; }
.nearby-sort select { width:auto; flex:1; }
.nearby-list { overflow-y:auto; min-height:80px; overscroll-behavior:contain; }
.nearby-row { display:flex; justify-content:space-between; width:100%; text-align:left; gap:12px; background:transparent!important; border-width:0 0 1px!important; border-radius:0!important; padding:12px 2px!important; }
.nearby-row strong { font-size:15px; font-variant-numeric:tabular-nums; }
.nearby-row-meta { display:block; margin-top:5px; color:var(--ui-muted); font-size:12px; }
.nearby-row-end { display:flex; flex-direction:column; align-items:flex-end; gap:5px; color:var(--ui-muted); font-size:12px; }
.map-tools-toggle,.discovery-toolbar,.place-results,.legend {
background:var(--ui-header-acrylic)!important;
border:1px solid var(--ui-line-strong);
-webkit-backdrop-filter:blur(24px) saturate(1.4);
backdrop-filter:blur(24px) saturate(1.4);
box-shadow:var(--ui-shadow-sm);
}
.map-tools-toggle { position:absolute; z-index:130; top:12px; left:12px; min-height:44px; padding:10px 16px; border-radius:14px; color:var(--ui-ink); font:inherit; font-size:13px; cursor:pointer; }
#map-filter-indicator { color:var(--ui-muted); font-size:11px; }
.discovery-toolbar { position:absolute; z-index:155; bottom:12px; left:12px; width:min(360px,calc(100% - 24px)); max-height:min(68%,560px); padding:14px; border-radius:20px; overflow-y:auto; overscroll-behavior:contain; color:var(--ui-ink); font-size:13px; }
.discovery-heading,.nearby-heading { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:8px; }
.discovery-heading h2 { font-size:17px; letter-spacing:-.3px; font-weight:650; }
.discovery-toolbar button,.discovery-toolbar summary,.discovery-toolbar select,.discovery-toolbar input { font:inherit; }
.discovery-toolbar button,.discovery-actions summary,.location-status button,.theme-options button,.order-filters button,.order-load-more,.sub-rule button,.preview-settings button {
min-height:44px; border:1px solid var(--ui-line); border-radius:10px; padding:8px 12px;
background:var(--ui-acrylic-soft); color:var(--ui-ink); cursor:pointer;
}
.discovery-heading button,.nearby-heading button { border:0; background:transparent; min-width:44px; padding:6px; color:var(--ui-muted); }
.place-search-row { display:flex; align-items:center; gap:6px; }
.place-search-row input { width:100%; min-width:0; min-height:44px; border:1px solid var(--ui-line-strong); border-radius:11px; padding:10px 12px; background:var(--ui-acrylic-soft); color:var(--ui-ink); font-size:14px; }
.place-results { position:relative; margin-top:6px; max-height:150px; overflow-y:auto; border-radius:12px; }
.place-results button { width:100%; display:flex; justify-content:space-between; align-items:center; border:0; border-radius:0; border-bottom:1px solid var(--ui-line); background:transparent; text-align:left; gap:12px; }
.place-results small,.discovery-muted { color:var(--ui-muted); font-size:12px; }
.discovery-actions { display:flex; align-items:flex-start; gap:8px; margin-top:8px; }
.discovery-actions > button { flex:1; }
.discovery-actions details { flex:1; }
.discovery-actions details[open] { flex-basis:100%; }
.discovery-actions:has(details[open]) { flex-wrap:wrap; }
.discovery-actions summary { list-style:none; display:flex; justify-content:center; align-items:center; }
.discovery-actions summary::-webkit-details-marker { display:none; }
.discovery-filter-fields { display:grid; grid-template-columns:1fr 1fr; gap:10px; padding:12px 2px 4px; }
.discovery-filter-fields label { display:flex; flex-direction:column; gap:6px; color:var(--ui-muted); font-size:12px; }
.discovery-filter-fields .checkbox-label { flex-direction:row; align-items:center; grid-column:1/-1; color:var(--ui-ink); }
.discovery-filter-fields input[type=checkbox] { width:18px; height:18px; }
.discovery-filter-fields select,.nearby-sort select,.order-filters input,.order-filters select { min-height:44px; min-width:0; width:100%; border:1px solid var(--ui-line); border-radius:9px; padding:8px; background:var(--ui-acrylic-soft); color:var(--ui-ink); }
.discovery-origin { width:100%; min-height:32px!important; padding:8px 0!important; border:0!important; background:transparent!important; color:var(--ui-muted)!important; font-size:12px!important; text-align:left; }
.discovery-places { border-top:1px solid var(--ui-line); padding-top:4px; }
.discovery-places > summary { min-height:36px; color:var(--ui-muted); cursor:pointer; line-height:36px; font-size:12px; }
.favorite-places { display:flex; flex-wrap:wrap; gap:6px; padding:4px 0 8px; }
.favorite-place { display:flex; border:1px solid var(--ui-line); border-radius:9px; overflow:hidden; }
.favorite-place button { border:0; border-radius:0; background:transparent; min-height:36px; padding:6px 9px; }
.favorite-place button:last-child { min-width:36px; padding:5px; color:var(--ui-muted); }
#favorite-save { min-height:36px; font-size:12px; margin-bottom:6px; }
.nearby-panel { display:flex; flex-direction:column; position:static; margin-top:8px; padding-top:10px; border-top:1px solid var(--ui-line); background:transparent; }
.nearby-heading { margin-bottom:0; }
.nearby-heading h2 { font-size:14px; font-weight:600; }
.nearby-summary { color:var(--ui-muted); font-size:11px; line-height:1.6; padding:2px 0 8px; }
.nearby-sort { display:flex; align-items:center; gap:10px; padding-bottom:6px; color:var(--ui-muted); font-size:12px; }
.nearby-sort select { flex:1; width:auto; }
.nearby-list { overflow-y:auto; max-height:210px; overscroll-behavior:contain; }
.nearby-row { display:flex; justify-content:space-between; gap:12px; width:100%; padding:11px 0!important; border-width:0 0 1px!important; border-radius:0!important; background:transparent!important; text-align:left; }
.nearby-row strong { font-size:14px; font-variant-numeric:tabular-nums; }
.nearby-row-meta { display:block; color:var(--ui-muted); font-size:12px; margin-top:4px; }
.nearby-row-end { display:flex; flex-direction:column; align-items:flex-end; gap:4px; color:var(--ui-muted); font-size:12px; white-space:nowrap; }
.vehicle-status { color:var(--ui-ink); font-weight:600; }
.vehicle-status.available { color:var(--discovery-available,#237947); }
.vehicle-status.lowbattery,.vehicle-status.locked { color:var(--discovery-warning,#9a5a08); }
.discovery-empty { padding:15px 4px; line-height:1.8; color:var(--ui-muted); }
.discovery-empty { padding:12px 0; color:var(--ui-muted); line-height:1.7; }
.discovery-empty strong { color:var(--ui-ink); }
.discovery-empty button { margin-top:10px; }
.location-status { position:absolute; z-index:125; bottom:14px; left:50%; transform:translateX(-50%); width:min(400px,calc(100% - 130px)); padding:10px 12px; border:1px solid var(--ui-line-strong); border-radius:12px; background:var(--ui-surface); color:var(--ui-ink); box-shadow:var(--ui-shadow-sm); font-size:12px; line-height:1.6; }
.location-status-actions { display:flex; gap:8px; margin-top:5px; }
.stats-card { top:auto!important; bottom:14px; }
.legend summary { cursor:pointer; min-height:32px; font-size:12px; color:var(--ui-muted); }
.discovery-empty button { margin-top:8px; }
.location-status { position:static; padding-top:8px; border-top:1px solid var(--ui-line); color:var(--ui-muted); font-size:12px; line-height:1.6; }
.location-status-actions { display:flex; gap:8px; margin-top:6px; }
.location-status-actions button { min-height:36px; padding:6px 9px; font-size:12px; }
.legend { top:12px!important; right:12px!important; bottom:auto!important; }
.legend summary { cursor:pointer; min-height:28px; line-height:28px; font-size:12px; color:var(--ui-muted); }
.legend:not([open]) .legend-item { display:none; }
.theme-options { display:flex; gap:8px; padding:12px 0; }
.theme-options button { flex:1; }
body:has(#discovery-drawer:not([hidden])) .locate-fab { visibility:hidden; }
.header-school-row { display:flex; align-items:center; gap:7px; }
.preview-tag { font-size:10px; color:var(--ui-muted); border:1px solid var(--ui-line-strong); border-radius:5px; padding:1px 4px; line-height:1.3; }
.preview-entry { display:flex; justify-content:center; gap:10px; align-items:center; color:var(--ui-muted); margin:12px 0 2px; font-size:12px; }
.preview-entry button { padding:5px 2px; background:transparent; color:inherit; border:0; cursor:pointer; font:inherit; min-height:32px; }
.preview-settings { padding:14px 0; }
.preview-settings > div { display:flex; gap:8px; margin-top:8px; }
.preview-settings button { flex:1; font:inherit; font-size:13px; }
.theme-options { display:flex; gap:8px; padding:10px 0 14px; }
.theme-options button { flex:1; font:inherit; font-size:13px; }
.theme-options button[aria-pressed=true] { background:var(--ui-solid); color:var(--ui-on-solid); }
.order-filters { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:10px 0 14px; }
.order-filters label { display:flex; flex-direction:column; gap:6px; color:var(--ui-muted); font-size:12px; min-width:0; }
.order-filters input,.order-filters select { font:inherit; }
.order-filter-actions { display:flex; gap:8px; grid-column:1/-1; }
.order-load-more { margin-top:12px; }
.sub-rule { border-bottom:1px solid var(--ui-line); padding:12px 0; font-size:13px; line-height:1.7; }
.sub-rule-head { display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.sub-rule-meta,.sub-rule-result { color:var(--ui-muted); font-size:12px; margin-top:4px; }
.sub-rule-actions { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; }
.sub-rule-actions button { min-height:40px; padding:6px 12px; }
.sub-rule-actions button { min-height:40px; padding:6px 12px; font:inherit; }
.sub-rule-actions .danger { color:var(--danger); }
.sub-editor-heading { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }
.sub-editor-heading button { min-height:40px; padding:6px 10px; border:1px solid var(--ui-line); border-radius:8px; background:var(--ui-surface); color:var(--ui-ink); }
.preview-notice { display:flex; align-items:center; justify-content:space-between; padding:6px 16px; gap:12px; background:#f6edd6; color:#624608; font-size:12px; line-height:1.6; z-index:170; flex-shrink:0; }
.preview-notice button,.preview-login { border:1px solid currentColor; border-radius:8px; padding:7px 12px; color:inherit; background:transparent; min-height:40px; cursor:pointer; }
.preview-login { display:block; width:100%; margin-top:12px; color:var(--ui-ink); border-color:var(--ui-line-strong); }
.preview-notice a { color:inherit; }
.discovery-welcome { display:flex; gap:12px; padding:14px; margin:10px 0; background:var(--ui-surface-raised); border-radius:12px; color:var(--ui-muted); font-size:13px; line-height:1.7; }
.discovery-welcome strong { color:var(--ui-ink); }
.sub-editor-heading button { min-height:40px; padding:6px 10px; border:1px solid var(--ui-line); border-radius:8px; background:var(--ui-acrylic-soft); color:var(--ui-ink); }
.settings-page { background:color-mix(in srgb,var(--ui-canvas) 82%,transparent)!important; -webkit-backdrop-filter:blur(32px) saturate(1.3); backdrop-filter:blur(32px) saturate(1.3); }
.settings-page .settings-group { background:var(--ui-acrylic-soft)!important; }
.bike-card:not(.show) { visibility:hidden; pointer-events:none; }
.bike-card.show { visibility:visible; }
.battery-unknown .battery-unit { display:none; }
.auth-modal:not(.show),.qr-modal:not(.show),.unlock-confirm-modal:not(.show),.return-confirm-modal:not(.show),.token-expired-modal:not(.show),.lost-modal:not(.show),.return-modal:not(.show),.bell-modal:not(.show) { visibility:hidden; }
html,body { overflow:clip; }
body { animation:none!important; }
@@ -75,22 +102,22 @@ body { animation:none!important; }
.auth-close,.bike-card-close,.qr-close { min-width:44px; min-height:44px; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
button:disabled { cursor:wait; opacity:.65; }
@media (max-width:768px) {
.discovery-toolbar { width:calc(100% - 24px); padding:8px; }
.legend { top:auto!important; bottom:74px!important; right:12px!important; padding:7px 10px!important; }
.legend summary { min-height:30px; }
.stats-card { bottom:12px; left:12px!important; }
.location-status { bottom:65px; width:calc(100% - 24px); }
.nearby-panel { max-height:56%; }
.locate-btn.locate-fab { width:auto; height:44px; padding:8px 12px; bottom:92px; right:12px; }
.locate-fab-label { display:inline!important; font-size:12px; }
.favorite-places { max-height:46px; }
.preview-notice { padding:5px 12px; }
.preview-notice button { min-height:32px; padding:4px 8px; }
@media(max-width:768px) {
.map-tools-toggle { top:10px; left:10px; padding:9px 14px; border-radius:13px; }
.legend { top:10px!important; right:10px!important; padding:6px 10px!important; }
.discovery-toolbar { left:10px; bottom:10px; width:calc(100% - 20px); max-height:64%; padding:12px; }
.locate-btn.locate-fab { width:44px; height:44px; padding:0; border-radius:50%; bottom:94px; right:12px; }
.locate-fab-label { display:none!important; }
.nearby-list { max-height:180px; }
}
@media (prefers-reduced-motion:reduce) { .nearby-panel,.discovery-toolbar { transition:none; } }
@media(prefers-reduced-motion:reduce) { .discovery-toolbar { transition:none; } }
.battery-unknown .battery-unit { display:none; }
body:has(#nearby-panel:not([hidden])) .locate-fab { display:none; }
.preview-notice > span { flex:1; }
@media(max-width:768px){ .preview-notice { flex-wrap:wrap; gap:4px 8px; } .preview-notice > span { flex-basis:100%; } .preview-notice button { min-height:32px; } }
.discovery-toolbar[data-view=list] > .place-search-wrap,
.discovery-toolbar[data-view=list] > .discovery-actions,
.discovery-toolbar[data-view=list] > .discovery-origin,
.discovery-toolbar[data-view=list] > .discovery-places,
.discovery-toolbar[data-view=list] > .location-status { display:none!important; }
.discovery-toolbar[data-view=list] .nearby-heading h2 { display:none; }
.discovery-toolbar[data-view=list] .nearby-panel { margin-top:0; padding-top:0; border-top:0; }
.discovery-toolbar[data-view=list] .nearby-heading { justify-content:flex-start; }
.discovery-toolbar[data-view=list] #nearby-close { min-height:32px; padding:3px 0; color:var(--ui-muted); font-size:12px; }
+1 -1
View File
@@ -942,7 +942,7 @@
checkOrderStatus();
checkRentalStatus();
refreshAuthExpiry(); // 登录态有效期不足 2 天时挂顶部提醒
if (map) { loadMapData(currentType, false); startAutoLocation(); }
if (map) { loadMapData(currentType, false); resumeLocationIfGranted(); }
} else {
tip.textContent = data.message || "登录失败";
}
+32 -9
View File
@@ -36,8 +36,9 @@
if (!initialized) return;
const rows = items();
byId('nearby-count').textContent = rows.length;
byId('map-filter-indicator').hidden = !(filters.onlyAvailable || filters.minElectric || filters.kind !== 'all');
byId('discovery-origin').textContent = originName || (autoLocationMarker ? '以我的位置查找' : '以地图中心查找');
byId('nearby-summary').textContent = `${filters.radius ? filters.radius + ' 米内' : '全部范围'} · ${rows.length} 辆符合条件 · 距离为直线距离`;
byId('nearby-summary').textContent = `${originName || (autoLocationMarker ? '我的位置' : '地图中心')} · ${filters.radius ? filters.radius + ' 米内' : '全部范围'} · ${rows.length} 辆,直线距离`;
const batteryText = e => e === null ? '电量未知' : `${Math.round(e)}% 电量`;
byId('nearby-list').innerHTML = rows.length ? rows.slice(0, 100).map(row => {
const s = BikeData.state(row.bike), k = { small:'小车', big:'大车', red:'红车' }[BikeData.kind(row.bike)];
@@ -64,11 +65,29 @@
byId('filter-radius').value = filters.radius;
byId('nearby-sort').value = filters.sort;
}
function openTools() {
byId('discovery-drawer').hidden = false;
byId('map-tools-toggle').setAttribute('aria-expanded', 'true');
render();
}
function closeTools(restoreFocus = true) {
byId('discovery-drawer').hidden = true;
byId('discovery-drawer').dataset.view = 'tools';
byId('discovery-title').textContent = '找车';
byId('nearby-panel').hidden = true;
byId('nearby-toggle').setAttribute('aria-expanded', 'false');
byId('map-tools-toggle').setAttribute('aria-expanded', 'false');
byId('discovery-filters').open = false;
byId('place-results').hidden = true;
if (restoreFocus) byId('map-tools-toggle').focus({preventScroll:true});
}
function showList(open = true) {
if (open) { openTools(); byId('discovery-filters').open = false; }
byId('nearby-panel').hidden = !open;
byId('discovery-drawer').dataset.view = open ? 'list' : 'tools';
byId('discovery-title').textContent = open ? '附近车辆' : '找车';
byId('nearby-toggle').setAttribute('aria-expanded', String(open));
if (open) { render(); byId('nearby-close').focus({ preventScroll: true }); }
else byId('nearby-toggle').focus({ preventScroll: true });
if (open) render();
}
function choosePlace(point, name) {
if (!map) { showToast('地图正在加载,请稍后重试'); return; }
@@ -103,9 +122,9 @@
byId('location-message').textContent = message;
byId('location-retry').hidden = !retry;
}
async function nearest(point) {
async function nearest(point, name = "我的位置") {
if (!authToken) { showLoginGate(); return; }
if (point) { origin = { lat: point.lat, lng: point.lng }; originName = '我的位置'; }
if (point) { origin = { lat: point.lat, lng: point.lng }; originName = name; }
const candidates = items(true).filter(row => row.electric !== null && row.electric >= 20);
if (!candidates.length) {
showList(); locationStatus('没有符合当前条件的可用车,可在列表中放宽筛选。');
@@ -113,12 +132,16 @@
}
candidates.sort((a, b) => (a.distance ?? Infinity) - (b.distance ?? Infinity));
const row = candidates[0];
nearestBikeId = row.id; showList(false); showBikeDetail(row.id);
showToast(`最近可用:#${row.bike.code},${Math.round(row.distance || 0)} 米,电量 ${row.electric}%`);
nearestBikeId = row.id; closeTools(false); showBikeDetail(row.id);
showToast(`${originName || "地图中心"}最近可用:#${row.bike.code},${Math.round(row.distance || 0)} 米,电量 ${row.electric}%`);
}
async function init() {
if (initialized) return;
initialized = true; fillControls(); renderFavorites();
byId('map-tools-toggle').addEventListener('click', () => { if (byId('discovery-drawer').hidden) openTools(); else closeTools(); });
byId('discovery-close').addEventListener('click', () => closeTools());
byId('discovery-drawer').addEventListener('keydown', event => { if (event.key === 'Escape') { event.preventDefault(); closeTools(); } });
document.addEventListener('pointerdown', event => { if (!byId('discovery-drawer').hidden && !event.target.closest('#discovery-drawer,#map-tools-toggle')) closeTools(false); });
['filter-available','filter-electric','filter-kind','filter-radius','nearby-sort'].forEach(id => byId(id).addEventListener('change', () => {
filters.onlyAvailable = byId('filter-available').checked;
filters.minElectric = Number(byId('filter-electric').value);
@@ -134,7 +157,7 @@
byId('nearby-panel').addEventListener('keydown', e => { if (e.key === 'Escape') showList(false); });
byId('nearby-list').addEventListener('click', event => {
const row = event.target.closest('[data-bike-id]');
if (row) { showList(false); showBikeDetail(row.dataset.bikeId); }
if (row) { closeTools(false); showBikeDetail(row.dataset.bikeId); }
if (event.target.closest('[data-relax]')) relax();
});
byId('place-search').addEventListener('input', searchPlaces);
@@ -171,5 +194,5 @@
} catch (_) { locationStatus('校园地点加载失败,可拖动地图查找或重试刷新。'); }
render();
}
window.BikeDiscovery = { init, render, visibleBikes, locationStatus, nearest, showList };
window.BikeDiscovery = { init, render, visibleBikes, locationStatus, nearest, showList, openTools, closeTools };
})();
+3 -2
View File
@@ -429,9 +429,10 @@
// Update notes are available from Settings; first visits stay focused on finding a bike.
}
async function previewLogin() {
const button = document.querySelector(".preview-login") || document.getElementById("auth-btn");
async function previewLogin(button) {
button = button || document.querySelector("[data-preview-demo]") || document.getElementById("auth-btn");
await doLogin("demo@preview.local", "preview123", document.getElementById("gate-tip"), button);
if (currentUser?.email === "demo@preview.local" && typeof SettingsPages !== "undefined") SettingsPages.close();
}
async function createPreviewSession() {
return AppAPI.run("preview-session", null, async () => {
+12 -6
View File
@@ -523,7 +523,7 @@
// 启动自动持续定位(地图加载后立即开始)
if (typeof BikeDiscovery !== "undefined") BikeDiscovery.init();
if (authToken) startAutoLocation();
if (authToken) resumeLocationIfGranted();
})
.catch(err => {
console.error("初始化失败:", err);
@@ -1181,11 +1181,9 @@
// 手动找最近的车(基于当前自动定位的位置)
function findNearestBikeManual() {
if (!authToken) { showLoginGate(); return; }
if (!autoLocationMarker) {
BikeDiscovery.locationStatus("尚未获取位置。可重新定位,或按地图中心找车。", true);
BikeDiscovery.showList(); return;
}
findNearestBike(autoLocationMarker.getPosition());
const point = autoLocationMarker?.getPosition() || map?.getCenter();
if (!point) { showToast("地图正在加载,请稍后重试"); return; }
return BikeDiscovery.nearest(point, autoLocationMarker ? "我的位置" : "地图中心");
}
// 显示我的位置(手动定位模式,带 panTo)
@@ -1260,6 +1258,14 @@
}
// 启动自动持续定位
async function resumeLocationIfGranted() {
try {
const permission = await navigator.permissions?.query({name:"geolocation"});
if (permission?.state === "granted") startAutoLocation();
else BikeDiscovery.locationStatus("按地图中心找车,需要时可开启定位。", true);
} catch (_) { BikeDiscovery.locationStatus("按地图中心找车,需要时可开启定位。", true); }
}
function startAutoLocation() {
if (!navigator.geolocation) {
BikeDiscovery.locationStatus("浏览器不支持定位,可以按地图中心或校园地点找车。", false);