Commit b30763b3 authored by aiduck's avatar aiduck

opt

parent 086f64f7
{ {
"name": "hunter-rrweb", "name": "@tuia/rip",
"version": "0.0.1", "version": "0.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
......
...@@ -12,8 +12,10 @@ export default class Monitor { ...@@ -12,8 +12,10 @@ export default class Monitor {
payload: { payload: {
system, system,
userIdentifier, userIdentifier,
config: {
env, env,
log, log,
}
}, },
}); });
} }
......
...@@ -3,14 +3,18 @@ import Counter from "./counter"; ...@@ -3,14 +3,18 @@ import Counter from "./counter";
import { dataWrapper, log } from './utils'; import { dataWrapper, log } from './utils';
class Reporter { class Reporter {
system = ''; // 系统名 // 基础配置
baseInfo = {
system: '',
userIdentifier: '',
path: '',
};
// 系统配置
config = { config = {
env: 'prod', env: 'prod',
log: false log: false
}; // 系统配置 };
environmentUrl = ''; // 环境 environmentUrl = ''; // 环境配置
userIdentifier = ''; //用户标示
path = ''; // 当前路径
isUploading = false; // 是否在上传cdn isUploading = false; // 是否在上传cdn
bus = []; // 上传分片数据 bus = []; // 上传分片数据
counter = new Counter(); // 计数器和recordKey一起重置 counter = new Counter(); // 计数器和recordKey一起重置
...@@ -20,16 +24,15 @@ class Reporter { ...@@ -20,16 +24,15 @@ class Reporter {
} }
// 设置参数内容 // 设置参数内容
setData(dataObj) { setData(dataObj) {
console.log(dataObj);
// 设置系统名
this.system = dataObj.system || this.system;
// 设置配置内容 // 设置配置内容
this.config = dataObj.config || this.config; this.config = dataObj.config || this.config;
this.setEnvironment(this.config.env); this.setEnvironment(this.config.env);
// 设置用户标示 // 设置基础信息 系统名 + 用户标示 + 当前访问路径
this.userIdentifier = dataObj.userInfo || this.userIdentifier; dataObj.config && delete dataObj.config
// 设置当前访问路径 this.baseInfo = {
this.path = dataObj.url || this.path; ...this.baseInfo,
...dataObj
}
} }
// 设置系统环境变量 // 设置系统环境变量
......
...@@ -7,8 +7,8 @@ const reporter = new Reporter("recordKey"); ...@@ -7,8 +7,8 @@ const reporter = new Reporter("recordKey");
onmessage = ({ data: { type, payload } }) => { onmessage = ({ data: { type, payload } }) => {
switch (type) { switch (type) {
case "init": case "init":
log(reporter.config.log, 'init参数', payload);
reporter.setData(payload); reporter.setData(payload);
log(reporter.config.log, 'init参数', payload);
break; break;
case "record": case "record":
// todo : 数据本地存储 // todo : 数据本地存储
...@@ -31,11 +31,11 @@ onmessage = ({ data: { type, payload } }) => { ...@@ -31,11 +31,11 @@ onmessage = ({ data: { type, payload } }) => {
break; break;
case "reset": case "reset":
// todo : 重置参数,重新生成recordKey // todo : 重置参数,重新生成recordKey
const { url, email, userInfo } = payload; const { path, email } = payload;
reporter.setData(payload); reporter.setData({path});
let recordKey = md5(url + email + Date.parse(new Date())); let recordKey = md5(path + email + Date.parse(new Date()));
reporter.reset(recordKey); reporter.reset(recordKey);
log(reporter.config.log, '用户信息', userInfo); log(reporter.config.log, 'path', reporter.baseInfo.path);
log(reporter.config.log, '分片id', reporter.recordKey); log(reporter.config.log, '分片id', reporter.recordKey);
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment