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
a4558c32
Commit
a4558c32
authored
Oct 23, 2021
by
RuoYi
Browse files
解析blob响应是否登录失效
parent
ef4fef3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
ruoyi-ui/src/plugins/download.js
View file @
a4558c32
import
{
saveAs
}
from
'
file-saver
'
import
axios
from
'
axios
'
import
{
getToken
}
from
'
@/utils/auth
'
import
{
Message
}
from
'
element-ui
'
const
baseURL
=
process
.
env
.
VUE_APP_BASE_API
...
...
@@ -12,9 +13,14 @@ export default {
url
:
url
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}).
then
(
async
(
res
)
=>
{
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
Message
.
error
(
'
无效的会话,或者会话已过期,请重新登录。
'
);
}
})
},
resource
(
resource
)
{
...
...
@@ -24,9 +30,14 @@ export default {
url
:
url
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}).
then
(
async
(
res
)
=>
{
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
Message
.
error
(
'
无效的会话,或者会话已过期,请重新登录。
'
);
}
})
},
zip
(
url
,
name
)
{
...
...
@@ -36,13 +47,27 @@ export default {
url
:
url
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
'
application/zip
'
})
this
.
saveAs
(
blob
,
name
)
}).
then
(
async
(
res
)
=>
{
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
'
application/zip
'
})
this
.
saveAs
(
blob
,
name
)
}
else
{
Message
.
error
(
'
无效的会话,或者会话已过期,请重新登录。
'
);
}
})
},
saveAs
(
text
,
name
,
opts
)
{
saveAs
(
text
,
name
,
opts
);
}
},
async
blobValidate
(
data
)
{
try
{
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