spring
2025-04-27 41c9b2fa8cef5f45c23d00d33680764b48dfc3cc
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export function transform(response) {
  const relType = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel;charset=UTF-8']
  let type = response.data.type
  if (relType.includes(type)) {
    const blob = new Blob([response.data], {type: 'application/vnd.ms-excel'})
    const disposition = response.headers["content-disposition"]
    let temp = disposition.substring(disposition.lastIndexOf('=') + 1)
    let filename = decodeURI(temp)
    // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
    const elink = document.createElement('a')
    elink.download = filename
    elink.style.display = 'none'
    elink.href = URL.createObjectURL(blob)
    document.body.appendChild(elink)
    elink.click()
    URL.revokeObjectURL(elink.href) // 释放URL 对象
    document.body.removeChild(elink)
  }
}
 
export function transformZip(response) {
  const relType = ['application/zip']
  let type = response.data.type
  if (relType.includes(type)) {
    const blob = new Blob([response.data], {type: 'application/zip'})
    const disposition = response.headers["content-disposition"]
    let temp = disposition.substring(disposition.lastIndexOf('=') + 1)
    let filename = decodeURI(temp)
    // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
    const elink = document.createElement('a')
    elink.download = filename
    elink.style.display = 'none'
    elink.href = URL.createObjectURL(blob)
    document.body.appendChild(elink)
    elink.click()
    URL.revokeObjectURL(elink.href) // 释放URL 对象
    document.body.removeChild(elink)
  }
}
 
export function transformDoc(response) {
    const relType = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
    let type = response.data.type
    if (relType.includes(type)) {
        const blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'})
        const disposition = response.headers["content-disposition"]
        let temp = disposition.substring(disposition.lastIndexOf('=') + 1)
        let filename = decodeURI(temp)
        // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
        const elink = document.createElement('a')
        elink.download = filename
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href) // 释放URL 对象
        document.body.removeChild(elink)
    }
}