Joom 47 条进待发布:jmbatch 跑通(店铺复选框组/可搜索类目/smtChoice* store),新增 3 条坑(无星号必填、虚拟滚动下拉、哨兵串定位 store)与 4 平台侦察表
This commit is contained in:
1 parent
c69952bd59
commit
c275571317
17 files changed
+1156
-4
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { newPage, closePage, wait, installHook, readHook } from '/home/admin9webs/shein建品/sh_lib.mjs';
|
||||
import { fillRequiredSelects } from '/home/admin9webs/shein建品/sh_build.mjs';
|
||||
import { SAN as S } from '/tmp/cdp3.mjs';
|
||||
import { readFileSync } from 'fs';
|
||||
const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`;
|
||||
const pid = process.argv[2] || '676236596821';
|
||||
const it = JSON.parse(readFileSync('/home/admin9webs/tiktok建品/tk_input.json','utf8'))[pid];
|
||||
const IMGS = (it.imgs||[]).slice(0,6);
|
||||
|
||||
const c = await newPage('https://www.dianxiaomi.com/web/joomProduct/add');
|
||||
await wait(12000);
|
||||
await installHook(c);
|
||||
// 店
|
||||
console.log('店:', String(await c.evalJS(`(()=>{const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>/店铺名称/.test((e.querySelector('label')||{}).innerText||''));
|
||||
const w=[...it.querySelectorAll('.ant-checkbox-wrapper')].find(x=>{const t=(x.innerText||'').trim(); return t&&!/^全部/.test(t);});
|
||||
for(const ev of ['mousedown','mouseup','click']) w.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
|
||||
const i=w.querySelector('input'); if(i&&!i.checked) i.click(); return (w.innerText||'').trim();})()`)));
|
||||
await wait(6000);
|
||||
// 类目
|
||||
const pos = JSON.parse(String(await c.evalJS(`(()=>{const f=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>/产品分类/.test((e.querySelector('label')||{}).innerText||''));
|
||||
const s=f.querySelector('.ant-select-selector'); s.scrollIntoView({block:'center'}); const r=s.getBoundingClientRect();
|
||||
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
|
||||
await c.send('Input.dispatchMouseEvent',{type:'mouseMoved',x:pos[0],y:pos[1],buttons:0}); await wait(250);
|
||||
for(const t of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type:t,x:pos[0],y:pos[1],button:'left',clickCount:1,buttons:1});
|
||||
await wait(1500);
|
||||
await c.send('Input.insertText',{text: it.cat_kw || '发夹'}).catch(()=>{});
|
||||
await wait(2500);
|
||||
console.log('类目:', String(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')][0]; if(!op) return 'no-op';
|
||||
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 (op.innerText||'').trim().slice(0,30);})()`)));
|
||||
await wait(7000);
|
||||
// store 填
|
||||
const fill = await c.evalJS(`(()=>{const p=${P}; const imgs=${JSON.stringify(IMGS)};
|
||||
const mk=(u,i)=>({url:u,imgUrl:u,name:'img'+(i+1)+'.jpg',width:800,height:800});
|
||||
const b=p._s.get('smtChoiceAddBasicStore').$state.formState;
|
||||
b.name=${JSON.stringify(it.title)}; b.parentSku='JM-'+${JSON.stringify(pid)}; b.description=(${JSON.stringify((it.bullets||[]).join('. '))}||b.name); b.tags=(${JSON.stringify(it.keywords||'')}.split(', ').slice(0,10));
|
||||
const pr=p._s.get('joomAddPriceStore').$state.formState;
|
||||
pr.price=String(${JSON.stringify(String(it.price_cny||'19.90'))}); pr.inventory='999'; pr.msrp=''; pr.shipping='0'; pr.declaredValue=String(${JSON.stringify(String(it.cost||'10'))});
|
||||
const im=p._s.get('joomAddImageStore').$state.formState;
|
||||
im.imageList=imgs.map(mk);
|
||||
if(Array.isArray(im.detailImageList)&&im.detailImageList[0]) im.detailImageList[0].images=imgs.map(mk);
|
||||
return JSON.stringify({name:b.name.slice(0,20), price:pr.price, imgs:im.imageList.length, cat:b.categoryId});})()`);
|
||||
console.log('填充:', S(String(fill)).slice(0,400));
|
||||
await wait(4000);
|
||||
const attrs = await fillRequiredSelects(c);
|
||||
console.log('必填属性:', S(String(attrs)).slice(0,300));
|
||||
await wait(2000);
|
||||
// dump(简化版,避免页面里复杂表达式报错)
|
||||
const d = await c.evalJS(`(()=>{ try {
|
||||
const p = document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
|
||||
const im = p._s.get('joomAddImageStore').$state;
|
||||
const labels = [];
|
||||
const all = document.querySelectorAll('.ant-form-item');
|
||||
for (const e of all) {
|
||||
if (e.offsetParent === null) continue;
|
||||
const l = e.querySelector('label');
|
||||
const t = l ? (l.innerText || '') : '';
|
||||
if (t.indexOf('图') >= 0 || t.indexOf('语言') >= 0) {
|
||||
labels.push(t.replace(/\\s+/g, ' ').trim().slice(0, 30) + ' | selects=' + e.querySelectorAll('.ant-select').length + ' imgs=' + e.querySelectorAll('img').length);
|
||||
}
|
||||
}
|
||||
return JSON.stringify({ keys: Object.keys(im), imageList: JSON.stringify(im.imageList).slice(0, 160),
|
||||
detail: JSON.stringify(im.detailImageList).slice(0, 260), labels: labels.slice(0, 12) });
|
||||
} catch (err) { return 'INNER-ERR ' + err.message; } })()`);
|
||||
console.log('图片区:', S(String(d)).slice(0, 1400));
|
||||
try { await c.shot('/tmp/joom_img.jpg'); console.log('shot ok'); } catch (e) {}
|
||||
await closePage(c); process.exit(0);
|
||||
Reference in new issue
Block a user