aliChoice 填到最后一步(差「请选择物流属性」);修 fillRequiredSelects 三个真 bug(attr-label.required 不认 / 容器项误点 / 下拉读残留)
This commit is contained in:
1 parent
acabadffd4
commit
924ca86fdc
6 files changed
+254
-40
No files matched your search
+20
-6
@@ -202,7 +202,9 @@ export async function fillRequiredSelects(c, skip = ['店铺账号', '产品分
|
||||
const r = await c.evalJS(`(()=>{
|
||||
const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>{
|
||||
if(e.offsetParent===null) return false;
|
||||
const req=e.querySelector('.attr-label.required')||e.querySelector('label.ant-form-item-required');
|
||||
const lab=e.querySelector('label');
|
||||
const req=e.querySelector('.attr-label.required')||(lab&&/required/.test(String(lab.className))?lab:null)
|
||||
||(lab&&(lab.innerText||'').trim().startsWith('*')?lab:null);
|
||||
if(!req) return false;
|
||||
const name=(req.innerText||'').replace(/\s+/g,' ').trim();
|
||||
if(${JSON.stringify(skip)}.some(s=>name.includes(s))) return false;
|
||||
@@ -229,8 +231,11 @@ export async function fillRequiredSelects(c, skip = ['店铺账号', '产品分
|
||||
for (let round = 0; round < 8; round++) {
|
||||
const tgt = JSON.parse(String(await c.evalJS(`(()=>{
|
||||
const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>{
|
||||
const l=e.querySelector('label'); if(!l||!/ant-form-item-required/.test(String(l.className))) return false;
|
||||
const l=e.querySelector('label');
|
||||
const reqOk = l && (/required/.test(String(l.className)) || (l.innerText||'').trim().startsWith('*') || e.querySelector('.attr-label.required'));
|
||||
if(!reqOk) return false;
|
||||
if(e.offsetParent===null) return false;
|
||||
if(e.querySelector('.ant-form-item')) return false; // 容器项(如「产品属性」):只管叶子项
|
||||
const name=(l.innerText||'').replace(/\\s+/g,' ').trim();
|
||||
if(${JSON.stringify(skip)}.some(s=>name.includes(s))) return false;
|
||||
const sel=e.querySelector('.ant-select'); if(!sel) return false;
|
||||
@@ -241,13 +246,22 @@ export async function fillRequiredSelects(c, skip = ['店铺账号', '产品分
|
||||
sel.scrollIntoView({block:'center'}); const r=sel.getBoundingClientRect();
|
||||
return JSON.stringify({name:(l.innerText||'').replace(/\\s+/g,' ').trim().slice(0,30), x:Math.round(r.x+r.width/2), y:Math.round(r.y+r.height/2)});})()`)));
|
||||
if (!tgt.name) break;
|
||||
await c.send('Input.dispatchKeyEvent', {type:'keyDown', key:'Escape', code:'Escape', windowsVirtualKeyCode:27}).catch(()=>{});
|
||||
await wait(400);
|
||||
await c.send('Input.dispatchMouseEvent', {type:'mouseMoved', x:tgt.x, y:tgt.y, buttons:0}); await wait(250);
|
||||
for (const t of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent', {type:t, x:tgt.x, y:tgt.y, button:'left', clickCount:1, buttons:1});
|
||||
await wait(1800);
|
||||
const pick = await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
|
||||
if(!dd) return 'no-dd';
|
||||
const op=[...dd.querySelectorAll('.ant-select-item-option')].filter(e=>e.offsetParent!==null)[0];
|
||||
if(!op) return 'no-op';
|
||||
if (/产地|Origin/i.test(tgt.name)) { await c.send('Input.insertText', {text:'中国'}).catch(()=>{}); await wait(1500); }
|
||||
const pick = await c.evalJS(`(()=>{const cy=${JSON.stringify(tgt.y)};
|
||||
const cands=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null);
|
||||
if(!cands.length) return 'no-dd';
|
||||
const dd=cands.map(e=>({e,d:Math.abs(e.getBoundingClientRect().top-cy)})).sort((a,b)=>a.d-b.d)[0].e;
|
||||
const ops=[...dd.querySelectorAll('.ant-select-item-option')].filter(e=>e.offsetParent!==null);
|
||||
if(!ops.length) return 'no-op';
|
||||
const want=${JSON.stringify(tgt.name)};
|
||||
const clean=x=>(x.innerText||'').replace(/\s+/g,' ').trim();
|
||||
const op=(/产地|Origin/i.test(want) ? ops.find(o=>/中国|China/i.test(clean(o))) : null)
|
||||
|| ops.find(o=>!/^(无|none|NONE)/.test(clean(o))) || ops[0];
|
||||
const r=op.getBoundingClientRect();
|
||||
for(const ev of ['mousedown','mouseup','click']) op.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window,clientX:r.x+r.width/2,clientY:r.y+r.height/2}));
|
||||
return 'picked:'+(op.innerText||'').trim().slice(0,18);})()`);
|
||||
|
||||
Reference in new issue
Block a user