Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
factory_front
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinjianhui
factory_front
Commits
a5b39b89
Commit
a5b39b89
authored
Mar 27, 2026
by
zhuzhequan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数组上报
parent
f46cc331
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
3 deletions
+48
-3
src/api/axios.ts
+48
-3
No files found.
src/api/axios.ts
View file @
a5b39b89
...
@@ -2,10 +2,36 @@ import router from '@/router'
...
@@ -2,10 +2,36 @@ import router from '@/router'
import
Axios
from
'axios'
import
Axios
from
'axios'
import
{
showError
}
from
'@/utils/ui.ts'
import
{
showError
}
from
'@/utils/ui.ts'
import
{
v4
as
uuidv4
}
from
'uuid'
import
{
v4
as
uuidv4
}
from
'uuid'
import
dayjs
from
'dayjs'
const
axios
=
Axios
.
create
({
const
axios
=
Axios
.
create
({
baseURL
:
import
.
meta
.
env
.
VITE_API_BASE
,
baseURL
:
import
.
meta
.
env
.
VITE_API_BASE
,
timeout
:
60
*
60
*
1000
,
//半小时
timeout
:
60
*
60
*
1000
,
//半小时
})
})
const
apiRequestKey
=
'apiRequestStorage'
const
getRequestData
=
()
=>
{
return
JSON
.
parse
(
localStorage
.
getItem
(
apiRequestKey
)
||
'[]'
)
}
const
findRequestItemByUUID
=
(
uuid
:
string
)
=>
{
const
data
=
getRequestData
()
return
data
.
find
((
d
:
any
)
=>
d
.
uuid
===
uuid
)
}
const
deleteRequestByUUID
=
(
uuid
:
string
)
=>
{
let
data
=
getRequestData
()
data
=
data
.
filter
((
d
:
any
)
=>
d
.
uuid
!==
uuid
)
localStorage
.
setItem
(
apiRequestKey
,
JSON
.
stringify
(
data
))
}
const
addRequestItem
=
(
item
?:
never
)
=>
{
const
data
=
getRequestData
()
data
.
push
(
item
)
localStorage
.
setItem
(
apiRequestKey
,
JSON
.
stringify
(
data
))
return
data
}
const
TOKEN_KEY
=
'token'
const
TOKEN_KEY
=
'token'
...
@@ -22,9 +48,15 @@ axios.interceptors.request.use(
...
@@ -22,9 +48,15 @@ axios.interceptors.request.use(
const
token
=
getToken
()
const
token
=
getToken
()
if
(
token
)
{
if
(
token
)
{
config
.
headers
[
'jwt-token'
]
=
token
config
.
headers
[
'jwt-token'
]
=
token
config
.
headers
.
timestamp
=
new
Date
().
getTime
()
config
.
headers
.
uuid
=
uuidv4
().
replace
(
/-/g
,
''
)
}
}
config
.
headers
.
timestamp
=
new
Date
().
getTime
()
config
.
headers
.
uuid
=
uuidv4
().
replace
(
/-/g
,
''
)
addRequestItem
({
url
:
config
.
url
,
method
:
config
.
method
,
startTime
:
dayjs
(
new
Date
()).
format
(
'YYYY-MM-DD HH:mm:ss'
),
uuid
:
config
.
headers
.
uuid
})
return
config
return
config
},
},
(
error
)
=>
{
(
error
)
=>
{
...
@@ -35,7 +67,20 @@ axios.interceptors.response.use(
...
@@ -35,7 +67,20 @@ axios.interceptors.response.use(
(
response
)
=>
{
(
response
)
=>
{
// 1. 判断响应码
// 1. 判断响应码
const
data
=
response
.
data
const
data
=
response
.
data
console
.
log
(
response
)
const
uuid
=
response
.
config
?.
headers
?.
uuid
const
item
=
findRequestItemByUUID
(
uuid
)
item
.
url
=
`/api
${
response
.
config
?.
url
}
`
const fm = new FormData()
for(const k in item || {}){
fm.append(k, item[k])
}
const processTime = response.headers['x-server-process-time']
fm.append('endTime', dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'))
fm.append('processTime', processTime)
navigator.sendBeacon('/api/factory/ops/report-data', fm)
console.log(uuid)
deleteRequestByUUID(uuid)
if (data && typeof data === 'object' && typeof data.code === 'number') {
if (data && typeof data === 'object' && typeof data.code === 'number') {
// token 过期
// token 过期
if (data.code === 403) {
if (data.code === 403) {
...
...
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