添加附件名称

This commit is contained in:
a0049873 2022-11-24 20:51:16 +08:00
parent 8f899ecf3e
commit 7538cc94d0
1 changed files with 67 additions and 6 deletions

View File

@ -2,7 +2,7 @@
* @Author: hisense.liangjunhua
* @Date: 2022-06-29 15:59:51
* @LastEditors: Light
* @LastEditTime: 2022-11-24 17:22:23
* @LastEditTime: 2022-11-24 20:45:45
* @Description: 告诉大家这是什么
-->
<!-- 流程业务表单 -->
@ -35,10 +35,15 @@
需求依据<span>
{{ dataForm.content.applicationBackground || '--' }}</span></span>
</p>
<p>
<!-- <p>
<div>
<el-button type="primary" v-if="dataForm.content.attachment" size="small" @click="download(dataForm.content)">附件下载</el-button>
</div>
</p> -->
<p>
<div>
<el-button type="primary" size="small" @click="download(dataForm.content)">附件下载</el-button>
</div>
</p>
<!-- <p>
<span>
@ -526,10 +531,66 @@ export default {
//
taskHandleErrorCallback (data) { },
download (data) {
const alink = document.createElement('a')
alink.download = '附件' // ,,IE10
alink.href = data.attachment // url
alink.click() //
this.downloadFile(data.attachment, '附件')
// const alink = document.createElement('a')
// alink.download = '' // ,,IE10
// // alink.href = data.attachment // url
// alink.href = 'http://10.134.135.92:8888/renren-admin/upload/2022/11/24/c1c2802f-b6d9-4eff-81c8-02965da1ba34.doc' // url
// alink.click() //
},
/**
* 获取 blob
* url 目标文件地址
*/
getBlob (url) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response)
}
}
xhr.send()
})
},
/**
* 保存 blob
* filename 想要保存的文件名称
*/
saveAs (blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename)
} else {
const link = document.createElement('a')
const body = document.querySelector('body')
link.href = window.URL.createObjectURL(blob)
link.download = filename
// fix Firefox
link.style.display = 'none'
body.appendChild(link)
link.click()
body.removeChild(link)
window.URL.revokeObjectURL(link.href)
}
},
/**
* 下载
* @param {String} url 目标文件地址
* @param {String} filename 想要保存的文件名称
*/
downloadFile (url, filename) {
this.getBlob(url).then(blob => {
this.saveAs(blob, filename)
})
}
},
mounted () {