Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
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
liyang
sts网站
Commits
a4558c32
Commit
a4558c32
authored
Oct 23, 2021
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解析blob响应是否登录失效
parent
ef4fef3d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
10 deletions
+35
-10
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
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'download-filename'
]))
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
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
const
blob
=
new
Blob
([
res
.
data
])
const
blob
=
new
Blob
([
res
.
data
])
this
.
saveAs
(
blob
,
decodeURI
(
res
.
headers
[
'download-filename'
]))
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
isLogin
=
await
this
.
blobValidate
(
res
.
data
);
if
(
isLogin
)
{
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
{
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