aliChoice:SKU分类是原生 select(新增 fillNativeSelects,失败 6/10→8/10);文本必填改为按字段名给值,修正颜色被填成材质词
This commit is contained in:
1 parent
14214862e6
commit
ad9b955d95
2 files changed
+46
-5
No files matched your search
+29
-1
@@ -279,6 +279,7 @@ export async function fillRequiredSelects(c, skip = ['店铺账号', '产品分
|
||||
/** 兜底填「必填但空着」的**文本输入**型类目属性(aliChoice 的「材质(Material)」就是 input,不是 select)。
|
||||
* values:候选值,按顺序给每个空文本项发一个(不够就重复最后一个)。 */
|
||||
export async function fillRequiredTextInputs(c, values = ['Other'], skip = ['店铺账号', '产品分类', '主规格', '产品标题', '店小秘分类', '尺码表', 'ParentSKU']) {
|
||||
// values 可以是数组(按顺序发),也可以是 (字段名)=>值的函数(推荐:不同字段给对的值)
|
||||
const filled = [];
|
||||
for (let round = 0; round < 6; round++) {
|
||||
const tgt = JSON.parse(String(await c.evalJS(`(()=>{
|
||||
@@ -299,7 +300,9 @@ export async function fillRequiredTextInputs(c, values = ['Other'], skip = ['店
|
||||
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 v = (typeof values === 'function')
|
||||
? String(values(tgt.name) || 'Other')
|
||||
: (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;
|
||||
@@ -326,3 +329,28 @@ export async function fillRequiredTextInputs(c, values = ['Other'], skip = ['店
|
||||
}
|
||||
return filled.join(' | ') || 'none';
|
||||
}
|
||||
|
||||
/** 兜底填**原生 <select>**(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';})()`);
|
||||
}
|
||||
Reference in new issue
Block a user