refactor: restore acrylic map UI and collapse mobile discovery tools
This commit is contained in:
@@ -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 || "登录失败";
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
})();
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user