You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
3 years ago
|
import { saveAs } from 'file-saver'
|
||
|
import axios from 'axios'
|
||
|
import { getToken } from '@/utils/auth'
|
||
|
|
||
|
const baseURL = process.env.VUE_APP_BASE_API
|
||
|
|
||
|
export default {
|
||
|
name(name, isDelete = true) {
|
||
|
var url = baseURL + "/common/download?fileName=" + encodeURI(name) + "&delete=" + isDelete
|
||
|
axios({
|
||
|
method: 'get',
|
||
|
url: url,
|
||
|
responseType: 'blob',
|
||
|
headers: { 'Authorization': 'Bearer ' + getToken() }
|
||
|
}).then(res => {
|
||
|
const blob = new Blob([res.data])
|
||
|
this.saveAs(blob, decodeURI(res.headers['download-filename']))
|
||
|
})
|
||
|
},
|
||
|
resource(resource) {
|
||
|
var url = baseURL + "/common/download/resource?resource=" + encodeURI(resource);
|
||
|
axios({
|
||
|
method: 'get',
|
||
|
url: url,
|
||
|
responseType: 'blob',
|
||
|
headers: { 'Authorization': 'Bearer ' + getToken() }
|
||
|
}).then(res => {
|
||
|
const blob = new Blob([res.data])
|
||
|
this.saveAs(blob, decodeURI(res.headers['download-filename']))
|
||
|
})
|
||
|
},
|
||
|
zip(url, name) {
|
||
|
var url = baseURL + url
|
||
|
axios({
|
||
|
method: 'get',
|
||
|
url: url,
|
||
|
responseType: 'blob',
|
||
|
headers: { 'Authorization': 'Bearer ' + getToken() }
|
||
|
}).then(res => {
|
||
|
const blob = new Blob([res.data], { type: 'application/zip' })
|
||
|
this.saveAs(blob, name)
|
||
|
})
|
||
|
},
|
||
|
saveAs(text, name, opts) {
|
||
|
saveAs(text, name, opts);
|
||
|
}
|
||
|
}
|
||
|
|