Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
a4558c32
Commit
a4558c32
authored
Oct 23, 2021
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解析blob响应是否登录失效
parent
ef4fef3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
10 deletions
+35
-10
ruoyi-ui/src/plugins/download.js
ruoyi-ui/src/plugins/download.js
+35
-10
No files found.
ruoyi-ui/src/plugins/download.js
View file @
a4558c32
import
{
saveAs
}
from
'
file-saver
'
import
{
saveAs
}
from
'
file-saver
'
import
axios
from
'
axios
'
import
axios
from
'
axios
'
import
{
getToken
}
from
'
@/utils/auth
'
import
{
getToken
}
from
'
@/utils/auth
'
import
{
Message
}
from
'
element-ui
'
const
baseURL
=
process
.
env
.
VUE_APP_BASE_API
const
baseURL
=
process
.
env
.
VUE_APP_BASE_API
...
@@ -12,9 +13,14 @@ export default {
...
@@ -12,9 +13,14 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
}).
then
(
async
(
res
)
=>
{
const
blob
=
new
Blob
([
res
.
data
])
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
Message
.
error
(
'
无效的会话,或者会话已过期,请重新登录。
'
);
}
})
})
},
},
resource
(
resource
)
{
resource
(
resource
)
{
...
@@ -24,9 +30,14 @@ export default {
...
@@ -24,9 +30,14 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
}).
then
(
async
(
res
)
=>
{
const
blob
=
new
Blob
([
res
.
data
])
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'
download-filename
'
]))
}
else
{
Message
.
error
(
'
无效的会话,或者会话已过期,请重新登录。
'
);
}
})
})
},
},
zip
(
url
,
name
)
{
zip
(
url
,
name
)
{
...
@@ -36,13 +47,27 @@ export default {
...
@@ -36,13 +47,27 @@ export default {
url
:
url
,
url
:
url
,
responseType
:
'
blob
'
,
responseType
:
'
blob
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
getToken
()
}
}).
then
(
res
=>
{
}).
then
(
async
(
res
)
=>
{
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
'
application/zip
'
})
const
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
this
.
saveAs
(
blob
,
name
)
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
)
{
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
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