gongxiangp2/lib/work-review-image-types.ts

33 lines
1.5 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.

import {
WORK_REVIEW_IMAGE_LABELS,
WORK_REVIEW_IMAGE_TYPES,
type WorkReviewImageType,
} from '@/types/work-review'
export function isWorkReviewImageType(value: unknown): value is WorkReviewImageType {
return WORK_REVIEW_IMAGE_TYPES.includes(value as WorkReviewImageType)
}
export function getWorkReviewImageSelectionError(
counts: Record<WorkReviewImageType, number>,
referenceCounts: Record<WorkReviewImageType, number>,
) {
const suiteTypes = ['main', 'detail', 'sku'] as const
if (suiteTypes.some((type) => counts[type] > 0) && suiteTypes.some((type) => counts[type] === 0)) {
const missing = suiteTypes.filter((type) => counts[type] === 0).map((type) => WORK_REVIEW_IMAGE_LABELS[type])
return `主图、详情、SKU 必须三项一起上传,还缺少:${missing.join('、')}`
}
if (WORK_REVIEW_IMAGE_TYPES.every((type) => counts[type] === 0)) {
return '请上传定调图片,或同时上传主图、详情、SKU 三项图片'
}
const orphanReference = WORK_REVIEW_IMAGE_TYPES.find((type) => referenceCounts[type] > 0 && counts[type] === 0)
if (orphanReference) return `上传${WORK_REVIEW_IMAGE_LABELS[orphanReference]}参考图前,请先添加对应作品图片,或移除该参考图`
if (Object.values(counts).reduce((sum, count) => sum + count, 0) > 60) {
return '作品图片合计最多上传 60 张,请移除多余图片'
}
if (Object.values(referenceCounts).reduce((sum, count) => sum + count, 0) > 60) {
return '参考图片合计最多上传 60 张,请移除多余图片'
}
return null
}