feat(web-ui): 重构地图设置与目标列表页面并优化实时地图导航体验 - 重构地图设置页面布局,采用 flex 替代 grid,新增导航栏、标签页 和下载步骤组件,改善响应式断点适配 - 将目标列表管理从侧边抽屉方案改为全页面内联编辑器,包含表格视图 与分类侧栏,支持移动端卡片式降级展示 - 为实时地图屏幕添加半透明毛玻璃导航栏样式,支持 backdrop-filter 降级,并在地图模式下调整内容区域偏移量 - 修复地图渲染器在画布尺寸为 0 时的边界异常,增加宽高校验 - 优化 fitBounds 的 padding 计算,改为基于容器宽度的比例值并 限制最大值,避免小屏下地图偏移过大 - 新增 B5、B6、B7 三组 SVG 壁纸资源 ```
41 lines
9.3 KiB
JavaScript
41 lines
9.3 KiB
JavaScript
// Real SQLite, Rust/Wasm, Worker and WebGL acceptance. No physical transports opened.
|
|
import {mkdtemp,readFile,writeFile} from 'node:fs/promises';
|
|
import {tmpdir} from 'node:os';
|
|
import path from 'node:path';
|
|
import http from 'node:http';
|
|
import net from 'node:net';
|
|
import {spawn} from 'node:child_process';
|
|
import {createRequire} from 'node:module';
|
|
import assert from 'node:assert/strict';
|
|
const {chromium}=createRequire(import.meta.url)('playwright');
|
|
const root=await mkdtemp(path.join(tmpdir(),'RID-list-page-'));
|
|
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
|
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
|
let base,child,browser,heartbeat,output='';const errors=[],csp=[],sockets=new Set();
|
|
const proxy=http.createServer(async(req,res)=>{if(process.env.RID_SOURCE_ASSETS==='1'&&!req.url.startsWith('/api/')){const pathname=new URL(req.url,'http://localhost').pathname;const relative=pathname==='/'||pathname==='/realtime'?'index.html':pathname.slice(1);if(!relative.includes('..'))try{let bytes;try{bytes=await readFile(path.join('crates/web-ui/public',relative));}catch{bytes=await readFile(path.join('dist/web-ui',relative));}res.writeHead(200,{'content-type':relative.endsWith('.html')?'text/html':relative.endsWith('.css')?'text/css':relative.endsWith('.wasm')?'application/wasm':relative.endsWith('.svg')?'image/svg+xml':relative.endsWith('.png')?'image/png':'text/javascript'});res.end(bytes);return}catch{}}const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
|
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
|
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
|
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
|
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
|
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/target-lists')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)}
|
|
async function snapshot(){return(await fetch(base+'/api/target-lists')).json()}
|
|
async function save(id,kind,note='验收备注'){const current=await snapshot();const r=await fetch(base+'/api/target-lists/'+id,{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({list_kind:kind,note,expected_revision:current.revision})});assert.equal(r.status,200);return r.json()}
|
|
let report={};
|
|
try{
|
|
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
|
for(let i=0;i<115;i++)await save('PAGE-'+String(i).padStart(3,'0'),i%2?'white':'black','演示备注 '+i);
|
|
browser=await chromium.launch({headless:true,channel:'msedge'});const context=await browser.newContext({viewport:{width:1366,height:768}});const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(/violates.*Content Security|Refused.*policy/i.test(m.text()))csp.push(m.text())});
|
|
await page.goto(base+'/realtime');await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();assert.equal(await page.locator('#rt-dock').isVisible(),false);const fullHeight=await page.locator('.live-list-body').evaluate(e=>e.clientHeight);assert.ok(fullHeight>=240,String(fullHeight));await page.locator('#rt-dock-restore').click();await wait(200);const dockHeight=await page.locator('.live-list-body').evaluate(e=>e.clientHeight);assert.ok(fullHeight-dockHeight>100);await page.getByRole('button',{name:'隐藏事件面板',exact:true}).click();
|
|
await page.getByRole('button',{name:'黑白名单管理',exact:true}).click();await page.locator('body[data-screen=target-lists]').waitFor();await page.getByRole('heading',{name:'黑白名单管理',exact:true}).waitFor();assert.equal(await page.locator('#workspace-content').isVisible(),false);assert.equal(await page.locator('#rt-list-manager .rt-list-row').count(),50);
|
|
const bounds=await page.locator('#rt-list-manager').boundingBox();assert.ok(bounds.width>1200&&bounds.x<90&&bounds.y<=50);assert.equal(await page.locator('[aria-modal=true]').count(),0);await page.locator('#rt-list-manager .rt-list-pagination').getByRole('button',{name:'下一页',exact:true}).click();await page.locator('.rt-list-row[data-target-id="PAGE-050"]').waitFor();
|
|
await page.getByRole('group',{name:'管理名单分类'}).getByRole('button',{name:/^白名单/}).click();await page.locator('.rt-list-row[data-target-id="PAGE-001"]').waitFor();assert.equal(await page.locator('.rt-list-row[data-target-id="PAGE-000"]').count(),0);
|
|
await page.locator('.rt-list-search input').fill('PAGE-001');await page.locator('.rt-list-row').getByRole('button',{name:'编辑',exact:true}).click();await page.locator('#rt-list-entry-note').fill('保留草稿');await page.getByRole('button',{name:'电子围栏',exact:true}).click();await page.locator('body[data-screen=geofences]').waitFor();await page.getByRole('button',{name:'黑白名单管理',exact:true}).click();assert.equal(await page.locator('#rt-list-entry-note').inputValue(),'保留草稿');assert.equal(await page.locator('.rt-list-search input').inputValue(),'PAGE-001');
|
|
for(const [width,height]of [[1600,1000],[1366,768],[900,700],[390,844],[1200,540]]){await page.setViewportSize({width,height});await page.locator('#rt-list-entry-form .primary').scrollIntoViewIfNeeded();assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);const box=await page.locator('#rt-list-entry-form .primary').boundingBox();assert.ok(box.x>=0&&box.x+box.width<=width+1&&box.y>=48&&box.y+box.height<=height+1);await page.screenshot({path:path.join(root,'manager-'+width+'x'+height+'.png'),fullPage:true});}
|
|
await page.setViewportSize({width:1280,height:720});await page.evaluate(()=>document.documentElement.style.zoom='2');await page.locator('#rt-list-entry-form .primary').scrollIntoViewIfNeeded();assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);await page.evaluate(()=>document.documentElement.style.zoom='');
|
|
await page.keyboard.press('Escape');await page.locator('body[data-screen=geofences]').waitFor();await page.setViewportSize({width:1366,height:768});await page.getByRole('button',{name:'黑白名单管理',exact:true}).click();await page.getByRole('button',{name:'返回工作区',exact:true}).click();await page.locator('body[data-screen=geofences]').waitFor();
|
|
// Full page is also available without mounting the realtime app; preserve registration draft.
|
|
await page.goto(base+'/?app=register');await page.locator('body[data-screen=register]').waitFor();const originalUrl=page.url();await page.getByRole('button',{name:'黑白名单管理',exact:true}).click();await page.locator('body[data-screen=target-lists]').waitFor();assert.equal(page.url(),originalUrl);await page.getByRole('button',{name:'返回工作区',exact:true}).click();await page.locator('body[data-screen=register]').waitFor();
|
|
await page.goto(base+'/?app=target-lists');await page.locator('body[data-screen=target-lists]').waitFor();await page.locator('.rt-list-row').first().waitFor();
|
|
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);report={status:'PASS',root,exe,fullHeight,dockHeight,checks:['left menu complete page','map hidden; not a dialog','both kinds and search','115 entries pagination','independent editor','draft and filter across pages','five sizes and 200percent','return to origin workspace','registration route retains document','direct bookmark','directory height expanded','default dock collapsed'],errors,csp};console.log(JSON.stringify(report));
|
|
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify(errors));if(browser){const page=browser.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.join(root,'failure.png'),fullPage:true}).catch(()=>{});}throw error;}finally{if(browser)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,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|