import type { CosScene } from "../../api/cos"; import type { FileNameStrategy, PntCosUploadOptions } from "../PntCosUploader"; import React, { FC } from 'react'; import './index.scss'; /** * PntUpload 文案集合 * @description 所有内部展示文案均可通过 texts prop 自定义,用于多语言场景 */ export interface PntUploadTexts { /** 上传中文案 */ uploading?: string; /** 上传失败文案 */ uploadFailed?: string; /** 文件大小超出限制文案 */ sizeInvalid?: string; /** 文件类型不支持文案 */ typeInvalid?: string; /** 选择文件文案(无文件时) */ selectFile?: string; /** 重新选择文案(已有文件时,非图片模式) */ reselect?: string; } /** * 校验/上传失败阶段 */ export type PntUploadErrorPhase = 'validate' | 'upload'; export interface PntUploadProps { /** * 当前已上传文件 URL(受控) */ value?: string; /** * 上传成功回调 * @param fileUrl 上传后的可访问 URL * @param cosKey COS 对象 Key * @param file 原始文件 */ onChange?: (fileUrl: string, cosKey: string, file: File) => void; /** * 删除回调 * @description 由消费方清空 value */ onRemove?: () => void; /** * 异常回调(校验失败 / 上传失败) * @param err 错误对象(校验失败时 message 为对应文案) * @param phase 失败阶段:validate=本地校验,upload=凭证获取或 COS 上传 * @param file 原始文件 */ onError?: (err: Error, phase: PntUploadErrorPhase, file: File) => void; /** * 业务场景(透传给 PntCosUploader) */ scene: CosScene; /** * 业务类型路径 key(透传给 PntCosUploader) */ pathKey?: string; /** * 业务上下文(透传给 PntCosUploader) */ context?: Record; /** * 网关 audience(透传给 PntCosUploader) * @default '/player-network' */ audience?: string; /** * 文件类型限制 * @description 支持 MIME('image/png')、通配('image/*')、扩展名('.zip'),可传数组 */ accept?: string | string[]; /** * 文件大小限制(字节) */ sizeLimit?: number; /** * 是否为图片预览模式 * @description true 使用 PntImage 预览;false 使用文件名 + 选择区域 * @default true */ imagePreview?: boolean; /** * 图片预览区样式(imagePreview=true 生效,一般控制宽高) */ previewStyle?: React.CSSProperties; /** * 默认占位图(imagePreview=true 生效) */ defaultImg?: string; /** * 文件名生成策略(透传给 PntCosUploader) * @default 'uuid' */ fileNameStrategy?: FileNameStrategy; /** * 是否走 CDN 域名拼接(透传给 PntCosUploader) * @default true */ useCdn?: boolean; /** * 自定义凭证获取函数(透传给 PntCosUploader) */ getCredential?: PntCosUploadOptions['getCredential']; /** * 自定义凭证响应归一化(透传给 PntCosUploader) */ normalizeCredential?: PntCosUploadOptions['normalizeCredential']; /** * 多语言文案 * @description 传入即覆盖默认中文文案;仅对应字段会覆盖,未传字段仍用默认值 */ texts?: PntUploadTexts; /** * 禁用上传与删除 * @default false */ disabled?: boolean; /** * 自定义样式 */ style?: React.CSSProperties; /** * 自定义类名 */ className?: string; } /** * PntUpload 业务上传组件 * @description 基于 TDesign Upload + PntImage + usePntCosUploader, * 内置 COS 凭证获取、直传、进度、校验、错误处理;支持图片预览 / 文件两种模式 * * @example * ```tsx * setIconUrl(url)} * onRemove={() => setIconUrl('')} * /> * ``` */ declare const PntUpload: FC; export default PntUpload;