From ad9b955d955d74ae612c9bd908fcfc142c11dfe8 Mon Sep 17 00:00:00 2001 From: admin9webs Date: Sun, 20 Sep 2026 23:09:39 +0800 Subject: [PATCH] =?UTF-8?q?aliChoice=EF=BC=9ASKU=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=98=AF=E5=8E=9F=E7=94=9F=20select=EF=BC=88=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20fillNativeSelects=EF=BC=8C=E5=A4=B1=E8=B4=A5=206/10=E2=86=92?= =?UTF-8?q?8/10=EF=BC=89=EF=BC=9B=E6=96=87=E6=9C=AC=E5=BF=85=E5=A1=AB?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=8C=89=E5=AD=97=E6=AE=B5=E5=90=8D=E7=BB=99?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E4=BF=AE=E6=AD=A3=E9=A2=9C=E8=89=B2=E8=A2=AB?= =?UTF-8?q?=E5=A1=AB=E6=88=90=E6=9D=90=E8=B4=A8=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alichoice建品/alcbatch.mjs | 21 +++++++++++++++++---- shein建品/sh_build.mjs | 30 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/alichoice建品/alcbatch.mjs b/alichoice建品/alcbatch.mjs index 31c99ab..1e7587b 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, fillRequiredTextInputs } from '/home/admin9webs/shein建品/sh_build.mjs'; +import { selectCategory, fillRequiredSelects, fillRequiredTextInputs, fillNativeSelects } from '/home/admin9webs/shein建品/sh_build.mjs'; const DIR = '/home/admin9webs/alichoice建品'; const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`; @@ -140,11 +140,24 @@ for (const t of tasks) { 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); + const t = String(it.title || ''); + const matHit = t.match(/plastic|cotton|polyester|stainless steel|metal|silicone|wood|resin|aluminum|alloy|fabric|nylon|glass|ceramic|leather/i); + const colorHit = t.match(/black|white|pink|red|blue|green|beige|grey|gray|purple|yellow|brown|khaki|ivory|apricot|silver|gold|multicolou?r/i); + // 按字段名给值:颜色别串成材质(曾把「颜色」填成 Resin) + const valueFor = (name) => { + if (/颜色|Color/i.test(name)) return colorHit ? colorHit[0] : 'Multicolor'; + if (/材质|Material/i.test(name)) return matHit ? matHit[0] : 'Polyester'; + if (/图案|Pattern/i.test(name)) return 'Solid'; + if (/尺寸|Size/i.test(name)) return 'Medium'; + return 'Other'; + }; + const txtAttrs = await fillRequiredTextInputs(c, valueFor); if (txtAttrs !== 'none') log(` 文本必填: ${String(txtAttrs).slice(0, 120)}`); await wait(1200); + // 原生 **(aliChoice 的「SKU分类」= 单品单件/同款多件/混合套装, + * 以及「件/个 / 双」这类单位选择)。antd 选择器一个都匹配不到,只能按原生元素处理。 */ +export async function fillNativeSelects(c, preferred = ['单品单件', '件/个']) { + return c.evalJS(`(()=>{const pref=${JSON.stringify(preferred)}; + const done=[]; + for (const sel of document.querySelectorAll('select')) { + if (sel.offsetParent === null) continue; + if (sel.multiple) continue; + const cur = sel.options[sel.selectedIndex]; + const empty = !sel.value || (cur && cur.disabled) || sel.selectedIndex <= 0; + if (!empty) continue; + const opts = [...sel.options].filter(o => !o.disabled && o.value !== ''); + if (!opts.length) continue; + let pick = null; + for (const p of pref) { pick = opts.find(o => (o.textContent || '').includes(p)); if (pick) break; } + if (!pick) pick = opts[0]; + sel.value = pick.value; + sel.dispatchEvent(new Event('input', { bubbles: true })); + sel.dispatchEvent(new Event('change', { bubbles: true })); + const label = (sel.closest('.ant-form-item') || {}).innerText || ''; + done.push((label.replace(/\\s+/g, ' ').trim().slice(0, 12) || 'select') + '=' + (pick.textContent || '').trim().slice(0, 12)); + } + return done.join(' | ') || 'none';})()`); +}