fix: 后台外壳容忍异常品牌成员数据
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
This commit is contained in:
1 parent
ec84988e57
commit
737010ea03
4 files changed
+107
-16
No files matched your search
@@ -0,0 +1,32 @@
|
||||
export interface BrandSwitcherOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 品牌切换器只接受形状完整的成员记录。
|
||||
* 接口返回异常条目时跳过该条,避免整个后台外壳渲染失败。
|
||||
*/
|
||||
export function toBrandSwitcherOptions(value: unknown): BrandSwitcherOption[] {
|
||||
if (!Array.isArray(value)) return [];
|
||||
const options: BrandSwitcherOption[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
for (const item of value) {
|
||||
const brand = (item as { brand?: { id?: unknown; name?: unknown } } | null | undefined)?.brand;
|
||||
if (!brand || typeof brand.id !== "string" || brand.id.length === 0) continue;
|
||||
if (seen.has(brand.id)) continue;
|
||||
seen.add(brand.id);
|
||||
options.push({
|
||||
value: brand.id,
|
||||
label: typeof brand.name === "string" && brand.name.length > 0 ? brand.name : brand.id,
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/** 品牌名称必须是字符串,异常数据回退到给定文案。 */
|
||||
export function toBrandDisplayName(value: unknown, fallback: string): string {
|
||||
return typeof value === "string" && value.trim().length > 0 ? value : fallback;
|
||||
}
|
||||
Reference in new issue
Block a user