提交
This commit is contained in:
1 parent
dacfdc9ff6
commit
f9676f8759
906 files changed
+533306
-12946
No files matched your search
@@ -95,6 +95,46 @@ export function fillAttachmentInfoCache(
|
||||
})
|
||||
}
|
||||
|
||||
export type ContractAttachmentItem = {
|
||||
uid: string
|
||||
name: string
|
||||
ossId?: string
|
||||
url?: string
|
||||
localPreview?: string
|
||||
status: 'uploading' | 'success' | 'error'
|
||||
category: 'single_seal' | 'double_seal' | 'other'
|
||||
}
|
||||
|
||||
/** 合同附件列表 → 保存 API 用的 JSON 字符串 */
|
||||
export function serializeContractAttachments(items: ContractAttachmentItem[]): string {
|
||||
const payload = items
|
||||
.filter((file) => file.status === 'success' && file.ossId)
|
||||
.map((file) => ({
|
||||
ossId: String(file.ossId),
|
||||
category: file.category || 'other'
|
||||
}))
|
||||
return payload.length ? JSON.stringify(payload) : ''
|
||||
}
|
||||
|
||||
/** 合同附件列表 → uploadAttachments 接口 payload */
|
||||
export function mapContractAttachmentsPayload(items: ContractAttachmentItem[]) {
|
||||
return items
|
||||
.filter((file) => file.status === 'success' && file.ossId)
|
||||
.map((file) => ({
|
||||
ossId: String(file.ossId),
|
||||
category: file.category || 'other'
|
||||
}))
|
||||
}
|
||||
|
||||
/** MinIO 相对路径 → 浏览器可访问 URL */
|
||||
export function resolveCrmAttachmentUrl(fileUrl: string): string {
|
||||
const trimmed = String(fileUrl || '').trim()
|
||||
if (!trimmed) return ''
|
||||
if (/^https?:\/\//i.test(trimmed)) return trimmed
|
||||
const base = String(import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
||||
return base ? `${base}/${trimmed.replace(/^\//, '')}` : trimmed
|
||||
}
|
||||
|
||||
export function isCrmImageFile(file: { name?: string; url?: string; ossId?: string }): boolean {
|
||||
const name = file.name || ''
|
||||
if (/\.(jpg|jpeg|png|gif|bmp|webp)$/i.test(name)) return true
|
||||
@@ -102,11 +142,29 @@ export function isCrmImageFile(file: { name?: string; url?: string; ossId?: stri
|
||||
return /\.(jpg|jpeg|png|gif|bmp|webp)(\?|$)/i.test(src)
|
||||
}
|
||||
|
||||
export function isCrmPdfFile(file: { name?: string; url?: string; ossId?: string }): boolean {
|
||||
const name = file.name || ''
|
||||
if (/\.pdf$/i.test(name)) return true
|
||||
const src = file.url || file.ossId || ''
|
||||
return /\.pdf(\?|$)/i.test(src)
|
||||
}
|
||||
|
||||
export function getCrmFileExt(fileName: string): string {
|
||||
const ext = fileName.split('.').pop()?.toUpperCase()
|
||||
return ext || 'FILE'
|
||||
}
|
||||
|
||||
const CRM_ATTACHMENT_CATEGORY_LABELS: Record<string, string> = {
|
||||
single_seal: '单章附件',
|
||||
double_seal: '双章附件',
|
||||
other: '其他附件'
|
||||
}
|
||||
|
||||
/** 附件分类 → 展示文案 */
|
||||
export function getCrmAttachmentCategoryLabel(category?: string): string {
|
||||
return CRM_ATTACHMENT_CATEGORY_LABELS[category || 'other'] || CRM_ATTACHMENT_CATEGORY_LABELS.other
|
||||
}
|
||||
|
||||
/** 下载 CRM 附件(fileUrl / ossId 均为 MinIO 路径或完整 URL) */
|
||||
export async function downloadCrmAttachment(file: {
|
||||
ossId?: string
|
||||
|
||||
Reference in new issue
Block a user