|
@@ -66,6 +66,7 @@ export default {
|
|
|
},
|
|
|
openType: '', // 类型
|
|
|
target: '', // 外链地址
|
|
|
+ filename: '', // 指定文件名
|
|
|
openInBrowserTip: false
|
|
|
}
|
|
|
},
|
|
@@ -81,9 +82,12 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
getParams() {
|
|
|
- const { type, target = '' } = this.$route.query
|
|
|
+ const { type, filename, target = '' } = this.$route.query
|
|
|
this.openType = type
|
|
|
this.target = decodeURIComponent(target)
|
|
|
+ if (filename) {
|
|
|
+ this.filename = filename
|
|
|
+ }
|
|
|
},
|
|
|
setHeaderTitle() {
|
|
|
const { title } = this.$route.query
|
|
@@ -100,13 +104,28 @@ export default {
|
|
|
const { actionEvent } = this.openConf
|
|
|
actionEvent && actionEvent()
|
|
|
},
|
|
|
+ _downloadFile(url, filename) {
|
|
|
+ if (!url) return
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.style.display = 'none'
|
|
|
+ link.href = url
|
|
|
+ // 同源download才会生效
|
|
|
+ if (filename) {
|
|
|
+ link.setAttribute('download', filename)
|
|
|
+ }
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link)
|
|
|
+ return link
|
|
|
+ },
|
|
|
attachmentAction() {
|
|
|
const { inWx } = this.$envs
|
|
|
if (inWx) {
|
|
|
this.openInBrowserTip = true
|
|
|
} else {
|
|
|
if (this.target) {
|
|
|
- location.href = this.target
|
|
|
+ // location.href = this.target
|
|
|
+ this._downloadFile(this.target, this.filename)
|
|
|
}
|
|
|
}
|
|
|
}
|