Commit 5e4c1a64 by 李少勇

处理word文件流下载问题

parent bc11304b
......@@ -5,6 +5,7 @@
</template>
<script>
import Api from "~/service/Api"
import axios from 'axios'
export default {
name: 'FileReview',
data () {
......@@ -13,11 +14,12 @@ export default {
}
},
mounted () {
this.getFileTemplateUrl()
// this.getFileTemplateUrl()
this.getWordBlobDown()
},
methods: {
async getFileTemplateUrl () {
let res = await Api.post('/file/api/templateWord', {
let res = await Api.post('/file/api/word', {
fileName: '222.docx',
templateName: '222.docx',
templateData: {
......@@ -41,6 +43,38 @@ export default {
// this.fileUrl = 'data:image/png;base64,' + res
// console.log('this.fileUrl', this.fileUrl)
},
// 获取word文件流
getWordBlobDown () {
axios({
method: 'post',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
url: '/gjjs/file/api/word',
responseType: 'blob',
data: {"fileName":"2222.docx","templateName":"222.docx","title":"1111","date":"2222","brNo":"3333","amount":"4444","no":"4444"},
}).then((res) => {
console.log('pppp', res)
var content = res.headers['content-disposition'];
var name = content && content.split(';')[1].split('filename=')[1];
var fileName = decodeURIComponent(name)
this.downloadFile(res.data,fileName)
})
},
// word文件流下载
downloadFile (data, fileName) {
// data为blob格式
var blob = new Blob([data]);
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL(blob);
// downloadElement.href = href;
// downloadElement.download = fileName;
// document.body.appendChild(downloadElement);
// downloadElement.click();
// document.body.removeChild(downloadElement);
// window.URL.revokeObjectURL(href);
this.fileUrl = href
},
viewPdf (content) {
if (!content) {
console.log(content)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment