This commit is contained in:
sjl
2026-01-06 08:35:36 +08:00
parent fd09e24cf0
commit cb19fef4c6
88 changed files with 117 additions and 135 deletions

View File

@@ -1,8 +1,13 @@
import { downloadFile } from '@/api/system-boot/file'
const sanitizeUrl = (url: string): string => {
return url.replace(/\[/g, '(').replace(/\]/g, ')')
}
// 下载文件
export const download = (urls: string) => {
//console.log('下载', urls)
downloadFile({ filePath: urls })
.then((res: any) => {
// 1. 确定文件MIME类型优化用更简洁的方式
@@ -55,10 +60,8 @@ function removeLastDotSuffix(str: string) {
export const previewFile = async (urls: any) => {
//console.log('预览', urls)
let url = ''
//console.log('urls', decodeURI(urls))
await downloadFile({ filePath: decodeURI(urls) })
.then((res: any) => {
.then((res: any) => {
// 1. 确定文件MIME类型优化用更简洁的方式
const getFileType = (url: string) => {
const ext = url.split('.').pop()?.toLowerCase() || ''
@@ -74,11 +77,8 @@ export const previewFile = async (urls: any) => {
jpg: 'image/jpg'
}
return mimeMap[ext] || ''
}
}
const blob = new Blob([res], { type: getFileType(decodeURI(urls)) })
// 3. 创建下载链接
url = window.URL.createObjectURL(blob)
})