reconciliationRuleTabIndex.js
935 Bytes
/**
* “全部品类”没有服务端规则行、但页面保留了草稿快照时,该 Tab 使用独立的 phantom 槽位。
* rules 为空时仍需保留此语义,否则删除最后一个特殊品类后会把全部品类草稿判成空槽位。
*/
export function hasPhantomFullCategoryRuleSlot(rules, phantomRule) {
const list = Array.isArray(rules) ? rules : [];
if (list[0]?.groupType == 1) {
return false;
}
if (list[0]?.groupType == 2) {
return true;
}
return !!(phantomRule && typeof phantomRule === "object");
}
/**
* 页面 Tab 下标转服务端规则数组下标。
* phantom 占用 Tab 0,但不占 rules 数组位置,因此特殊品类需向前偏移一位。
*/
export function getReconciliationRuleIndexForTab(
rules,
tabIndex,
phantomRule,
) {
if (!hasPhantomFullCategoryRuleSlot(rules, phantomRule)) {
return tabIndex;
}
if (tabIndex <= 0) {
return null;
}
return tabIndex - 1;
}