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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/** 后台封面、轮播图、预约二维码图等:单张图片大小上限(与 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 } ) `
}