Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rip
Project
Project
Details
Activity
Releases
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
fanxuehui
rip
Commits
0ea00e76
Commit
0ea00e76
authored
Aug 06, 2019
by
fanxuehui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor:
parent
152a8893
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
31 deletions
+63
-31
package-lock.json
package-lock.json
+30
-11
index.d.ts
src/index.d.ts
+0
-9
index.js
src/index.js
+1
-1
monitor.js
src/lib/monitor.js
+10
-3
reporter.js
src/lib/reporter.js
+14
-6
tracks.worker.js
src/lib/tracks.worker.js
+1
-1
utils.js
src/lib/utils.js
+7
-0
No files found.
package-lock.json
View file @
0ea00e76
...
...
@@ -2274,7 +2274,8 @@
"ansi-regex"
:
{
"version"
:
"2.1.1"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"aproba"
:
{
"version"
:
"1.2.0"
,
...
...
@@ -2295,12 +2296,14 @@
"balanced-match"
:
{
"version"
:
"1.0.0"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"brace-expansion"
:
{
"version"
:
"1.1.11"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"balanced-match"
:
"^1.0.0"
,
"concat-map"
:
"0.0.1"
...
...
@@ -2315,17 +2318,20 @@
"code-point-at"
:
{
"version"
:
"1.1.0"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"concat-map"
:
{
"version"
:
"0.0.1"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"console-control-strings"
:
{
"version"
:
"1.1.0"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"core-util-is"
:
{
"version"
:
"1.0.2"
,
...
...
@@ -2442,7 +2448,8 @@
"inherits"
:
{
"version"
:
"2.0.3"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"ini"
:
{
"version"
:
"1.3.5"
,
...
...
@@ -2454,6 +2461,7 @@
"version"
:
"1.0.0"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"number-is-nan"
:
"^1.0.0"
}
...
...
@@ -2468,6 +2476,7 @@
"version"
:
"3.0.4"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"brace-expansion"
:
"^1.1.7"
}
...
...
@@ -2475,12 +2484,14 @@
"minimist"
:
{
"version"
:
"0.0.8"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"minipass"
:
{
"version"
:
"2.3.5"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"safe-buffer"
:
"^5.1.2"
,
"yallist"
:
"^3.0.0"
...
...
@@ -2499,6 +2510,7 @@
"version"
:
"0.5.1"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"minimist"
:
"0.0.8"
}
...
...
@@ -2579,7 +2591,8 @@
"number-is-nan"
:
{
"version"
:
"1.0.1"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"object-assign"
:
{
"version"
:
"4.1.1"
,
...
...
@@ -2591,6 +2604,7 @@
"version"
:
"1.4.0"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"wrappy"
:
"1"
}
...
...
@@ -2676,7 +2690,8 @@
"safe-buffer"
:
{
"version"
:
"5.1.2"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"safer-buffer"
:
{
"version"
:
"2.1.2"
,
...
...
@@ -2712,6 +2727,7 @@
"version"
:
"1.0.2"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"code-point-at"
:
"^1.0.0"
,
"is-fullwidth-code-point"
:
"^1.0.0"
,
...
...
@@ -2731,6 +2747,7 @@
"version"
:
"3.0.1"
,
"bundled"
:
true
,
"dev"
:
true
,
"optional"
:
true
,
"requires"
:
{
"ansi-regex"
:
"^2.0.0"
}
...
...
@@ -2774,12 +2791,14 @@
"wrappy"
:
{
"version"
:
"1.0.2"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
},
"yallist"
:
{
"version"
:
"3.0.3"
,
"bundled"
:
true
,
"dev"
:
true
"dev"
:
true
,
"optional"
:
true
}
}
},
...
...
src/index.d.ts
deleted
100644 → 0
View file @
152a8893
export
interface
MProps
{
system
:
string
;
userIdentifier
:
string
;
env
:
"dev"
|
"prod"
;
log
:
boolean
;
}
export
declare
class
Monitor
{
constructor
(
props
:
MProps
);
}
\ No newline at end of file
src/index.js
View file @
0ea00e76
import
Monitor
from
"./lib/monitor"
;
export
default
Monitor
;
export
default
new
Monitor
()
;
src/lib/monitor.js
View file @
0ea00e76
import
*
as
rrweb
from
"rrweb"
;
import
TracksWorker
from
"./tracks.worker"
;
import
{
getPureHash
}
from
"./utils"
;
class
Monitor
{
rrwebHandler
=
null
;
initialized
=
false
;
listenedRoute
=
false
;
tracksWorker
=
new
TracksWorker
();
init
({
system
,
userIdentifier
,
env
=
"prod"
,
log
=
false
})
{
init
({
system
,
userIdentifier
,
env
=
"prod"
,
log
=
false
,
path
=
"/"
})
{
if
(
!
system
||
!
userIdentifier
)
{
console
.
error
(
"system,userIdentifier是必传的"
);
}
...
...
@@ -14,6 +14,7 @@ class Monitor {
this
.
tracksWorker
.
postMessage
({
type
:
"init"
,
payload
:
{
path
,
system
,
userIdentifier
,
env
,
...
...
@@ -51,7 +52,13 @@ class Monitor {
listenOnHash
()
{
if
(
this
.
listenedRoute
)
return
;
let
timer
=
null
;
let
preHash
=
""
;
window
.
addEventListener
(
"hashchange"
,
()
=>
{
// 忽略hash后的query
let
hash
=
getPureHash
(
location
.
hash
);
if
(
hash
===
preHash
)
return
;
preHash
=
hash
;
//防抖,防止无效的频繁触发
clearTimeout
(
timer
);
timer
=
setTimeout
(()
=>
{
this
.
reset
({
path
:
location
.
hash
});
...
...
@@ -80,4 +87,4 @@ class Monitor {
}
}
export
default
new
Monitor
()
;
export
default
Monitor
;
src/lib/reporter.js
View file @
0ea00e76
...
...
@@ -10,6 +10,7 @@ class Reporter {
userIdentifier
:
""
,
path
:
""
,
};
recordKey
=
""
;
environmentUrl
=
""
;
// 环境配置
isUploading
=
false
;
// 是否在上传cdn
bus
=
[];
// 上传分片数据
...
...
@@ -19,13 +20,13 @@ class Reporter {
this
.
baseInfo
=
baseInfo
;
this
.
setEnvironment
(
env
);
}
// 设置参数内容
setData
(
dataObj
)
{
// 设置基础信息 系统名 + 用户标示 + 当前访问路径
// 更新数据
updateData
(
data
)
{
this
.
baseInfo
=
{
...
this
.
baseInfo
,
...
data
Obj
,
...
data
,
};
this
.
generateKey
();
}
// 设置系统环境变量
...
...
@@ -127,8 +128,15 @@ class Reporter {
}
}
generateKey
()
{
const
{
path
,
userIdentifier
}
=
this
;
this
.
recordKey
=
md5
(
path
+
userIdentifier
+
Date
.
parse
(
new
Date
()));
let
{
path
,
userIdentifier
}
=
this
.
baseInfo
;
let
userIdentifierStr
=
""
;
if
(
typeof
userIdentifier
!==
"string"
)
{
userIdentifierStr
=
JSON
.
stringify
(
userIdentifier
);
}
else
{
userIdentifierStr
=
userIdentifier
;
}
let
str
=
path
+
userIdentifierStr
+
Date
.
now
().
valueOf
();
this
.
recordKey
=
md5
(
str
);
}
// 重置数据(分条使用)
reset
()
{
...
...
src/lib/tracks.worker.js
View file @
0ea00e76
...
...
@@ -31,7 +31,7 @@ onmessage = ({ data: { type, payload } }) => {
break
;
case
"reset"
:
// todo : 重置参数,重新生成recordKey
reporter
.
set
Data
(
payload
);
reporter
.
update
Data
(
payload
);
reporter
.
reset
();
log
(
"path"
,
reporter
.
baseInfo
.
path
);
log
(
"分片id"
,
reporter
.
recordKey
);
...
...
src/lib/utils.js
View file @
0ea00e76
...
...
@@ -9,3 +9,10 @@ export const dataWrapper = (extraData, event) => {
track
:
event
,
};
};
export
const
is
=
(
type
,
target
)
=>
{
return
Object
.
prototype
.
toString
.
apply
(
target
)
===
`[object
${
type
}
]`
;
};
export
const
getPureHash
=
hash
=>
{
return
hash
.
split
(
"?"
)[
0
];
};
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