Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e5f4a21d
authored
Dec 31, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
format
parent
77a09347
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
service/monitor.ts
service/monitor.ts
View file @
e5f4a21d
import
Axios
from
"axios"
;
import
Axios
,
{
AxiosResponse
}
from
"axios"
;
import
{
UniplatSdk
}
from
"uniplat-sdk"
;
import
{
ImEnvironment
}
from
"../model"
;
...
...
@@ -31,6 +31,7 @@ class WebMonitor {
private
key
=
""
;
private
envir
=
ImEnvironment
.
Dev
;
private
product
=
Product
.
Default
;
private
cachedUa
=
''
;
private
readonly
url
=
"https://pre-hrs-monitor.hrs100.com"
;
public
updateKey
(
key
:
string
)
{
...
...
@@ -84,13 +85,28 @@ class WebMonitor {
);
}
private
getUa
()
{
if
(
!
this
.
cachedUa
)
{
const
build
=
(
t
:
string
,
c
:
string
)
=>
`<span class="
${
c
}
">
${
t
}
</span>`
this
.
cachedUa
=
window
.
navigator
.
userAgent
.
replace
(
/Android/ig
,
build
(
'Android'
,
'primary'
))
.
replace
(
/iPhone/ig
,
build
(
'iPhone'
,
'primary'
))
.
replace
(
/Mac OS X/ig
,
build
(
'Mac OS X'
,
'primary'
))
.
replace
(
/QQXBUA/ig
,
build
(
'QQXBUA'
,
'secondary'
))
.
replace
(
/isFlutter/ig
,
build
(
'isFlutter'
,
'secondary'
))
.
replace
(
/
\"
version
\"
/ig
,
build
(
'"version"'
,
'secondary'
));
}
return
this
.
cachedUa
;
}
public
useSdk
(
sdk
:
UniplatSdk
,
options
:
SdkMonitorOption
)
{
this
.
envir
=
options
.
envir
;
this
.
product
=
options
.
product
;
sdk
.
events
.
addUniversalErrorResponseCallback
((
r
)
=>
{
sdk
.
events
.
addUniversalErrorResponseCallback
((
r
:
AxiosResponse
<
any
>
)
=>
{
if
(
this
.
enable
())
{
const
msg
:
string
[]
=
[];
msg
.
push
(
`URL:
${
decodeURIComponent
(
r
.
config
.
url
)}
`
);
msg
.
push
(
`URL:
${
decodeURIComponent
(
r
.
config
.
url
as
string
)}
`
);
msg
.
push
(
`Token:
${
sdk
.
global
.
jwtToken
}
`
);
const
header
=
r
.
config
.
headers
;
if
(
header
)
{
...
...
@@ -106,6 +122,7 @@ class WebMonitor {
options
&&
options
.
userAgent
&&
msg
.
push
(
`UserAgent:
${
window
.
navigator
.
userAgent
}
`
);
r
.
config
&&
r
.
config
.
data
&&
msg
.
push
(
`Payload:
${
JSON
.
stringify
(
r
.
config
.
data
)}
`
);
r
&&
r
.
config
&&
this
.
error
(
msg
.
join
(
"\n"
));
}
});
...
...
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