Files
2026-07-13 19:57:46 +08:00

80 lines
3.2 KiB
JavaScript

const { chromium } = require('playwright-core');
const fs = require('node:fs');
const path = require('node:path');
const PROFILE = 'C:\\Users\\wxy\\AppData\\Local\\LTJT-ERP-Hermes-Chrome';
const CHROME = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
const ERP = 'https://ltjt.yunzhi.run';
const GROUP = 'LLW-260802A-A';
const DDID = '14037';
const OUTPUT = 'C:\\Users\\wxy\\Documents\\泰国下单skill\\runtime\\erp-order-entry\\outputs';
const DOWNLOADS = 'C:\\Users\\wxy\\Documents\\泰国下单skill\\runtime\\erp-order-entry\\downloads';
const EXPORTS = [
{ key: 'liantai-confirm', url: `${ERP}/System/Business/orders_confirm_new.asp?did=${DDID}&tid=${DDID}` },
{ key: 'xingyou-confirm', url: `${ERP}/System/Business/orders_confirm_news.asp?did=${DDID}&tid=${DDID}` },
{ key: 'job-order', url: `${ERP}/System/Business/teams_beian1.asp?did=${DDID}` },
];
async function main() {
fs.mkdirSync(OUTPUT, { recursive: true });
fs.mkdirSync(DOWNLOADS, { recursive: true });
const context = await chromium.launchPersistentContext(PROFILE, {
executablePath: CHROME, headless: false, viewport: { width: 1440, height: 900 },
acceptDownloads: true, downloadsPath: DOWNLOADS,
});
const page = context.pages()[0] || await context.newPage();
const results = [];
for (const exp of EXPORTS) {
try {
console.log(`\n=== Exporting ${exp.key}: ${exp.url} ===`);
await page.goto(exp.url, { waitUntil: 'domcontentloaded', timeout: 30000 });
await page.waitForTimeout(2000);
// Check for error
const bodyText = await page.evaluate(() => document.body.innerText.slice(0, 500));
if (bodyText.includes('错误') || bodyText.includes('error') || bodyText.includes('不存在')) {
console.log(` ERROR: ${bodyText}`);
results.push({ key: exp.key, status: 'error', message: bodyText });
continue;
}
// Click export button if present
const exportBtn = await page.$('input[value*="导出"], input[value*="export"], button:has-text("导出"), a:has-text("导出"), input[value*="Word"], input[value*="word"]');
if (exportBtn) {
console.log(' Clicking export button...');
await exportBtn.click();
await page.waitForTimeout(3000);
}
// Check for downloads
const files = fs.readdirSync(DOWNLOADS).sort((a, b) => {
return fs.statSync(path.join(DOWNLOADS, b)).mtimeMs - fs.statSync(path.join(DOWNLOADS, a)).mtimeMs;
});
const recent = files.slice(0, 5);
console.log(` Recent downloads: ${JSON.stringify(recent)}`);
// Try to save page content as doc
const content = await page.content();
const docPath = path.join(OUTPUT, `${GROUP}_${exp.key}.doc`);
fs.writeFileSync(docPath, content, 'utf8');
console.log(` Saved page to: ${docPath} (${content.length} bytes)`);
results.push({ key: exp.key, status: 'ok', path: docPath, size: content.length });
} catch (err) {
console.log(` Exception: ${err.message}`);
results.push({ key: exp.key, status: 'error', message: err.message });
}
}
console.log(`\n=== Results ===`);
console.log(JSON.stringify(results, null, 2));
await context.close();
}
main();