Files
2026-09-15 23:04:38 +08:00

50 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 穿搭状态语义的单一事实来源。
//
// 后端 OutfitCreateResponse.status:1=正常 2=封禁 3=待用户保存(AI 推荐生成后未保存),
// 列表、详情、创建响应都会带出。这里把「状态 → 胶囊文案与样式」的判定收敛到一处,
// 避免同一语义在穿搭页、AI 穿搭页、穿搭详情页各写一遍 if-else 而逐渐分叉。
//
// 零彩色纪律下的映射:需要用户操作/强调 = 实心黑胶囊;中性 = 描边胶囊;失效 = 无底色灰字。
import { OutfitSource, IsPublic } from './config'
export const OUTFIT_STATUS = {
NORMAL: 1,
BANNED: 2,
PENDING: 3,
} as const
export interface OutfitStatusLike {
status?: number
source?: number
is_public?: number
}
export interface OutfitStatusPill {
text: string
cls: string
}
// 待保存:AI 已生成但用户尚未保存;status 缺失按正常处理,兼容无该字段的老响应
export function isPendingSave(o: OutfitStatusLike): boolean {
return Number(o.status) === OUTFIT_STATUS.PENDING
}
// 封禁:展示降级且禁止一切管理操作
export function isBanned(o: OutfitStatusLike): boolean {
return Number(o.status) === OUTFIT_STATUS.BANNED
}
// 状态胶囊:待保存 > 封禁 > AI 来源 > 公开态
export function outfitStatusPill(o: OutfitStatusLike): OutfitStatusPill {
if (isPendingSave(o)) return { text: '待保存', cls: 'pill--ink' }
if (isBanned(o)) return { text: '已封禁', cls: 'pill--plain' }
if (Number(o.source) === OutfitSource.AI) return { text: 'AI 推荐', cls: 'pill--ink' }
if (Number(o.is_public) === IsPublic.PUBLIC) return { text: '已公开', cls: 'pill--line' }
return { text: '仅自己可见', cls: '' }
}
// 待保存态可保存;已正常则保存幂等;封禁态不可保存
export function canSaveOutfit(o: OutfitStatusLike): boolean {
return isPendingSave(o)
}