From 14214862e601c44a789aac6325088c537b50f68a Mon Sep 17 00:00:00 2001 From: admin9webs Date: Sun, 20 Sep 2026 22:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20aliChoice=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=A0=B9=E5=9B=A0=EF=BC=9A=E7=B1=BB=E7=9B=AE=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=B2=A1=E5=85=B3=EF=BC=88=E9=81=AE=E7=BD=A9=E6=8C=A1?= =?UTF-8?q?=E4=BD=8F=E6=89=80=E6=9C=89=E5=BF=85=E5=A1=AB=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=EF=BC=89+=20=E6=96=B0=E5=A2=9E=E6=96=87=E6=9C=AC=E5=9E=8B?= =?UTF-8?q?=E5=BF=85=E5=A1=AB=E5=85=9C=E5=BA=95=20fillRequiredTextInputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alichoice建品/alc_diag2.mjs | 79 +++++++++++++++++++++++++++++++++++++ alichoice建品/alcbatch.mjs | 8 +++- shein建品/sh_build.mjs | 63 +++++++++++++++++++++++++++-- 3 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 alichoice建品/alc_diag2.mjs diff --git a/alichoice建品/alc_diag2.mjs b/alichoice建品/alc_diag2.mjs new file mode 100644 index 0000000..e8da783 --- /dev/null +++ b/alichoice建品/alc_diag2.mjs @@ -0,0 +1,79 @@ +/** 诊断 aliChoice 剩下的两类必填:类目属性 材质/尺寸、SKU 行的 SKU分类 */ +import { newPage, closePage, wait, installHook, readHook } from '/home/admin9webs/shein建品/sh_lib.mjs'; +import { selectCategory, fillRequiredSelects } from '/home/admin9webs/shein建品/sh_build.mjs'; +import { SAN as S } from '/tmp/cdp3.mjs'; +import { readFileSync } from 'fs'; + +const DIR = '/home/admin9webs/alichoice建品'; +const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`; +const pid = process.argv[2] || '685456757807'; +const it = JSON.parse(readFileSync('/home/admin9webs/tiktok建品/tk_input.json', 'utf8'))[pid]; +const ROUTE = JSON.parse(readFileSync(`${DIR}/alc_route.json`, 'utf8')); +const IMGS = (it.imgs || []).slice(0, 6); + +const c = await newPage('https://www.dianxiaomi.com/web/smtChoice/add'); +await wait(12000); +await installHook(c); + +async function pickFirstOption(labelRe) { + const p = JSON.parse(String(await c.evalJS(`(()=>{const f=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null) + .find(e=>new RegExp(${JSON.stringify(labelRe)}).test((e.querySelector('label')||{}).innerText||'')); + const s=f?f.querySelector('.ant-select-selector'):null; if(!s) return '[]'; 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)]);})()`))); + if (!p.length) return 'no-sel'; + await c.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: p[0], y: p[1], buttons: 0 }); await wait(250); + for (const t of ['mousePressed', 'mouseReleased']) + await c.send('Input.dispatchMouseEvent', { type: t, x: p[0], y: p[1], button: 'left', clickCount: 1, buttons: 1 }); + await wait(1800); + return 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'; + 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,14);})()`); +} + +console.log('店:', await pickFirstOption('店铺名称')); await wait(5500); +console.log('备货:', await pickFirstOption('备货类型')); await wait(2500); +const cat = ROUTE[pid] && ROUTE[pid].cat ? ROUTE[pid].cat : (it.cat_kw || '发夹'); +console.log('类目词:', cat, '→', S(String(await selectCategory(c, cat, cat))).slice(0, 90)); +await wait(6000); + +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}); + p._s.get('smtChoiceAddBasicStore').$state.formState.subject=${JSON.stringify(it.title)}; + p._s.get('smtChoiceAddProductStore').$state.formState.mainImage=imgs.map(mk); + const sd=p._s.get('smtChoiceSkuDataStore').$state.formState; + (sd.skuDataList||[]).forEach(r=>{ r.skuPrice=String(${JSON.stringify(String(it.price_cny || '19.90'))}); r.skuCode='AC-'+${JSON.stringify(pid)}; + r.packageWeight='100'; r.packageLength='20'; r.packageWidth='15'; r.packageHeight='3'; }); + const d=p._s.get('smtChoiceAddStore').$state.describeInfoData; if(d) d.detail=${JSON.stringify((it.bullets || []).join('
'))}; + return 1;})()`); +await wait(3000); +console.log('必填属性:', S(String(await fillRequiredSelects(c))).slice(0, 200)); +await wait(1500); +await c.evalJS(`window.scrollTo(0,0)`); await wait(500); +await c.evalJS(`(()=>{const xs=[...document.querySelectorAll('button')].filter(e=>e.offsetParent!==null); + const b=xs.find(e=>/^\\s*保存\\s*$/.test((e.innerText||'').trim()))||xs.find(e=>/保存/.test(e.innerText||'')); + if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 1;})()`); +await wait(12000); + +const d = await c.evalJS(`(()=>{ + const out={}; + const probe=(name)=>{const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null) + .filter(e=>{const l=e.querySelector('label'); return l&&new RegExp(name).test(l.innerText||'');}); + if(!items.length) return 'no-item'; + const it=items[items.length-1]; + return {label:(it.querySelector('label')||{}).innerText, + kinds:[...it.querySelectorAll('input,textarea,.ant-select,.ant-checkbox-group,.ant-radio-group,.ant-cascader')].map(x=>x.tagName+'.'+String(x.className).slice(0,24)).slice(0,6), + html:it.outerHTML.replace(/\\s+/g,' ').slice(0,380)};}; + out['材质']=probe('材质'); out['尺寸']=probe('尺寸'); + out.errs=[...document.querySelectorAll('.ant-form-item-has-error')].map(x=>({t:(x.innerText||'').replace(/\\s+/g,' ').trim().slice(0,46), + html:x.outerHTML.replace(/\\s+/g,' ').slice(0,260)})).slice(0,5); + out.headers=[...document.querySelectorAll('th')].map(t=>(t.innerText||'').replace(/\\s+/g,' ').trim()).filter(Boolean).slice(0,14); + const p=${P}; const row=(p._s.get('smtChoiceSkuDataStore').$state.formState.skuDataList||[])[0]||{}; + out.skuRowKeys=Object.keys(row); out.skuClass=row.skuClassification; + return JSON.stringify(out);})()`); +console.log('诊断:', JSON.stringify(JSON.parse(String(d)), null, 1).slice(0, 2600)); +console.log('hook:', String(await readHook(c)).slice(-160)); +try { await c.shot('/tmp/alc_diag2.jpg'); console.log('shot ok'); } catch (e) {} +await closePage(c); +process.exit(0); diff --git a/alichoice建品/alcbatch.mjs b/alichoice建品/alcbatch.mjs index 8a35271..31c99ab 100644 --- a/alichoice建品/alcbatch.mjs +++ b/alichoice建品/alcbatch.mjs @@ -9,7 +9,7 @@ */ import { readFileSync, writeFileSync, appendFileSync } from 'fs'; import { newPage, closePage, wait, installHook, readHook } from '/home/admin9webs/shein建品/sh_lib.mjs'; -import { selectCategory, fillRequiredSelects } from '/home/admin9webs/shein建品/sh_build.mjs'; +import { selectCategory, fillRequiredSelects, fillRequiredTextInputs } from '/home/admin9webs/shein建品/sh_build.mjs'; const DIR = '/home/admin9webs/alichoice建品'; const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`; @@ -139,6 +139,12 @@ for (const t of tasks) { const attrs = await fillRequiredSelects(c); if (attrs !== 'none') log(` 必填属性: ${String(attrs).slice(0, 150)}`); await wait(1200); + // 文本型必填(aliChoice 的「材质(Material)」是 input,不是 select):按标题里的材质词兜底 + const matHit = String(it.title || '').match(/plastic|cotton|polyester|stainless steel|metal|silicone|wood|resin|aluminum|alloy|fabric|nylon|glass|ceramic|leather/i); + const matVals = [...new Set([matHit ? matHit[0] : null, 'Polyester', 'Other'].filter(Boolean))]; + const txtAttrs = await fillRequiredTextInputs(c, matVals); + if (txtAttrs !== 'none') log(` 文本必填: ${String(txtAttrs).slice(0, 120)}`); + await wait(1200); log(` PC端描述: ${await fillDescription(c, (it.bullets || []).join('
') || it.title)}`); await wait(1500); if (dry) { delete done[t.pid]; log(' ✓ dry 构建完成(未保存)'); await closePage(c); continue; } diff --git a/shein建品/sh_build.mjs b/shein建品/sh_build.mjs index 6a40920..c7849a1 100644 --- a/shein建品/sh_build.mjs +++ b/shein建品/sh_build.mjs @@ -75,17 +75,21 @@ export async function selectCategory(c, kw, preferName) { await wait(2000); } await wait(1800); - // 3) 弹窗必须关掉,否则后面的点击全被挡(曾出现「类目已选但弹窗还开着 → 预览图挂不上」) + // 3) 弹窗必须关掉,否则后面的点击全被挡(SHEIN/Temu 上是「预览图挂不上」, + // aliChoice 上更狠:弹窗不关 → 所有必填属性都填不上 → 保存报一串牛头不对马嘴的错) let left = Number(await c.evalJS(`[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).length`)); - for (let k = 0; k < 3 && left; k++) { + for (let k = 0; k < 6 && left; k++) { await c.evalJS(`(()=>{const m=[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).pop(); if(!m) return 'closed'; - const b=[...m.querySelectorAll('button')].find(x=>/^\\s*(确定|选择)\\s*$/.test((x.innerText||'').trim())); + const bar=[...m.querySelectorAll('button')]; + const b=bar.find(x=>/^\\s*(确定|选择)\\s*$/.test((x.innerText||'').trim()))||bar.find(x=>/^\\s*(关闭|取消)\\s*$/.test((x.innerText||'').trim())); if(b) for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); const c2=[...m.querySelectorAll('.ant-modal-close')][0]; if(c2) c2.click(); return b?'ok':'still-open';})()`); await wait(1500); - if (k >= 1) await c.send('Input.dispatchKeyEvent', {type:'keyDown', key:'Escape', code:'Escape', windowsVirtualKeyCode:27}).catch(()=>{}); + await c.send('Input.dispatchKeyEvent', {type:'keyDown', key:'Escape', code:'Escape', windowsVirtualKeyCode:27}).catch(()=>{}); + await wait(600); + if (k >= 3) await c.evalJS(`(()=>{const w=[...document.querySelectorAll('.ant-modal-wrap')].filter(e=>e.offsetParent!==null).pop(); if(w) w.click(); return 1;})()`); left = Number(await c.evalJS(`[...document.querySelectorAll('.ant-modal')].filter(e=>e.offsetParent!==null).length`)); } await wait(3000); @@ -271,3 +275,54 @@ export async function fillRequiredSelects(c, skip = ['店铺账号', '产品分 } return [filled.join(' | '), ticked].filter(x=>x&&x!=='none').join(' | ') || 'none'; } + +/** 兜底填「必填但空着」的**文本输入**型类目属性(aliChoice 的「材质(Material)」就是 input,不是 select)。 + * values:候选值,按顺序给每个空文本项发一个(不够就重复最后一个)。 */ +export async function fillRequiredTextInputs(c, values = ['Other'], skip = ['店铺账号', '产品分类', '主规格', '产品标题', '店小秘分类', '尺码表', 'ParentSKU']) { + const filled = []; + for (let round = 0; round < 6; round++) { + const tgt = JSON.parse(String(await c.evalJS(`(()=>{ + const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>{ + if(e.offsetParent===null) 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.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; + if(e.querySelector('.ant-select,.ant-checkbox-group,.ant-radio-group,.ant-cascader')) return false; + const inp=e.querySelector('input.ant-input, textarea.ant-input'); + if(!inp || inp.offsetParent===null) return false; + if(String(inp.value||'').trim()) return false; + return true;}); + const it=items[0]; if(!it) return '[]'; + const l=it.querySelector('label'); + return JSON.stringify({name:(l.innerText||'').replace(/\\s+/g,' ').trim().slice(0,30)});})()`))); + if (!tgt.name) break; + const v = values[Math.min(filled.length, values.length - 1)] || 'Other'; + const ok = await c.evalJS(`(()=>{ + const items=[...document.querySelectorAll('.ant-form-item')].filter(e=>{ + if(e.offsetParent===null) 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.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; + if(e.querySelector('.ant-select,.ant-checkbox-group,.ant-radio-group,.ant-cascader')) return false; + const inp=e.querySelector('input.ant-input, textarea.ant-input'); + return inp && inp.offsetParent!==null && !String(inp.value||'').trim();}); + const it=items.find(e=>((e.querySelector('label')||{}).innerText||'').replace(/\\s+/g,' ').trim().slice(0,30)===${JSON.stringify(tgt.name)}); + if(!it) return 'gone'; + const inp=it.querySelector('input.ant-input, textarea.ant-input'); + const proto = inp.tagName==='TEXTAREA' ? window.HTMLTextAreaElement.prototype : window.HTMLInputElement.prototype; + Object.getOwnPropertyDescriptor(proto,'value').set.call(inp, ${JSON.stringify(v)}); + inp.dispatchEvent(new Event('input',{bubbles:true})); inp.dispatchEvent(new Event('change',{bubbles:true})); + inp.dispatchEvent(new Event('blur',{bubbles:true})); + return 'ok';})()`); + filled.push(tgt.name + '=' + v); + await wait(1200); + if (ok === 'gone') break; + } + return filled.join(' | ') || 'none'; +}