Files
LWLT-AI/archive/handoff/2026-07-12/legacy-erp-handoff/tools/erp_split_parent_probe.js
2026-07-13 19:57:46 +08:00

76 lines
3.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
const ROOT = path.resolve(__dirname, '..');
const PROFILE = path.join(ROOT, 'diagnostics', 'erp-playwright-profile');
const RUN_ID = new Date().toISOString().replace(/[-:T.Z]/g, '').slice(0, 14);
const RUN_DIR = path.join(ROOT, 'diagnostics', 'split-parent-probe', `run-${RUN_ID}`);
fs.mkdirSync(RUN_DIR, { recursive: true });
async function setField(frame, selector, value) {
const locator = frame.locator(selector).first();
await locator.fill(String(value));
await locator.evaluate((el) => {
el.dispatchEvent(new Event('input', { bubbles: true }));
el.dispatchEvent(new Event('change', { bubbles: true }));
el.dispatchEvent(new Event('blur', { bubbles: true }));
});
}
async function dump(page, name) {
const frames = [];
for (const frame of page.frames()) {
const data = await frame.evaluate(() => ({
url: location.href,
bodyText: document.body.innerText.replace(/\s+/g, ' ').slice(0, 3500),
values: Array.from(document.querySelectorAll('input')).map((el) => ({
id: el.id || '',
name: el.name || '',
type: el.type || '',
value: el.value || '',
checked: el.checked || false,
text: (el.innerText || '').replace(/\s+/g, ' ').trim(),
})).slice(0, 200),
})).catch((error) => ({ url: frame.url(), bodyText: `ERROR:${error.message}`, values: [] }));
frames.push(data);
}
fs.writeFileSync(path.join(RUN_DIR, `${name}.json`), JSON.stringify(frames, null, 2), 'utf8');
await page.screenshot({ path: path.join(RUN_DIR, `${name}.png`), fullPage: false });
console.log(JSON.stringify({ name, RUN_DIR, frames: frames.map((f) => ({ url: f.url, body: f.bodyText.slice(0, 260), inputs: f.values.length })) }, null, 2));
}
async function main() {
const context = await chromium.launchPersistentContext(PROFILE, {
headless: false,
viewport: { width: 1920, height: 1000 },
acceptDownloads: true,
});
const page = context.pages()[0] || await context.newPage();
page.setDefaultTimeout(15000);
try {
await page.goto('https://ltjt.yunzhi.run/System/Business/plan.asp', { waitUntil: 'domcontentloaded', timeout: 30000 });
await page.waitForTimeout(1200);
await page.locator('input[value="新增计划"], a:has-text("新增计划"), button:has-text("新增计划")').first().click();
await page.waitForTimeout(2000);
const frame = page.frames().find((f) => f.url().includes('/Business/plan_add.asp'));
if (!frame) throw new Error('plan_add frame not found');
await setField(frame, '#Riqi1', '2026-07-01');
await setField(frame, '#Riqi2', '2026-07-31');
await setField(frame, '#jihuashu', 10);
await setField(frame, '#jiedairen', '测试');
await frame.locator('input[name="zhouqi"][value="6"]').check();
await frame.locator('input[name="cpid"][value="412"]').check();
await page.waitForTimeout(2500);
await dump(page, 'filled-no-save');
} finally {
await context.close();
}
}
main().catch((error) => {
console.error(error);
process.exit(1);
});