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,64 @@
|
||||
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 dumpImgs = async (tag) => {
|
||||
const r = await c.evalJS(`(()=>{ try {
|
||||
const p = document.querySelector('#app').__vue_app__.config.globalProperties.$pinia;
|
||||
const st = p._s.get('joomAddImageStore').$state;
|
||||
const f = st.formState || {};
|
||||
return JSON.stringify({ keys: Object.keys(f), imageList: Array.isArray(f.imageList) ? f.imageList.length : 'undef',
|
||||
detail: Array.isArray(f.detailImageList) && f.detailImageList[0] && Array.isArray(f.detailImageList[0].images) ? f.detailImageList[0].images.length : 'undef',
|
||||
domImgs: document.querySelectorAll('img').length });
|
||||
} catch (e) { return 'ERR ' + e.message; } })()`);
|
||||
console.log(tag, S(String(r)).slice(0, 300));
|
||||
};
|
||||
await wait(800); await dumpImgs('填完立刻:');
|
||||
await wait(6000); await dumpImgs('6 秒后:');
|
||||
const attrs = await fillRequiredSelects(c);
|
||||
console.log('必填属性:', S(String(attrs)).slice(0, 200));
|
||||
await wait(2500); await dumpImgs('填必填属性后:');
|
||||
try { await c.shot('/tmp/joom_img2.jpg'); console.log('shot ok'); } catch (e) {}
|
||||
await closePage(c); process.exit(0);
|
||||
Reference in new issue
Block a user