58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
export const CERTIFICATE_REPORT_MATERIAL_TYPE = '证书-检测报告'
|
|
|
|
export const CERTIFICATE_REPORT_ASSET_TYPE = {
|
|
PDF: 'report-pdf',
|
|
IMAGE: 'report-image',
|
|
} as const
|
|
|
|
export type CertificateReportAssetType =
|
|
(typeof CERTIFICATE_REPORT_ASSET_TYPE)[keyof typeof CERTIFICATE_REPORT_ASSET_TYPE]
|
|
|
|
export type CertificateReportFileKind = 'pdf' | 'image'
|
|
|
|
export function isCertificateReportMaterialType(materialType: string | null | undefined): boolean {
|
|
return String(materialType || '').trim() === CERTIFICATE_REPORT_MATERIAL_TYPE
|
|
}
|
|
|
|
export function normalizeReportTitle(value: string | null | undefined): string | null {
|
|
const normalized = typeof value === 'string' ? value.trim() : ''
|
|
return normalized || null
|
|
}
|
|
|
|
export function getCertificateReportDisplayTitle(input: {
|
|
productModel?: string | null
|
|
reportTitle?: string | null
|
|
}): string {
|
|
const productModel = String(input.productModel || '').trim()
|
|
if (productModel) {
|
|
return productModel
|
|
}
|
|
|
|
const reportTitle = String(input.reportTitle || '').trim()
|
|
if (reportTitle) {
|
|
return reportTitle
|
|
}
|
|
|
|
return '未命名报告'
|
|
}
|
|
|
|
export function getCertificateReportFileKindByAssetType(assetType: string | null | undefined): CertificateReportFileKind | null {
|
|
if (assetType === CERTIFICATE_REPORT_ASSET_TYPE.PDF) {
|
|
return 'pdf'
|
|
}
|
|
|
|
if (assetType === CERTIFICATE_REPORT_ASSET_TYPE.IMAGE) {
|
|
return 'image'
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export function detectFileKindFromName(fileName: string | null | undefined): CertificateReportFileKind {
|
|
const lowerName = String(fileName || '').trim().toLowerCase()
|
|
if (lowerName.endsWith('.pdf')) {
|
|
return 'pdf'
|
|
}
|
|
return 'image'
|
|
}
|