debug_furniture_zoom_position.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { chromium } = require('playwright');
  2. const fs = require('fs');
  3. (async () => {
  4. const browser = await chromium.launch({ headless: true, executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe' });
  5. const page = await browser.newPage({ viewport: { width: 1800, height: 2000 } });
  6. const errors = [];
  7. page.on('pageerror', error => errors.push(error.message));
  8. await page.goto('http://127.0.0.1:8931/AI%E5%BF%AB%E9%80%9F%E6%8A%A5%E4%BB%B7_Demo2.html?v=zoom-position-test', { waitUntil: 'load' });
  9. const image = fs.readFileSync('C:/Users/miao/Downloads/494f54100a93c5a6e0c90f404c597514.jpeg').toString('base64');
  10. await page.evaluate(data => {
  11. qUploadedDrawing = { name:'zoom.jpeg', size:data.length, type:'image/jpeg' };
  12. qUploadedDrawingUrl = 'data:image/jpeg;base64,' + data;
  13. qUploadedDrawingDataUrl = qUploadedDrawingUrl;
  14. qStartAnalysis();
  15. }, image);
  16. await page.waitForTimeout(600);
  17. await page.locator('#q-floorplan-layout-workspace').scrollIntoViewIfNeeded();
  18. const tool = page.locator('.q-furniture-tool').filter({ hasText:'主卧衣柜' }).first();
  19. const workspace = page.locator('#q-floorplan-layout-workspace');
  20. const drawing = page.locator('#q-ai-cleaned-img');
  21. const ir = await drawing.boundingBox(), toolBox = await tool.boundingBox();
  22. const target1 = { x:ir.x + ir.width*.32, y:ir.y + ir.height*.43 };
  23. await page.mouse.move(toolBox.x+toolBox.width/2,toolBox.y+toolBox.height/2);
  24. await page.mouse.down();
  25. await page.mouse.move(target1.x,target1.y,{steps:10});
  26. await page.mouse.up();
  27. await page.waitForTimeout(150);
  28. const sticker = page.locator('.q-furniture-v3').first();
  29. const b1 = await sticker.boundingBox();
  30. const error1 = Math.hypot(b1.x+b1.width/2-target1.x, b1.y+b1.height/2-target1.y);
  31. const target2 = { x:ir.x + ir.width*.72, y:ir.y + ir.height*.62 };
  32. await page.mouse.move(b1.x+b1.width/2,b1.y+b1.height/2);
  33. await page.mouse.down();
  34. await page.mouse.move(target2.x,target2.y,{steps:8});
  35. await page.mouse.up();
  36. await page.waitForTimeout(100);
  37. const b2 = await sticker.boundingBox();
  38. const error2 = Math.hypot(b2.x+b2.width/2-target2.x, b2.y+b2.height/2-target2.y);
  39. const state = await page.evaluate(() => ({ zoom:getComputedStyle(document.body).zoom, item:qFurnitureLayout[0] }));
  40. await sticker.dblclick({ delay: 100 });
  41. await page.waitForTimeout(120);
  42. const remainingAfterDoubleClick = await page.locator('.q-furniture-v3').count();
  43. console.log(JSON.stringify({ errorAfterDrop:+error1.toFixed(2), errorAfterMove:+error2.toFixed(2), remainingAfterDoubleClick, state, errors }));
  44. await browser.close();
  45. })().catch(error => { console.error(error); process.exit(1); });