Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue-gjjs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fukai
vue-gjjs
Commits
5e4c1a64
Commit
5e4c1a64
authored
Mar 22, 2023
by
李少勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理word文件流下载问题
parent
bc11304b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
2 deletions
+36
-2
index.vue
src/views/FileReview/index.vue
+36
-2
No files found.
src/views/FileReview/index.vue
View file @
5e4c1a64
...
...
@@ -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/
templateW
ord'
,
{
let
res
=
await
Api
.
post
(
'/file/api/
w
ord'
,
{
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment