feat(web-ui): 重构地图设置与目标列表页面并优化实时地图导航体验

- 重构地图设置页面布局,采用 flex 替代 grid,新增导航栏、标签页
  和下载步骤组件,改善响应式断点适配
- 将目标列表管理从侧边抽屉方案改为全页面内联编辑器,包含表格视图
  与分类侧栏,支持移动端卡片式降级展示
- 为实时地图屏幕添加半透明毛玻璃导航栏样式,支持 backdrop-filter
  降级,并在地图模式下调整内容区域偏移量
- 修复地图渲染器在画布尺寸为 0 时的边界异常,增加宽高校验
- 优化 fitBounds 的 padding 计算,改为基于容器宽度的比例值并
  限制最大值,避免小屏下地图偏移过大
- 新增 B5、B6、B7 三组 SVG 壁纸资源
```
This commit is contained in:
2026-10-23 14:50:27 +08:00
parent cd1b717e74
commit 461e2c8e7f
29 changed files with 910 additions and 319 deletions
+58 -14
View File
@@ -34,12 +34,12 @@ try{
for(const name of ['map-settings.css','map-settings-adapter.js','map-loader.js','map-adapter.js'])assert.equal(await(await fetch(base+'/'+name)).text(),await readFile(path.resolve('crates/web-ui/public',name),'utf8'),'stale embedded asset: '+name);
page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(/Content Security Policy|Refused to/i.test(m.text()))csp.push(m.text());});
const retryPage=await browser.newPage();let initialAttempts=0;await retryPage.route('**/api/maps/preferences',route=>++initialAttempts===1?route.fulfill({status:503,contentType:'application/json',body:JSON.stringify({error:'模拟首次读取失败'})}):route.continue());
await retryPage.goto(base);await retryPage.locator('#home-app-settings').click();await retryPage.locator('#appearance-view [data-open=maps]').click();await retryPage.waitForFunction(()=>document.querySelector('#map-save-message').textContent.includes('模拟首次读取失败'));assert.equal(await retryPage.locator('[data-map-action=reload]').isEnabled(),true,'initial load failure disabled retry');await retryPage.locator('[data-map-action=reload]').click();await retryPage.waitForFunction(()=>!document.querySelector('#map-save').disabled);assert.equal(initialAttempts,2);await retryPage.close();
await retryPage.goto(base);await retryPage.locator('#home-app-settings').click();await retryPage.locator('.reference-rail [data-open=maps]').click();await retryPage.waitForFunction(()=>document.querySelector('#map-save-message').textContent.includes('模拟首次读取失败'));assert.equal(await retryPage.locator('[data-map-action=reload]').isEnabled(),true,'initial load failure disabled retry');await retryPage.locator('[data-map-action=reload]').click();await retryPage.waitForFunction(()=>!document.querySelector('#map-save').disabled);assert.equal(initialAttempts,2);await retryPage.close();
// Switching away and back during the first load must not create competing responses.
let releaseLoad,firstLoad,loadRequests=0;const loadGate=new Promise(r=>releaseLoad=r),loadSeen=new Promise(r=>firstLoad=r);const pendingLoads=[];
const holdLoad=route=>{const work=(async()=>{loadRequests++;firstLoad();const response=await route.fetch();await loadGate;await route.fulfill({response});})();pendingLoads.push(work);return work;};
await page.route('**/api/maps/preferences',holdLoad);
try{await page.goto(base);await page.locator('#home-app-settings').click();await page.locator('#appearance-view [data-open=maps]').click();await loadSeen;await page.locator('#map-settings-view [data-open=settings]').click();await page.locator('#appearance-view [data-open=maps]').click();await page.waitForTimeout(250);assert.equal(loadRequests,1,'first load duplicated by rapid settings navigation');}
try{await page.goto(base);await page.locator('#home-app-settings').click();await page.locator('.reference-rail [data-open=maps]').click();await loadSeen;await page.locator('.reference-rail [data-open=settings]').click();await page.locator('.reference-rail [data-open=maps]').click();await page.waitForTimeout(250);assert.equal(loadRequests,1,'first load duplicated by rapid settings navigation');}
finally{releaseLoad();await Promise.all(pendingLoads);await page.unroute('**/api/maps/preferences',holdLoad);}
await page.locator('#map-save').waitFor();await page.waitForFunction(()=>!document.querySelector('#map-save').disabled);
assert.equal(await page.locator('#map-settings-view').getAttribute('tabindex'),'-1');
@@ -51,20 +51,47 @@ try{
finally{releaseSave();await saveSent;await page.unroute('**/api/maps/preferences',holdSave);}
await page.waitForFunction(()=>!document.querySelector('#map-save').disabled);
await page.waitForFunction(()=>window.ridMapSettings?.metrics()?.camera);
await page.locator('#map-settings-drawer [data-map-action=drawer]').click();assert.equal(await page.locator('#map-settings-drawer').isHidden(),true);await page.locator('.map-settings-head [data-map-action=drawer]').click();
await page.locator('.map-settings-head [data-map-action=point]').click();await page.locator('#settings-map').click({position:{x:220,y:220}});assert.match(await page.locator('#map-save-message').textContent(),/起始点已选定/);
await page.locator('#map-tab-location').focus();await page.keyboard.press('ArrowRight');assert.equal(await page.locator('#map-tab-downloads').getAttribute('aria-selected'),'true');
await page.locator('#map-step-next').click();assert.match(await page.locator('#map-step-message').textContent(),/有效范围/);assert.equal(await page.locator('#map-step-region').isVisible(),true);
await page.keyboard.press('Home');await page.locator('#map-tab-location').click();
await page.locator('#map-location-panel [data-map-action=point]').click();await page.locator('#settings-map').click({position:{x:220,y:220}});assert.match(await page.locator('#map-save-message').textContent(),/起始点已选定/);
await page.locator('#map-longitude').fill('181');await page.locator('#map-save').click();assert.match(await page.locator('#map-save-message').textContent(),/有效经纬度/);
await page.locator('#map-longitude').fill('116.4');await page.locator('#map-latitude').fill('39.9');await page.locator('#map-zoom').fill('12');await page.locator('#map-basemap').selectOption('road');await page.locator('#map-save').click();await page.waitForFunction(()=>document.querySelector('#map-save-message').textContent.includes('已保存'));
assert.equal((await json('/api/maps/preferences')).value.longitude,116.4);
// Unsaved fields survive a settings navigation within this document.
await page.locator('#map-longitude').fill('116.41');await page.locator('#map-settings-view [data-open=settings]').click();await page.locator('#appearance-view [data-open=maps]').click();assert.equal(await page.locator('#map-longitude').inputValue(),'116.41');await page.locator('#map-longitude').fill('116.4');
await page.locator('#map-basemap').selectOption('imagery');await page.locator('#map-settings-view [data-open=settings]').click();await page.locator('#appearance-view [data-open=maps]').click();await page.waitForFunction(()=>window.ridMapSettings?.metrics()?.camera);assert.equal(await page.locator('#map-basemap').inputValue(),'imagery');assert.equal(await page.evaluate(()=>window.ridMapSettings.metrics().basemap),'imagery','unsaved basemap disagrees with preview after navigation');await page.locator('#map-basemap').selectOption('road');
await page.locator('.map-settings-head [data-map-action=box]').click();const rect=await page.locator('#settings-map').boundingBox();await page.mouse.move(rect.x+100,rect.y+100);await page.mouse.down();await page.mouse.move(rect.x+260,rect.y+230,{steps:8});await page.mouse.up();assert.ok(Number(await page.locator('#map-west').inputValue())<Number(await page.locator('#map-east').inputValue()));
for(const [id,v]of Object.entries({'map-west':'120.15','map-south':'30.28','map-east':'120.16','map-north':'30.29','map-min-zoom':'11','map-max-zoom':'11'}))await page.locator('#'+id).fill(v);
await page.locator('#map-region-name').fill('验收常用区域');await page.locator('[data-map-action=region-save]').click();await page.locator('#map-save').click();await page.waitForFunction(()=>document.querySelector('#map-save-message').textContent.includes('已保存'));
await page.locator('#map-estimate').click();await page.waitForFunction(()=>document.querySelector('#map-estimate-message').textContent.includes('共 4 张'));
await page.locator('#map-longitude').fill('116.41');await page.locator('.reference-rail [data-open=settings]').click();await page.locator('.reference-rail [data-open=maps]').click();assert.equal(await page.locator('#map-longitude').inputValue(),'116.41');await page.locator('#map-longitude').fill('116.4');
await page.locator('#map-basemap').selectOption('imagery');await page.locator('.reference-rail [data-open=settings]').click();await page.locator('.reference-rail [data-open=maps]').click();await page.waitForFunction(()=>window.ridMapSettings?.metrics()?.camera);assert.equal(await page.locator('#map-basemap').inputValue(),'imagery');assert.equal(await page.evaluate(()=>window.ridMapSettings.metrics().basemap),'imagery','unsaved basemap disagrees with preview after navigation');await page.locator('#map-basemap').selectOption('road');
await page.locator('#map-tab-downloads').click();await page.locator('[data-map-action=box]').click();const rect=await page.locator('#settings-map').boundingBox();await page.mouse.move(rect.x+100,rect.y+100);await page.mouse.down();await page.mouse.move(rect.x+260,rect.y+230,{steps:8});await page.mouse.up();assert.ok(Number(await page.locator('#map-west').inputValue())<Number(await page.locator('#map-east').inputValue()));
await page.locator('.map-advanced summary').click();
for(const [id,v]of Object.entries({'map-west':'120.15','map-south':'30.28','map-east':'120.16','map-north':'30.29'}))await page.locator('#'+id).fill(v);
await page.locator('#map-region-name').fill('验收常用区域');await page.locator('[data-map-action=region-save]').click();
await page.locator('#map-tab-location').click();await page.locator('#map-longitude').fill('117.5');await page.locator('#map-tab-downloads').click();
await page.locator('#map-region-persist').click();await page.waitForFunction(()=>document.querySelector('#map-region-persist').disabled && document.querySelector('#map-region-message').textContent.includes('已保存'));
assert.equal((await json('/api/maps/preferences')).value.longitude,116.4,'region save persisted location draft');
await page.locator('#map-region').selectOption('0');await page.locator('[data-map-action=region-delete]').click();assert.equal(await page.locator('#map-region option').count(),1);await page.locator('#map-region-persist').click();await page.waitForFunction(()=>document.querySelector('#map-region-persist').disabled);assert.equal((await json('/api/maps/preferences')).value.regions.length,0);
await page.locator('[data-map-action=region-save]').click();await page.locator('#map-region-persist').click();await page.waitForFunction(()=>document.querySelector('#map-region-persist').disabled);assert.equal((await json('/api/maps/preferences')).value.regions[0].name,'验收常用区域');
await page.locator('#map-tab-location').click();assert.equal(await page.locator('#map-longitude').inputValue(),'117.5');await page.locator('#map-longitude').fill('116.4');await page.locator('#map-tab-downloads').click();
await page.locator('#map-step-next').click();await page.locator('#map-min-zoom').fill('19');await page.locator('#map-step-next').click();assert.equal(await page.locator('#map-step-layers').isVisible(),true);assert.match(await page.locator('#map-step-message').textContent(),/0–18/);
await page.locator('#map-min-zoom').fill('11');await page.locator('#map-max-zoom').fill('11');
let starts=0;page.on('request',r=>{if(r.method()==='POST'&&new URL(r.url()).pathname==='/api/maps/downloads')starts++});
let failEstimate=true;await page.route('**/api/maps/downloads/estimate',route=>failEstimate?(failEstimate=false,route.fulfill({status:503,contentType:'application/json',body:JSON.stringify({error:'模拟核算失败'})})):route.continue());
await page.locator('#map-step-next').click();await page.waitForFunction(()=>document.querySelector('#map-step-message').textContent.includes('模拟核算失败'));assert.equal(await page.locator('#map-download-start').isDisabled(),true);
await page.locator('#map-estimate').click();await page.waitForFunction(()=>document.querySelector('#map-estimate-message').textContent.includes('共 4 张'));assert.equal(starts,0,'estimate started download');
await page.locator('#map-step-back').click();await page.locator('#map-max-zoom').fill('12');await page.locator('#map-max-zoom').fill('11');assert.equal(await page.locator('#map-download-start').isDisabled(),true,'changed draft kept old estimate');
await page.locator('#map-step-next').click();await page.waitForFunction(()=>!document.querySelector('#map-download-start').disabled);await page.unroute('**/api/maps/downloads/estimate');
await page.locator('#map-download-start').click();const done=await job('completed');assert.equal(done.done,4);assert.equal(done.failed,0);
for(const layer of ['vec_w','cva_w','img_w','cia_w'])assert.deepEqual(await readFile(path.join(root,`maps/offline/${layer}/11/${x}/${y}.png`)),png);
// UI state for an already-running task, including re-entry and explicit cancellation.
let uiRunning=true,cancelClicks=0;
await page.route('**/api/maps/downloads',route=>route.request().method()==='GET'?route.fulfill({contentType:'application/json',body:JSON.stringify({available:true,job:{state:uiRunning?'running':'cancelled',message:uiRunning?'测试任务下载中':'测试任务已取消',done:1,total:4}})}):route.continue());
await page.route('**/api/maps/downloads/cancel',route=>{cancelClicks++;uiRunning=false;return route.fulfill({contentType:'application/json',body:JSON.stringify({message:'已请求取消'})})});
await page.waitForFunction(()=>!document.querySelector('#map-download-cancel').hidden);
assert.equal(await page.locator('[data-map-action=step-region]').isDisabled(),true);assert.equal(await page.locator('#map-west').isDisabled(),true);
await page.locator('#map-tab-location').click();await page.locator('#map-tab-downloads').click();assert.equal(await page.locator('#map-step-review').isVisible(),true);
await page.locator('#map-download-cancel').click();await page.waitForFunction(()=>document.querySelector('#map-download-message').textContent.includes('测试任务已取消'));assert.equal(cancelClicks,1);
await page.unroute('**/api/maps/downloads');await page.unroute('**/api/maps/downloads/cancel');
// Offline files remain readable even after the online cache is no longer needed.
const tile=await fetch(base+`/api/maps/tile/vec_w/11/${x}/${y}`);assert.equal(tile.status,200);
const task={bounds:{west:120.15,south:30.28,east:120.16,north:30.29},minZoom:16,maxZoom:16,road:true,imagery:true};
@@ -80,12 +107,29 @@ try{
assert.equal(await page.evaluate(()=>window.ridMap.metrics().basemap),'road');
assert.equal((await json('/api/realtime/ingest','POST',[{target_id:'MAP-REVIEW-001',receiver_id:'MAP-REVIEW',source_epoch:1,sequence:1,longitude:120.1538,latitude:30.2874,altitude_m:120,heading_deg:0}])).status,200);await page.waitForFunction(()=>window.ridMap.metrics().targets>0);const populatedCamera=await page.evaluate(()=>window.ridMap.metrics().camera);assert.ok(Math.abs(populatedCamera.center[0]-116.4)<.0001,'initial telemetry replaced configured map center');
await page.getByRole('button',{name:'MAP-REVIEW-001',exact:true}).click();await page.getByRole('button',{name:'聚焦此目标',exact:true}).click();await page.waitForFunction(()=>{const c=window.ridMap.metrics().camera.center;return Math.abs(c[0]-120.1538)<.1&&Math.abs(c[1]-30.2874)<.1});
await page.locator('[data-open=settings]').first().click();await page.locator('#appearance-view [data-open=maps]').click();await page.waitForFunction(()=>!document.querySelector('#map-save').disabled);await page.waitForFunction(()=>window.ridMapSettings?.metrics()?.camera);
await page.locator('[data-open=settings]').first().click();await page.locator('.reference-rail [data-open=maps]').click();await page.waitForFunction(()=>!document.querySelector('#map-save').disabled);await page.waitForFunction(()=>window.ridMapSettings?.metrics()?.camera);
assert.equal(await page.locator('#map-region option').count(),2);await page.waitForFunction(()=>!document.querySelector('#map-network-note').textContent.includes('正在检查'));
await page.route('**/api/maps/status',route=>route.abort('connectionfailed'));await page.waitForFunction(()=>document.querySelector('#map-network-note').textContent.includes('无法连接本机地图服务'));await page.unroute('**/api/maps/status');await page.waitForFunction(()=>document.querySelector('#map-network-note').textContent.includes('密钥未配置'));
await page.screenshot({path:path.resolve('previews/map-settings-live-C-20261023.png')});
await page.locator('#map-tab-downloads').click();await page.locator('[data-map-action=step-region]').click();await page.locator('#map-region').selectOption('0');await page.locator('#map-step-next').click();await page.locator('#map-min-zoom').fill('11');await page.locator('#map-max-zoom').fill('11');await page.locator('#map-step-next').click();await page.waitForFunction(()=>!document.querySelector('#map-download-start').disabled);
await page.locator('#map-tab-location').click();
for(const [width,height]of [[1600,900],[1366,768],[900,700],[390,844],[1200,540]]){
await page.setViewportSize({width,height});
for(const tab of ['location','downloads']){
await page.locator('#map-tab-'+tab).click();
if(tab==='downloads')await page.locator('[data-map-action=step-review]').click();
const button=page.locator(tab==='location'?'#map-save':'#map-download-start');await button.scrollIntoViewIfNeeded();
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true,`${width} ${tab} overflow`);
if(tab==='location'&&width>=1366)assert.equal(await page.locator('#map-location-panel .map-settings-scroll').evaluate(e=>e.scrollHeight<=e.clientHeight+1),true,'common map settings still require scrolling');
const b=await button.boundingBox();assert.ok(b.x>=0&&b.x+b.width<=width+1&&b.y>=48&&b.y+b.height<=height+1,JSON.stringify({width,tab,b}));
await page.screenshot({path:path.resolve(`previews/map-settings-${tab}-${width}x${height}.png`)});
}
}
await page.setViewportSize({width:1366,height:768});await page.evaluate(()=>document.documentElement.style.zoom='2');await page.locator('#map-tab-location').click();await page.locator('#map-save').scrollIntoViewIfNeeded();assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);await page.evaluate(()=>document.documentElement.style.zoom='');
await page.setViewportSize({width:800,height:1000});assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
await stop();start();await ready();const reloaded=(await json('/api/maps/preferences')).value;assert.equal(reloaded.longitude,116.4);assert.equal(reloaded.regions[0].name,'验收常用区域');
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
report={status:'PASS',root,camera,download:done,scenarios:['actual C drawer and MapLibre point selection','pending save locks edits and ignores late map callbacks','invalid coordinates','default camera survives first telemetry','coordinates and unsaved basemap retained across navigation','saved region reload','actual Go sidecar and four-layer offline raster validation','download cancellation and single-job limit','unavailable tiles fail honestly','local service failure and automatic recovery','foreign origin rejection','800px width','no page errors or CSP violations']};console.log(JSON.stringify(report));
}finally{await browser?.close();await stop();for(const socket of sockets)socket.destroy();proxy.closeAllConnections();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));}
report={status:'PASS',root,camera,download:done,scenarios:['A layout and C wizard with real MapLibre','step validation and estimate retry','region save preserves location draft','parameter edits invalidate estimate','five viewport sizes and 200percent zoom','pending save locks edits and ignores late map callbacks','invalid coordinates','default camera survives first telemetry','coordinates and unsaved basemap retained across navigation','saved region reload','actual Go sidecar and four-layer offline raster validation','download cancellation and single-job limit','unavailable tiles fail honestly','local service failure and automatic recovery','foreign origin rejection','800px width','no page errors or CSP violations']};console.log(JSON.stringify(report));
}catch(error){console.error('MAP TEST FAILED',root,error.stack);const page=browser?.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.resolve('previews/map-settings-failure.png'),fullPage:true}).catch(()=>{});throw error;}finally{await browser?.close();await stop();for(const socket of sockets)socket.destroy();proxy.closeAllConnections();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));}