先建一个download文件夹
第一个文件download.ts代码是
import { Request } from "@/api/axios/Request";
import {getFileType} from "@/api/download/getFileType"
export function downloadFile(url: string, params?: any, filename?: any) {
return new Promise((resolve, reject) => {
Request.download(url, params).then((res: any,) => {
const type:string =filename.split('.').pop().toLowerCase()
let fileType = getFileType(type);
if (fileType == null || fileType === '') {
resolve({res:null})
} else {
resolve({ res, fileType})
}
}).catch((err) => {
console.error("err")
reject(err)
})
});
}
第二个fileDataList存放的是文件的类型
let fileDateList = [
{ key: "doc", value: "application/msword" },
{ key: "pdf", value: "application/pdf" },
{ key: "xlsx", value: "application/vnd.ms-excel" },
{ key: "zip", value: "application/zip" },
{ key: "mime_7z", value: "application/x-7z-compressed" },
{ key: "rar", value: "application/x-tar" },
{ key: "json", value: "application/json" },
{ key: "txt", value: "text/plain" },
{ key: "html", value: "text/html" },
{key:"ra