Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
tswj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2022-06-30 00:11:07 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9ce556b603a46c64b91c03ad4a75d5e53e0f3045
9ce556b6
1 parent
83e58a87
代码优化
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
src/composables/useUpload.js
src/utils/axios.js
src/composables/useUpload.js
View file @
9ce556b
/*
* @Date: 2022-05-10 12:15:14
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-
18 22:30:10
* @LastEditTime: 2022-06-
29 23:36:29
* @FilePath: /tswj/src/composables/useUpload.js
* @Description: 图片上传模块
*/
...
...
@@ -21,8 +21,8 @@ export const useUpload = () => {
let
base64url
=
dataURL
.
slice
(
dataURL
.
indexOf
(
','
)
+
1
);
// 截取前缀的base64 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnoAAAJeCAYAA.......
// 获取七牛token
const
{
token
,
key
,
code
}
=
await
qiniuTokenAPI
({
filename
:
`
${
affix
}
_
${
res
.
file
.
name
}
`
,
file
:
base64url
});
if
(
code
===
1
)
{
le
t
config
=
{
if
(
code
)
{
cons
t
config
=
{
headers
:
{
'Content-Type'
:
'application/octet-stream'
,
'Authorization'
:
'UpToken '
+
token
,
// UpToken后必须有一个 ' '(空格)
...
...
src/utils/axios.js
View file @
9ce556b
...
...
@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-
29 22:32:15
* @LastEditTime: 2022-06-
30 00:10:50
* @FilePath: /tswj/src/utils/axios.js
* @Description:
*/
...
...
@@ -24,8 +24,11 @@ axios.interceptors.request.use(
// GET请求默认打上时间戳,避免从缓存中拿数据。
const
timestamp
=
config
.
method
===
'get'
?
(
new
Date
()).
valueOf
()
:
''
;
// 上传相关接口需要屏蔽掉封装, 不能序列化数据会报错。
const
excludeUrl
=
[
'a=upload'
,
'upload.qiniup.com'
];
if
(
config
.
method
===
'post'
&&
!
excludeUrl
.
includes
(
config
.
url
))
{
if
(
config
.
method
===
'post'
&&
(
config
.
url
.
indexOf
(
'a=upload'
)
===
-
1
&&
config
.
url
.
indexOf
(
'upload.qiniup.com'
)
===
-
1
)
)
{
// POST PHP需要修改数据格式
config
.
data
=
qs
.
stringify
(
config
.
data
)
}
...
...
@@ -51,22 +54,14 @@ axios.interceptors.response.use(
if
(
response
.
data
.
code
===
401
)
{
// 特殊标识-带此标识报错不显示
response
.
data
.
show
=
false
;
// 未授权跳转登录页
// 带着上一个页面的信息, 授权完成后 返回当前页面
router
.
replace
({
path
:
'/auth'
,
query
:
{
href
:
location
.
hash
,
prefixAPI
}
});
/**
* 未授权跳转登录页
* 带着上一个页面的信息, 授权完成后 返回当前页面
*/
router
.
replace
({
path
:
'/auth'
,
query
:
{
href
:
location
.
hash
,
prefixAPI
}
});
}
// 拦截B端未登录情况
if
(
response
.
data
.
msg
===
'老师请先登录!'
||
response
.
data
.
msg
===
'老师不存在!'
)
{
router
.
replace
({
path
:
'/business/login'
});
}
if
([
'老师请先登录!'
,
'老师不存在!'
].
includes
(
response
.
data
.
msg
))
{
router
.
replace
({
path
:
'/business/login'
});
}
return
response
;
},
error
=>
{
...
...
Please
register
or
login
to post a comment