修改:文件服务器由nginx改为springboot
This commit is contained in:
parent
e031ee7c60
commit
f55e614902
@ -2626,11 +2626,13 @@ export default {
|
||||
if (window.location.port.length > 0) {
|
||||
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
|
||||
}
|
||||
let api = '/api/packageDownload'
|
||||
let api = '/api/file/packageDownload'
|
||||
if (fileIds.length === 1 && !this.rowContextData.isFolder) {
|
||||
api = '/api/download'
|
||||
api = '/api/file/download'
|
||||
}
|
||||
window.open(`${document.location.protocol}//${host}${api}?jmal-token=${this.$store.state.user.token}&fileIds=${fileIds}`, '_self')
|
||||
// this.downloadFile1("haha", `${document.location.protocol}//${host}${api}?fileIds=${fileIds}`, this.$store.state.user.token)
|
||||
// window.open(`${document.location.protocol}//${host}${api}?jmal-token=${this.$store.state.user.token}&fileIds=${fileIds}`, '_self')
|
||||
window.open(`${document.location.protocol}//${host}${api}/${fileIds}`, '_self')
|
||||
} else {
|
||||
this.$message({
|
||||
message: '所选文件为空',
|
||||
@ -2638,6 +2640,34 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
downloadFile1(filename, fileUrl, token) {
|
||||
const xhr = new XMLHttpRequest()
|
||||
const url = fileUrl
|
||||
xhr.open('get', url, true)
|
||||
xhr.setRequestHeader('Authorization', `Bearer ${token}`) // 给后端发送请求头
|
||||
xhr.setRequestHeader('Access-Control-Allow-Origin', `http://localhost:9528`)
|
||||
xhr.responseType = 'blob'
|
||||
xhr.onload = function(e) {
|
||||
if (this.status === 200) {
|
||||
const blob = this.response
|
||||
// URL对象是硬盘(SD卡等)指向文件的一个路径,
|
||||
//如果我们做文件上传的时候,想在没有上传服务器端的情况下看到上传图片的效果图
|
||||
//就可是以通过var url=window.URL.createObjectURL(obj.files[0]);获得一个http格式的url路径
|
||||
//这个时候就可以设置到<img>中显示了
|
||||
//window.webkitURL和window.URL是一样的,window.URL标准定义
|
||||
//window.webkitURL是webkit内核的实现(一般手机上就是使用这个),还有火狐等浏览器的实现。
|
||||
const urlObject = window.URL || window.webkitURL || window
|
||||
const export_blob = new Blob([blob])
|
||||
const a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a') // 利用a标签特性下载
|
||||
const url = urlObject.createObjectURL(export_blob)
|
||||
a.href = url
|
||||
a.download = filename
|
||||
a.click()
|
||||
}
|
||||
}
|
||||
// 发送请求
|
||||
xhr.send()
|
||||
},
|
||||
// 收藏/取消收藏
|
||||
favoriteOperating(isFavorite) {
|
||||
const fileIds = this.getSelectIdList()
|
||||
@ -2835,7 +2865,12 @@ export default {
|
||||
}
|
||||
if (row.suffix === 'pdf') {
|
||||
// pdf文件
|
||||
window.open(`${process.env.VUE_APP_BASE_FILE_API}/preview/${row.name}?jmal-token=${this.$store.state.user.token}&fileIds=${row.id}`, '_blank')
|
||||
let host = window.location.host
|
||||
if (window.location.port.length > 0) {
|
||||
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
|
||||
}
|
||||
window.open(`${document.location.protocol}//${host}/api/file/download/${row.id}`, '_self')
|
||||
// window.open(`${process.env.VUE_APP_BASE_FILE_API}/preview/${row.name}?jmal-token=${this.$store.state.user.token}&fileIds=${row.id}`, '_blank')
|
||||
return
|
||||
}
|
||||
if (suffix.compressedFile.includes(row.suffix)) {
|
||||
|
||||
@ -560,9 +560,9 @@
|
||||
if (window.location.port.length > 0) {
|
||||
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
|
||||
}
|
||||
let api = '/api/packageDownload'
|
||||
let api = '/api/file/packageDownload'
|
||||
if (fileIds.length === 1 && !this.rowContextData.isFolder) {
|
||||
api = '/api/download'
|
||||
api = '/api/file/download'
|
||||
}
|
||||
window.open(`${document.location.protocol}//${host}${api}?jmal-token=${this.$store.state.user.token}&fileIds=${fileIds}`, '_self')
|
||||
} else {
|
||||
|
||||
@ -871,9 +871,9 @@
|
||||
if (window.location.port.length > 0) {
|
||||
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
|
||||
}
|
||||
let api = '/api/packageDownload'
|
||||
let api = '/api/file/packageDownload'
|
||||
if (fileIds.length === 1 && !this.rowContextData.isFolder) {
|
||||
api = '/api/download'
|
||||
api = '/api/file/download'
|
||||
}
|
||||
window.open(`${document.location.protocol}//${host}${api}?jmal-token=${this.$store.state.user.token}&fileIds=${fileIds}`, '_self')
|
||||
} else {
|
||||
|
||||
@ -822,9 +822,9 @@
|
||||
if (window.location.port.length > 0) {
|
||||
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
|
||||
}
|
||||
let api = '/api/packageDownload'
|
||||
let api = '/api/file/packageDownload'
|
||||
if (fileIds.length === 1 && !this.rowContextData.isFolder) {
|
||||
api = '/api/download'
|
||||
api = '/api/file/download'
|
||||
}
|
||||
window.open(`${document.location.protocol}//${host}${api}?jmal-token=${this.$store.state.user.token}&fileIds=${fileIds}`, '_self')
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user