111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import axios from 'axios'
 
const loadFile = async function (path) {
    let text;
    await axios.get(path).then(res => {
        text = res;
    })
    return text
}
 
/**
 *  文件下载
 * @param downloadUrl   文件
 * @param fileName      文件名
 */
const fileDownload = function (downloadUrl,fileName) {
    let aLink = document.createElement("a");
    aLink.style.display = "none";
    aLink.href = downloadUrl;
    aLink.download = fileName;
    document.body.appendChild(aLink);
    aLink.click();
    document.body.removeChild(aLink);
}
 
const base64toFile = function (base64, fileName) {
    let arr = base64.split(","),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], fileName,{ type: mime });
}
export {fileDownload, base64toFile, loadFile}