feat(admin): expandable family members with per-link tag config + SKU pricing dims columns
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
cleanLinkName,
|
||||
deriveLinkTagNames,
|
||||
linkDims,
|
||||
parseLinkName,
|
||||
sameOriginGroup,
|
||||
truncateToProcess,
|
||||
@@ -106,3 +107,23 @@ describe('deriveLinkTagNames', () => {
|
||||
expect(deriveLinkTagNames(null)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('linkDims', () => {
|
||||
it('解析物流备注/工艺/印花数量', () => {
|
||||
expect(linkDims('美国(包邮)180g纯棉T恤成人款-DG001-单面印花')).toEqual({
|
||||
logistics: '包邮',
|
||||
crafts: ['烫画'],
|
||||
printCount: '单面印花',
|
||||
});
|
||||
expect(linkDims('美国(不包邮光板)180GT恤成人款-JSA002-不打印·美西洛杉矶二仓')).toEqual({
|
||||
logistics: '不包邮光板',
|
||||
crafts: ['不打印', '光板'],
|
||||
printCount: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('无括号结构时物流为 null,手工名称工艺默认烫画', () => {
|
||||
expect(linkDims('纯棉T恤')).toEqual({ logistics: null, crafts: ['烫画'], printCount: null });
|
||||
expect(linkDims(null)).toEqual({ logistics: null, crafts: [], printCount: null });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,6 +52,35 @@ export function cleanLinkName(name: string | null | undefined): string {
|
||||
|
||||
const CRAFT_KEYWORDS = ['直喷', '不打印', '光板'] as const;
|
||||
|
||||
/** 链接的定价维度(SKU 表展示用):物流备注 / 工艺 / 印花数量 */
|
||||
export interface LinkDims {
|
||||
logistics: string | null;
|
||||
crafts: string[];
|
||||
printCount: string | null;
|
||||
}
|
||||
|
||||
/** 从链接名称解析定价维度;工艺无命中时默认烫画(与派生标签规则一致) */
|
||||
export function linkDims(name: string | null | undefined): LinkDims {
|
||||
if (!name) return { logistics: null, crafts: [], printCount: null };
|
||||
const head = name.split('-')[0] ?? '';
|
||||
const openCandidates = [head.indexOf('('), head.indexOf('(')].filter((i) => i >= 0);
|
||||
const openIdx = openCandidates.length ? Math.min(...openCandidates) : -1;
|
||||
const closeIdx = Math.max(head.lastIndexOf(')'), head.lastIndexOf(')'));
|
||||
const logistics =
|
||||
openIdx >= 0 && closeIdx > openIdx ? head.slice(openIdx + 1, closeIdx).trim() || null : null;
|
||||
const craftHits = CRAFT_KEYWORDS.filter((k) => name.includes(k));
|
||||
const printCount = name.includes('双面印花')
|
||||
? '双面印花'
|
||||
: name.includes('单面印花')
|
||||
? '单面印花'
|
||||
: null;
|
||||
return {
|
||||
logistics,
|
||||
crafts: craftHits.length > 0 ? craftHits : ['烫画'],
|
||||
printCount,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 由链接名称派生标签名(与 api 端 auto-tag-rules.ts 规则一致,仅用于成员行只读展示):
|
||||
* 印花数量:双面印花 优先于 单面印花;工艺:直喷/不打印/光板,皆无则默认烫画;
|
||||
|
||||
Reference in New Issue
Block a user