Update micBrowserSession.js via upload script - 2026-09-21 02:21:26

This commit is contained in:
mike 2026-09-21 02:21:35 +08:00
parent 229c61d8cf
commit 513316a3b6
1 changed files with 58 additions and 0 deletions

View File

@ -207,6 +207,64 @@ class MicBrowserSession {
this.log(`✓ 型号: ${model}`); this.log(`✓ 型号: ${model}`);
} }
// "规格"字段(选择器 input[name="prodStandard"],来自原脚本),填产品尺寸。
// 没有尺寸数据时直接跳过,不当错误处理。
async fillSpec(specText) {
if (!specText) { this.log('(没有尺寸数据,跳过"规格"字段)'); return; }
try {
const el = await this.page.waitForSelector('input[name="prodStandard"]', { timeout: 5000 });
await this.slowType(el, specText, 15);
await this.page.evaluate(() => {
document.querySelector('input[name="prodStandard"]')?.dispatchEvent(new Event('input', { bubbles: true }));
});
this.log(`✓ 规格: ${specText}`);
} catch (e) {
this.log(`规格填写失败: ${e.message}`, 'WARNING');
}
}
// "单个包裹尺寸"三个独立输入框:packDepth(长)/packWidth(宽)/packHeight(高),
// 单位是cm。depthCm/widthCm/heightCm 三个都是数字或数字字符串,缺哪个就跳过哪个。
async fillPackageDimensions({ depthCm, widthCm, heightCm }) {
const fields = [
['packDepth', '长', depthCm],
['packWidth', '宽', widthCm],
['packHeight', '高', heightCm],
];
for (const [name, label, value] of fields) {
if (value === undefined || value === null || value === '') continue;
try {
const el = await this.page.waitForSelector(`input[name="${name}"]`, { timeout: 5000 });
await this.slowType(el, String(value), 15);
await this.page.evaluate((n) => {
document.querySelector(`input[name="${n}"]`)?.dispatchEvent(new Event('input', { bubbles: true }));
}, name);
this.log(`✓ 包裹尺寸-${label}: ${value} cm`);
} catch (e) {
this.log(`包裹尺寸-${label} 填写失败: ${e.message}`, 'WARNING');
}
}
}
// "单个包裹毛重",选择器 input[name="grossWeight"],单位kg。
async fillPackageWeight(weightKg) {
if (weightKg === undefined || weightKg === null || weightKg === '') {
this.log('(没有重量数据,跳过"单个包裹毛重"字段)');
return;
}
try {
const el = await this.page.waitForSelector('input[name="grossWeight"]', { timeout: 5000 });
await this.slowType(el, String(weightKg), 15);
await this.page.evaluate(() => {
document.querySelector('input[name="grossWeight"]')?.dispatchEvent(new Event('input', { bubbles: true }));
});
this.log(`✓ 单个包裹毛重: ${weightKg} kg`);
} catch (e) {
this.log(`单个包裹毛重填写失败: ${e.message}`, 'WARNING');
}
}
// attrList: [{ name, value }, ...],已由 micFieldMapping.js 净化/排序好 // attrList: [{ name, value }, ...],已由 micFieldMapping.js 净化/排序好
async fillAttributes(attrList) { async fillAttributes(attrList) {
// MIC这个属性区实际硬上限是15行(不是20)——超过这个数点"添加自定义属性" // MIC这个属性区实际硬上限是15行(不是20)——超过这个数点"添加自定义属性"