Commit 07d42b86 authored by fanxuehui's avatar fanxuehui

fix

parent 41d47ee6
...@@ -9,7 +9,7 @@ class Reporter { ...@@ -9,7 +9,7 @@ class Reporter {
system: "", system: "",
userIdentifier: "", userIdentifier: "",
path: "", path: "",
protocol: "" protocol: "",
}; };
recordKey = ""; recordKey = "";
environmentUrl = ""; // 环境配置 environmentUrl = ""; // 环境配置
...@@ -44,15 +44,15 @@ class Reporter { ...@@ -44,15 +44,15 @@ class Reporter {
// 保存上下文 // 保存上下文
const trackId = this.counter.count; const trackId = this.counter.count;
const recordKey = this.recordKey; const recordKey = this.recordKey;
log('trackId', trackId); log("trackId", trackId);
log('recordKey', recordKey); log("recordKey", recordKey);
this.uploadingPile.add(trackId); this.uploadingPile.add(trackId);
formData.append("file", blob, `${this.recordKey + trackId}.json`); formData.append("file", blob, `${this.recordKey + trackId}.json`);
const extra = { const extra = {
...this.baseInfo, ...this.baseInfo,
recordKey: this.recordKey, recordKey: this.recordKey,
trackId: trackId, trackId: trackId,
isCDN: true isCDN: true,
}; };
try { try {
fetch(`${this.environmentUrl}/upload`, { fetch(`${this.environmentUrl}/upload`, {
...@@ -70,15 +70,11 @@ class Reporter { ...@@ -70,15 +70,11 @@ class Reporter {
* 而toCDN的接口会保存之前的trackId,而this.bus在路由跳转的时候会被清空 * 而toCDN的接口会保存之前的trackId,而this.bus在路由跳转的时候会被清空
* 那么上下文的trackId在this.bus中就会找不到,找到也不是正确的*/ * 那么上下文的trackId在this.bus中就会找不到,找到也不是正确的*/
if (this.recordKey !== recordKey) { if (this.recordKey !== recordKey) {
log('路由跳转遗留数据'); log("路由跳转遗留数据");
return; return;
} else { } else {
const snapIndex = this.bus && this.bus.findIndex((item, index) => { const snapIndex = this.bus && this.bus.findIndex(item => item.trackId === trackId);
if (item.trackId === trackId) { log("snapIndex", snapIndex);
return index;
}
});
log('snapIndex', snapIndex);
// 向bus中注入 // 向bus中注入
this.bus.splice(snapIndex, 1, dataWrapper(extra, res.data.url)); this.bus.splice(snapIndex, 1, dataWrapper(extra, res.data.url));
// 在trackId之前 包括trackId本身的数据全部上传 // 在trackId之前 包括trackId本身的数据全部上传
...@@ -97,7 +93,7 @@ class Reporter { ...@@ -97,7 +93,7 @@ class Reporter {
...this.baseInfo, ...this.baseInfo,
recordKey: this.recordKey, recordKey: this.recordKey,
trackId: this.counter.next(), trackId: this.counter.next(),
isCDN: false isCDN: false,
}; };
this.bus.push(dataWrapper(extra, data)); this.bus.push(dataWrapper(extra, data));
} }
...@@ -105,18 +101,17 @@ class Reporter { ...@@ -105,18 +101,17 @@ class Reporter {
tryReport(isOverHundred) { tryReport(isOverHundred) {
// 如果有cdn的内容在上传,那么我们不做任何的上传直接返回 // 如果有cdn的内容在上传,那么我们不做任何的上传直接返回
if (this.uploadingPile.length > 0) { if (this.uploadingPile.length > 0) {
log('有cdn的内容在上传', this.uploadingPile); log("有cdn的内容在上传", this.uploadingPile);
return; return;
} else { } else {
let reportData = isOverHundred ? this.bus.splice(0, 100) : this.bus.splice(0, this.bus.length); let reportData = isOverHundred ? this.bus.splice(0, 100) : this.bus.splice(0, this.bus.length);
this.report(reportData); this.report(reportData);
} }
} }
// 真正上传 // 真正上传
report(data) { report(data) {
log("上传数据", data); log("上传数据", data);
log('上传后的bus', this.bus); log("上传后的bus", this.bus);
try { try {
fetch(`${this.environmentUrl}/behavior/record`, { fetch(`${this.environmentUrl}/behavior/record`, {
// fetch(`http://localhost:3000/behavior/record`, { // fetch(`http://localhost:3000/behavior/record`, {
......
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