You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
795 B

1 month ago
/** 后台封面、轮播图、预约二维码图等:单张图片大小上限(与 UI 文案一致) */
export const ADMIN_UPLOAD_IMAGE_MAX_BYTES = 1024 * 1024
/** 与上传校验配套,跟在「尺寸推荐」后 */
export const ADMIN_IMAGE_RECOMMEND_LABEL =
'图片尺寸推荐 1200×600图片大小不超过 1MB'
/** @returns 可提示用户的中文错误文案;未超限或非图片返回 null */
export function adminUploadImageTooLargeMessage(file: File): string | null {
if (!file.type.startsWith('image/')) return null
if (file.size <= ADMIN_UPLOAD_IMAGE_MAX_BYTES) return null
const mb = file.size / (1024 * 1024)
const cur =
mb >= 1 ? `${mb.toFixed(2)}MB` : `${Math.ceil(file.size / 1024)}KB`
return `单张图片不能超过 1MB当前约 ${cur}`
}