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
+5
View File
@@ -181,3 +181,8 @@ node --test tests/test_api_client.cjs tests/test_bike_data.cjs tests/test_bike_c
``` ```
浏览器验收采用演示账号;真实上游链路用替身请求验证路由与账号隔离,不在自动化验收中执行真实车辆操作。 浏览器验收采用演示账号;真实上游链路用替身请求验证路由与账号隔离,不在自动化验收中执行真实车辆操作。
### 手机界面
地图默认只保留找车入口、状态图例、最近车辆按钮和车牌查询。地点、常用地点、筛选与附近列表收进同一个按需展开的亚克力面板;列表与筛选互相切换,选中车辆或点击地图即可收起。定位提示不再悬浮遮挡地图,首次进入也不会主动弹出定位权限请求;已授权的设备会恢复定位。数据分析及演示/真实测试切换位于设置,预览标识缩为校名旁的小标签。
+94 -67
View File
@@ -1,73 +1,100 @@
/* Discovery tools reuse the existing porcelain / charcoal theme. */ /* Keep the map clear. Secondary tools open only on demand, in the original acrylic material. */
.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; }
[hidden] { display:none!important; } [hidden] { display:none!important; }
.nearby-heading { display:flex; align-items:center; justify-content:space-between; gap:10px; } .map-tools-toggle,.discovery-toolbar,.place-results,.legend {
.nearby-heading h2 { font-size:17px; letter-spacing:-.3px; } background:var(--ui-header-acrylic)!important;
.nearby-heading button { min-width:44px; } border:1px solid var(--ui-line-strong);
.nearby-summary { color:var(--ui-muted); padding:5px 0 10px; font-size:12px; line-height:1.6; } -webkit-backdrop-filter:blur(24px) saturate(1.4);
.nearby-sort { display:flex; align-items:center; gap:10px; padding-bottom:8px; } backdrop-filter:blur(24px) saturate(1.4);
.nearby-sort select { width:auto; flex:1; } box-shadow:var(--ui-shadow-sm);
.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; } .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; }
.nearby-row strong { font-size:15px; font-variant-numeric:tabular-nums; } #map-filter-indicator { color:var(--ui-muted); font-size:11px; }
.nearby-row-meta { display:block; margin-top:5px; color:var(--ui-muted); font-size:12px; } .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; }
.nearby-row-end { display:flex; flex-direction:column; align-items:flex-end; gap:5px; color:var(--ui-muted); font-size:12px; } .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 { color:var(--ui-ink); font-weight:600; }
.vehicle-status.available { color:var(--discovery-available,#237947); } .vehicle-status.available { color:var(--discovery-available,#237947); }
.vehicle-status.lowbattery,.vehicle-status.locked { color:var(--discovery-warning,#9a5a08); } .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 strong { color:var(--ui-ink); }
.discovery-empty button { margin-top:10px; } .discovery-empty button { margin-top:8px; }
.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 { 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:5px; } .location-status-actions { display:flex; gap:8px; margin-top:6px; }
.stats-card { top:auto!important; bottom:14px; } .location-status-actions button { min-height:36px; padding:6px 9px; font-size:12px; }
.legend summary { cursor:pointer; min-height:32px; font-size:12px; color:var(--ui-muted); } .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; } .legend:not([open]) .legend-item { display:none; }
.theme-options { display:flex; gap:8px; padding:12px 0; } body:has(#discovery-drawer:not([hidden])) .locate-fab { visibility:hidden; }
.theme-options button { flex:1; } .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); } .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 { 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 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-filter-actions { display:flex; gap:8px; grid-column:1/-1; }
.order-load-more { margin-top:12px; } .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 { 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-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-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 { 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-rule-actions .danger { color:var(--danger); }
.sub-editor-heading { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; } .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); } .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); }
.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; } .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); }
.preview-notice button,.preview-login { border:1px solid currentColor; border-radius:8px; padding:7px 12px; color:inherit; background:transparent; min-height:40px; cursor:pointer; } .settings-page .settings-group { background:var(--ui-acrylic-soft)!important; }
.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); }
.bike-card:not(.show) { visibility:hidden; pointer-events:none; } .bike-card:not(.show) { visibility:hidden; pointer-events:none; }
.bike-card.show { visibility:visible; } .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; } .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; } html,body { overflow:clip; }
body { animation:none!important; } body { animation:none!important; }
@@ -76,21 +103,21 @@ body { animation:none!important; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; } .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; } button:disabled { cursor:wait; opacity:.65; }
@media(max-width:768px) { @media(max-width:768px) {
.discovery-toolbar { width:calc(100% - 24px); padding:8px; } .map-tools-toggle { top:10px; left:10px; padding:9px 14px; border-radius:13px; }
.legend { top:auto!important; bottom:74px!important; right:12px!important; padding:7px 10px!important; } .legend { top:10px!important; right:10px!important; padding:6px 10px!important; }
.legend summary { min-height:30px; } .discovery-toolbar { left:10px; bottom:10px; width:calc(100% - 20px); max-height:64%; padding:12px; }
.stats-card { bottom:12px; left:12px!important; } .locate-btn.locate-fab { width:44px; height:44px; padding:0; border-radius:50%; bottom:94px; right:12px; }
.location-status { bottom:65px; width:calc(100% - 24px); } .locate-fab-label { display:none!important; }
.nearby-panel { max-height:56%; } .nearby-list { max-height:180px; }
.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 (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; } .discovery-toolbar[data-view=list] > .place-search-wrap,
body:has(#nearby-panel:not([hidden])) .locate-fab { display:none; } .discovery-toolbar[data-view=list] > .discovery-actions,
.preview-notice > span { flex:1; } .discovery-toolbar[data-view=list] > .discovery-origin,
@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] > .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(); checkOrderStatus();
checkRentalStatus(); checkRentalStatus();
refreshAuthExpiry(); // 登录态有效期不足 2 天时挂顶部提醒 refreshAuthExpiry(); // 登录态有效期不足 2 天时挂顶部提醒
if (map) { loadMapData(currentType, false); startAutoLocation(); } if (map) { loadMapData(currentType, false); resumeLocationIfGranted(); }
} else { } else {
tip.textContent = data.message || "登录失败"; tip.textContent = data.message || "登录失败";
} }
+32 -9
View File
@@ -36,8 +36,9 @@
if (!initialized) return; if (!initialized) return;
const rows = items(); const rows = items();
byId('nearby-count').textContent = rows.length; 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('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)}% 电量`; const batteryText = e => e === null ? '电量未知' : `${Math.round(e)}% 电量`;
byId('nearby-list').innerHTML = rows.length ? rows.slice(0, 100).map(row => { 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)]; 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('filter-radius').value = filters.radius;
byId('nearby-sort').value = filters.sort; 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) { function showList(open = true) {
if (open) { openTools(); byId('discovery-filters').open = false; }
byId('nearby-panel').hidden = !open; 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)); byId('nearby-toggle').setAttribute('aria-expanded', String(open));
if (open) { render(); byId('nearby-close').focus({ preventScroll: true }); } if (open) render();
else byId('nearby-toggle').focus({ preventScroll: true });
} }
function choosePlace(point, name) { function choosePlace(point, name) {
if (!map) { showToast('地图正在加载,请稍后重试'); return; } if (!map) { showToast('地图正在加载,请稍后重试'); return; }
@@ -103,9 +122,9 @@
byId('location-message').textContent = message; byId('location-message').textContent = message;
byId('location-retry').hidden = !retry; byId('location-retry').hidden = !retry;
} }
async function nearest(point) { async function nearest(point, name = "我的位置") {
if (!authToken) { showLoginGate(); return; } 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); const candidates = items(true).filter(row => row.electric !== null && row.electric >= 20);
if (!candidates.length) { if (!candidates.length) {
showList(); locationStatus('没有符合当前条件的可用车,可在列表中放宽筛选。'); showList(); locationStatus('没有符合当前条件的可用车,可在列表中放宽筛选。');
@@ -113,12 +132,16 @@
} }
candidates.sort((a, b) => (a.distance ?? Infinity) - (b.distance ?? Infinity)); candidates.sort((a, b) => (a.distance ?? Infinity) - (b.distance ?? Infinity));
const row = candidates[0]; const row = candidates[0];
nearestBikeId = row.id; showList(false); showBikeDetail(row.id); nearestBikeId = row.id; closeTools(false); showBikeDetail(row.id);
showToast(`最近可用:#${row.bike.code},${Math.round(row.distance || 0)} 米,电量 ${row.electric}%`); showToast(`${originName || "地图中心"}最近可用:#${row.bike.code},${Math.round(row.distance || 0)} 米,电量 ${row.electric}%`);
} }
async function init() { async function init() {
if (initialized) return; if (initialized) return;
initialized = true; fillControls(); renderFavorites(); 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', () => { ['filter-available','filter-electric','filter-kind','filter-radius','nearby-sort'].forEach(id => byId(id).addEventListener('change', () => {
filters.onlyAvailable = byId('filter-available').checked; filters.onlyAvailable = byId('filter-available').checked;
filters.minElectric = Number(byId('filter-electric').value); 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-panel').addEventListener('keydown', e => { if (e.key === 'Escape') showList(false); });
byId('nearby-list').addEventListener('click', event => { byId('nearby-list').addEventListener('click', event => {
const row = event.target.closest('[data-bike-id]'); 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(); if (event.target.closest('[data-relax]')) relax();
}); });
byId('place-search').addEventListener('input', searchPlaces); byId('place-search').addEventListener('input', searchPlaces);
@@ -171,5 +194,5 @@
} catch (_) { locationStatus('校园地点加载失败,可拖动地图查找或重试刷新。'); } } catch (_) { locationStatus('校园地点加载失败,可拖动地图查找或重试刷新。'); }
render(); 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. // Update notes are available from Settings; first visits stay focused on finding a bike.
} }
async function previewLogin() { async function previewLogin(button) {
const button = document.querySelector(".preview-login") || document.getElementById("auth-btn"); button = button || document.querySelector("[data-preview-demo]") || document.getElementById("auth-btn");
await doLogin("demo@preview.local", "preview123", document.getElementById("gate-tip"), button); 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() { async function createPreviewSession() {
return AppAPI.run("preview-session", null, async () => { return AppAPI.run("preview-session", null, async () => {
+12 -6
View File
@@ -523,7 +523,7 @@
// 启动自动持续定位(地图加载后立即开始) // 启动自动持续定位(地图加载后立即开始)
if (typeof BikeDiscovery !== "undefined") BikeDiscovery.init(); if (typeof BikeDiscovery !== "undefined") BikeDiscovery.init();
if (authToken) startAutoLocation(); if (authToken) resumeLocationIfGranted();
}) })
.catch(err => { .catch(err => {
console.error("初始化失败:", err); console.error("初始化失败:", err);
@@ -1181,11 +1181,9 @@
// 手动找最近的车(基于当前自动定位的位置) // 手动找最近的车(基于当前自动定位的位置)
function findNearestBikeManual() { function findNearestBikeManual() {
if (!authToken) { showLoginGate(); return; } if (!authToken) { showLoginGate(); return; }
if (!autoLocationMarker) { const point = autoLocationMarker?.getPosition() || map?.getCenter();
BikeDiscovery.locationStatus("尚未获取位置。可重新定位,或按地图中心找车。", true); if (!point) { showToast("地图正在加载,请稍后重试"); return; }
BikeDiscovery.showList(); return; return BikeDiscovery.nearest(point, autoLocationMarker ? "我的位置" : "地图中心");
}
findNearestBike(autoLocationMarker.getPosition());
} }
// 显示我的位置(手动定位模式,带 panTo) // 显示我的位置(手动定位模式,带 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() { function startAutoLocation() {
if (!navigator.geolocation) { if (!navigator.geolocation) {
BikeDiscovery.locationStatus("浏览器不支持定位,可以按地图中心或校园地点找车。", false); BikeDiscovery.locationStatus("浏览器不支持定位,可以按地图中心或校园地点找车。", false);
+12 -23
View File
@@ -44,7 +44,7 @@
<script defer src="/static/js/ui-motion.js?v={{ map_asset_version }}"></script> <script defer src="/static/js/ui-motion.js?v={{ map_asset_version }}"></script>
</head> </head>
<body> <body>
{% if preview_mode %}<div class="preview-notice"><span><strong>预览环境</strong> · 演示账号使用模拟数据,独立测试账号可连接真实接口</span><button type="button" onclick="previewLogin()">演示体验</button><button type="button" onclick="createPreviewSession()">创建测试账号</button></div>{% endif %}
<!-- 登录态(微信凭据)到期提醒横幅:有效期不足 2 天时显示 --> <!-- 登录态(微信凭据)到期提醒横幅:有效期不足 2 天时显示 -->
<div class="auth-expiry-banner" id="auth-expiry-banner" onclick="openAuthModal()"> <div class="auth-expiry-banner" id="auth-expiry-banner" onclick="openAuthModal()">
@@ -126,7 +126,7 @@
<div class="header"> <div class="header">
<div> <div>
<div class="header-title">电动车地图</div> <div class="header-title">电动车地图</div>
<div class="header-sub" id="school-name">加载中...</div> <div class="header-school-row"><div class="header-sub" id="school-name">加载中...</div>{% if preview_mode %}<span class="preview-tag">预览</span>{% endif %}</div>
</div> </div>
<div class="header-right"> <div class="header-right">
<div class="header-badge"> <div class="header-badge">
@@ -175,20 +175,9 @@
<div class="loading-text">正在加载车辆...</div> <div class="loading-text">正在加载车辆...</div>
</div> </div>
<div class="stats-card"> <button type="button" class="map-tools-toggle" id="map-tools-toggle" aria-expanded="false" aria-controls="discovery-drawer">找车<span id="map-filter-indicator" hidden> · 已筛选</span></button>
<button class="stats-analysis-btn" onclick="uiNavigate('/analysis.html')"> <section class="discovery-toolbar" id="discovery-drawer" aria-labelledby="discovery-title" hidden><div class="discovery-heading"><h2 id="discovery-title">找车</h2><button type="button" id="discovery-close" aria-label="收起找车工具">×</button></div>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"> <div class="place-search-wrap"><label for="place-search" class="sr-only">搜索校园地点</label><div class="place-search-row"><input id="place-search" type="search" placeholder="搜索教学楼、宿舍或停车点" autocomplete="off" maxlength="40"></div><div id="place-results" class="place-results" hidden></div></div>
<path d="M3 3v18h18"/>
<path d="M18 17V9"/>
<path d="M13 17V5"/>
<path d="M8 17v-3"/>
</svg>
数据分析
</button>
</div>
<section class="discovery-toolbar" aria-label="找车工具">
<div class="place-search-wrap"><label for="place-search" class="sr-only">搜索校园地点</label><div class="place-search-row"><input id="place-search" type="search" placeholder="搜索教学楼、宿舍或停车点" autocomplete="off" maxlength="40"><button type="button" id="favorite-save" title="收藏当前查找地点">收藏</button></div><div id="place-results" class="place-results" hidden></div></div>
<div class="discovery-actions"><button type="button" id="nearby-toggle" aria-expanded="false" aria-controls="nearby-panel">附近车辆 <span id="nearby-count">0</span></button><details id="discovery-filters"><summary>筛选条件</summary><div class="discovery-filter-fields"> <div class="discovery-actions"><button type="button" id="nearby-toggle" aria-expanded="false" aria-controls="nearby-panel">附近车辆 <span id="nearby-count">0</span></button><details id="discovery-filters"><summary>筛选条件</summary><div class="discovery-filter-fields">
<label class="checkbox-label"><input type="checkbox" id="filter-available">仅看可用车辆</label> <label class="checkbox-label"><input type="checkbox" id="filter-available">仅看可用车辆</label>
<label>最低电量<select id="filter-electric"><option value="0">不限(含未知)</option><option value="20">20%</option><option value="40">40%</option><option value="60">60%</option><option value="80">80%</option></select></label> <label>最低电量<select id="filter-electric"><option value="0">不限(含未知)</option><option value="20">20%</option><option value="40">40%</option><option value="60">60%</option><option value="80">80%</option></select></label>
@@ -196,10 +185,10 @@
<label>列表范围<select id="filter-radius"><option value="200">200 米</option><option value="500">500 米</option><option value="1000">1 公里</option><option value="0">全部范围</option></select></label> <label>列表范围<select id="filter-radius"><option value="200">200 米</option><option value="500">500 米</option><option value="1000">1 公里</option><option value="0">全部范围</option></select></label>
</div></details></div> </div></details></div>
<button type="button" class="discovery-origin" id="discovery-origin" title="重置到我的位置或地图中心">以地图中心查找</button> <button type="button" class="discovery-origin" id="discovery-origin" title="重置到我的位置或地图中心">以地图中心查找</button>
<div class="favorite-places" id="favorite-places" aria-label="常用地点"></div> <details class="discovery-places"><summary>常用地点</summary><div class="favorite-places" id="favorite-places" aria-label="常用地点"></div><button type="button" id="favorite-save">收藏当前地点</button></details>
<section class="nearby-panel" id="nearby-panel" aria-labelledby="nearby-title" hidden><div class="nearby-heading"><h2 id="nearby-title">附近车辆</h2><button type="button" id="nearby-close">返回筛选</button></div><p class="nearby-summary" id="nearby-summary" role="status"></p><label class="nearby-sort">排序<select id="nearby-sort"><option value="distance">距离最近</option><option value="electric">电量最高</option></select></label><div class="nearby-list" id="nearby-list"></div></section>
<div id="location-status" class="location-status" role="status" hidden><span id="location-message"></span><div class="location-status-actions"><button type="button" id="location-retry" hidden>定位我的位置</button><button type="button" id="location-center">按地图中心找车</button></div></div>
</section> </section>
<section class="nearby-panel" id="nearby-panel" aria-labelledby="nearby-title" hidden><div class="nearby-heading"><h2 id="nearby-title">附近车辆</h2><button type="button" id="nearby-close" aria-label="关闭附近车辆列表">×</button></div><p class="nearby-summary" id="nearby-summary" role="status"></p><label class="nearby-sort">排序<select id="nearby-sort"><option value="distance">距离最近</option><option value="electric">电量最高</option></select></label><div class="nearby-list" id="nearby-list"></div></section>
<div id="location-status" class="location-status" role="status" hidden><span id="location-message"></span><div class="location-status-actions"><button type="button" id="location-retry" hidden>重新定位</button><button type="button" id="location-center">按地图中心找车</button></div></div>
<details class="legend"> <details class="legend">
<summary>状态图例</summary> <summary>状态图例</summary>
<div class="legend-item"><div class="legend-ring available"></div><span class="legend-text">可用 <span id="count-available">0</span></span></div> <div class="legend-item"><div class="legend-ring available"></div><span class="legend-text">可用 <span id="count-available">0</span></span></div>
@@ -212,7 +201,7 @@
<!-- 底部扫码栏 --> <!-- 底部扫码栏 -->
<div class="scan-bar"> <div class="scan-bar">
<label for="scan-input" class="sr-only">输入5位或8位车牌号</label><input class="scan-input" id="scan-input" type="text" inputmode="numeric" pattern="(?:[0-9]{5}|[0-9]{8})" maxlength="8" placeholder="输入5位或8位车牌号" autocomplete="off" /> <label for="scan-input" class="sr-only">输入5位或8位车牌号</label><input class="scan-input" id="scan-input" type="text" inputmode="numeric" pattern="(?:[0-9]{5}|[0-9]{8})" maxlength="8" placeholder="5位或8位车牌号" autocomplete="off" />
<button class="scan-btn" onclick="scanCode()">查询</button> <button class="scan-btn" onclick="scanCode()">查询</button>
</div> </div>
@@ -343,7 +332,7 @@
<button class="settings-link-row" onclick="openAuthModal()"><span class="map-setting-copy"><strong>微信凭证</strong><span>更新凭证与告警接收邮箱</span></span><span class="settings-chevron" aria-hidden="true">›</span></button> <button class="settings-link-row" onclick="openAuthModal()"><span class="map-setting-copy"><strong>微信凭证</strong><span>更新凭证与告警接收邮箱</span></span><span class="settings-chevron" aria-hidden="true">›</span></button>
<button class="settings-link-row" onclick="openDevicesModal()"><span class="map-setting-copy"><strong>登录设备</strong><span>查看和管理已登录的设备</span></span><span class="settings-chevron" aria-hidden="true">›</span></button> <button class="settings-link-row" onclick="openDevicesModal()"><span class="map-setting-copy"><strong>登录设备</strong><span>查看和管理已登录的设备</span></span><span class="settings-chevron" aria-hidden="true">›</span></button>
</div> </div>
<button class="settings-link-row" onclick="openVersionModal()"><span class="map-setting-copy"><strong>版本与使用说明</strong><span>查看更新记录与找车帮助</span></span><span aria-hidden="true">›</span></button><button class="settings-logout" onclick="handleLogout()">退出登录</button> <button class="settings-link-row" onclick="openVersionModal()"><span class="map-setting-copy"><strong>版本与使用说明</strong><span>查看更新记录与找车帮助</span></span><span aria-hidden="true">›</span></button><button class="settings-link-row" onclick="uiNavigate('/analysis.html')"><span class="map-setting-copy"><strong>数据分析</strong><span>查看车辆分布与历史趋势</span></span><span class="settings-chevron" aria-hidden="true">›</span></button>{% if preview_mode %}<div class="preview-settings"><span class="devices-tip">预览体验</span><div><button type="button" data-preview-demo onclick="previewLogin(this)">演示数据</button><button type="button" onclick="createPreviewSession()">真实接口测试</button></div></div>{% endif %}<button class="settings-logout" onclick="handleLogout()">退出登录</button>
</section> </section>
<!-- 账户功能子页面:统一标题、滚动区域与返回路径 --> <!-- 账户功能子页面:统一标题、滚动区域与返回路径 -->
<section class="settings-view" id="rental-settings-modal" hidden> <section class="settings-view" id="rental-settings-modal" hidden>
@@ -378,7 +367,7 @@
<section class="settings-view" id="auth-modal" hidden> <section class="settings-view" id="auth-modal" hidden>
<div class="settings-view-content"> <div class="settings-view-content">
<div class="auth-desc"> <div class="auth-desc">
从微信小程序抓包获取 hsf-x-tokenid 和 hsf-x-signature 从微信小程序获取 Token ID 和 AccessToken,保存前会验证凭证。
</div> </div>
<div class="profile-section"> <div class="profile-section">
<label class="profile-label">告警接收邮箱(凭据 1 天/1 小时过期、已过期时提醒,留空用账号邮箱)</label> <label class="profile-label">告警接收邮箱(凭据 1 天/1 小时过期、已过期时提醒,留空用账号邮箱)</label>
@@ -872,7 +861,7 @@
<div class="auth-tip" id="gate-tip"></div> <div class="auth-tip" id="gate-tip"></div>
<button type="submit" class="auth-submit">登录</button> <button type="submit" class="auth-submit">登录</button>
</form> </form>
<div class="discovery-welcome"><span><strong>三步找到车</strong><br>登录后按地点或定位找车,筛选电量与车型,再打开详情用车。</span></div>{% if preview_mode %}<button type="button" class="preview-login" onclick="previewLogin()">使用演示账号体验</button><button type="button" class="preview-login" onclick="createPreviewSession()">创建独立账号,测试真实接口</button>{% endif %} {% if preview_mode %}<div class="preview-entry"><button type="button" data-preview-demo onclick="previewLogin(this)">演示体验</button><span>·</span><button type="button" onclick="createPreviewSession()">真实接口测试</button></div>{% endif %}
<div class="login-gate-footer">没有账号?<a href="#" onclick="showRegisterModal(); return false;">注册</a> · <a href="#" onclick="showForgotFromGate(); return false;">忘记密码</a></div> <div class="login-gate-footer">没有账号?<a href="#" onclick="showRegisterModal(); return false;">注册</a> · <a href="#" onclick="showForgotFromGate(); return false;">忘记密码</a></div>
</div> </div>
</div> </div>