export const formatName = (showName: string) => { if (showName) { showName = showName.replace('#', '~~').replace('?', '~$').replace('&', '$') } return showName } export const checkFileAccept = (file: File, acceptStr: string) => { if (!acceptStr || !file) return true const accepts = acceptStr.split(',').map((s) => s.trim()) const fileExt = '.' + (file.name.split('.').pop()?.toLowerCase() || '') const fileType = file.type return accepts.some((item) => { // 扩展名匹配:".jpg"、".pdf" if (item.startsWith('.')) { return fileExt === item.toLowerCase() } // MIME 通配符匹配:"image/*"、"video/*" if (item.endsWith('/*')) { const typePrefix = item.slice(0, -1) // 'image/', 'video/' return fileType.startsWith(typePrefix) } // 精确 MIME 匹配:"image/png"、"application/pdf" return fileType === item }) }