Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
RuoYi Vue
Commits
81a01a1d
Commit
81a01a1d
authored
Feb 28, 2023
by
RuoYi
Browse files
优化文件下载出现的异常(I6DLNU)
parent
6523fe59
Changes
3
Hide whitespace changes
Inline
Side-by-side
ruoyi-ui/src/plugins/download.js
View file @
81a01a1d
...
@@ -15,9 +15,9 @@ export default {
...
@@ -15,9 +15,9 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
async
(
res
)
=>
{
}).
then
((
res
)
=>
{
const
is
Login
=
await
blobValidate
(
res
.
data
);
const
is
Blob
=
blobValidate
(
res
.
data
);
if
(
is
Login
)
{
if
(
is
Blob
)
{
const
blob
=
new
Blob
([
res
.
data
])
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURIComponent
(
res
.
headers
[
'
download-filename
'
]))
this
.
saveAs
(
blob
,
decodeURIComponent
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
}
else
{
...
@@ -32,9 +32,9 @@ export default {
...
@@ -32,9 +32,9 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
async
(
res
)
=>
{
}).
then
((
res
)
=>
{
const
is
Login
=
await
blobValidate
(
res
.
data
);
const
is
Blob
=
blobValidate
(
res
.
data
);
if
(
is
Login
)
{
if
(
is
Blob
)
{
const
blob
=
new
Blob
([
res
.
data
])
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURIComponent
(
res
.
headers
[
'
download-filename
'
]))
this
.
saveAs
(
blob
,
decodeURIComponent
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
}
else
{
...
@@ -49,9 +49,9 @@ export default {
...
@@ -49,9 +49,9 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
async
(
res
)
=>
{
}).
then
((
res
)
=>
{
const
is
Login
=
await
blobValidate
(
res
.
data
);
const
is
Blob
=
blobValidate
(
res
.
data
);
if
(
is
Login
)
{
if
(
is
Blob
)
{
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
'
application/zip
'
})
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
'
application/zip
'
})
this
.
saveAs
(
blob
,
name
)
this
.
saveAs
(
blob
,
name
)
}
else
{
}
else
{
...
...
ruoyi-ui/src/utils/request.js
View file @
81a01a1d
...
@@ -72,7 +72,7 @@ service.interceptors.response.use(res => {
...
@@ -72,7 +72,7 @@ service.interceptors.response.use(res => {
// 获取错误信息
// 获取错误信息
const
msg
=
errorCode
[
code
]
||
res
.
data
.
msg
||
errorCode
[
'
default
'
]
const
msg
=
errorCode
[
code
]
||
res
.
data
.
msg
||
errorCode
[
'
default
'
]
// 二进制数据则直接返回
// 二进制数据则直接返回
if
(
res
.
request
.
responseType
===
'
blob
'
||
res
.
request
.
responseType
===
'
arraybuffer
'
){
if
(
res
.
request
.
responseType
===
'
blob
'
||
res
.
request
.
responseType
===
'
arraybuffer
'
)
{
return
res
.
data
return
res
.
data
}
}
if
(
code
===
401
)
{
if
(
code
===
401
)
{
...
@@ -125,8 +125,8 @@ export function download(url, params, filename, config) {
...
@@ -125,8 +125,8 @@ export function download(url, params, filename, config) {
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
...
config
...
config
}).
then
(
async
(
data
)
=>
{
}).
then
(
async
(
data
)
=>
{
const
is
Login
=
await
blobValidate
(
data
);
const
is
Blob
=
blobValidate
(
data
);
if
(
is
Login
)
{
if
(
is
Blob
)
{
const
blob
=
new
Blob
([
data
])
const
blob
=
new
Blob
([
data
])
saveAs
(
blob
,
filename
)
saveAs
(
blob
,
filename
)
}
else
{
}
else
{
...
...
ruoyi-ui/src/utils/ruoyi.js
View file @
81a01a1d
...
@@ -228,12 +228,6 @@ export function tansParams(params) {
...
@@ -228,12 +228,6 @@ export function tansParams(params) {
}
}
// 验证是否为blob格式
// 验证是否为blob格式
export
async
function
blobValidate
(
data
)
{
export
function
blobValidate
(
data
)
{
try
{
return
data
.
type
!==
'
application/json
'
const
text
=
await
data
.
text
();
JSON
.
parse
(
text
);
return
false
;
}
catch
(
error
)
{
return
true
;
}
}
}
Write
Preview
Supports
Markdown
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