From d28b01d3e845c029f2cc495a65a7e479c75722d8 Mon Sep 17 00:00:00 2001 From: mehaotian <490272692@qq.com> Date: Thu, 22 Aug 2019 13:44:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(stat):=E4=BF=AE=E5=A4=8D=20=20ios=20setTime?= =?UTF-8?q?out=20=E6=8A=A5=E9=94=99=20=EF=BC=8C=20=E5=AE=89=E5=8D=93?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84bug=EF=BC=8Capp=20=E7=AB=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20=E8=8E=B7=E5=8F=96=20version=20=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-stat/dist/index.js | 72 ++++++++++++++++++++++----------- packages/uni-stat/package.json | 2 +- packages/uni-stat/src/stat.js | 72 ++++++++++++++++++++++----------- 3 files changed, 99 insertions(+), 47 deletions(-) diff --git a/packages/uni-stat/dist/index.js b/packages/uni-stat/dist/index.js index 7259e501..dadcf52c 100644 --- a/packages/uni-stat/dist/index.js +++ b/packages/uni-stat/dist/index.js @@ -446,16 +446,21 @@ class Util { }, 0); } _sendReportRequest(options) { + this._navigationBarTitle.lt = '1'; let query = options.query && JSON.stringify(options.query) !== '{}' ? '?' + JSON.stringify(options.query) : ''; this.statData.lt = '1'; - this.statData.url = options.path + query; + this.statData.url = (options.path + query) || ''; this.statData.t = getTime(); this.statData.sc = getScene(options.scene); this.statData.fvts = getFirstVisitTime(); this.statData.lvts = getLastVisitTime(); this.statData.tvc = getTotalVisitCount(); - this.getNetworkInfo(); + if (getPlatformName() === 'n') { + this.getProperty(); + } else { + this.getNetworkInfo(); + } } _sendPageRequest(opt) { @@ -479,6 +484,13 @@ class Util { t: getTime(), p: this.statData.p }; + if (getPlatformName() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.request(options); + }, 200); + return + } + this.request(options); } @@ -499,6 +511,12 @@ class Util { t: getTime(), p: this.statData.p }; + if (getPlatformName() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.request(options, type); + }, 200); + return + } this.request(options, type); } _sendEventRequest({ @@ -531,6 +549,13 @@ class Util { }); } + getProperty() { + plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { + this.statData.v = wgtinfo.version || ''; + this.getNetworkInfo(); + }); + } + getLocation() { if (statConfig.getLocation) { uni.getLocation({ @@ -618,28 +643,29 @@ class Util { return } - setTimeout(() => { - uni.request({ - url: STAT_URL, - method: 'POST', - data: optionsData, - success: () => { - if (process.env.NODE_ENV === 'development') { - console.log('stat request success'); - } - }, - fail: (e) => { - if (process.env.NODE_ENV === 'development') { - console.log('stat request fail', e); - } - if (++this._retry < 3) { - setTimeout(() => { - this.request(data); - }, 1000); - } + uni.request({ + url: STAT_URL, + method: 'POST', + // header: { + // 'content-type': 'application/json' // 默认值 + // }, + data: optionsData, + success: () => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request success'); } - }); - }, 200); + }, + fail: (e) => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request fail', e); + } + if (++this._retry < 3) { + setTimeout(() => { + this.request(data); + }, 1000); + } + } + }); } /** diff --git a/packages/uni-stat/package.json b/packages/uni-stat/package.json index 16f55d24..a96db93b 100644 --- a/packages/uni-stat/package.json +++ b/packages/uni-stat/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-stat", - "version": "0.0.111", + "version": "0.0.113", "description": "", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-stat/src/stat.js b/packages/uni-stat/src/stat.js index cce8a095..3389e8b1 100644 --- a/packages/uni-stat/src/stat.js +++ b/packages/uni-stat/src/stat.js @@ -181,16 +181,21 @@ class Util { }, 0) } _sendReportRequest(options) { + this._navigationBarTitle.lt = '1'; let query = options.query && JSON.stringify(options.query) !== '{}' ? '?' + JSON.stringify(options.query) : ''; this.statData.lt = '1'; - this.statData.url = options.path + query; + this.statData.url = (options.path + query) || ''; this.statData.t = getTime(); this.statData.sc = getScene(options.scene); this.statData.fvts = getFirstVisitTime(); this.statData.lvts = getLastVisitTime(); this.statData.tvc = getTotalVisitCount(); - this.getNetworkInfo(); + if (getPlatformName() === 'n') { + this.getProperty(); + } else { + this.getNetworkInfo(); + } } _sendPageRequest(opt) { @@ -214,6 +219,13 @@ class Util { t: getTime(), p: this.statData.p } + if (getPlatformName() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.request(options); + }, 200) + return + } + this.request(options); } @@ -234,6 +246,12 @@ class Util { t: getTime(), p: this.statData.p } + if (getPlatformName() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.request(options, type) + }, 200) + return + } this.request(options, type) } _sendEventRequest({ @@ -266,6 +284,13 @@ class Util { }); } + getProperty() { + plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { + this.statData.v = wgtinfo.version || ''; + this.getNetworkInfo(); + }); + } + getLocation() { if (statConfig.getLocation) { uni.getLocation({ @@ -353,28 +378,29 @@ class Util { return } - setTimeout(() => { - uni.request({ - url: STAT_URL, - method: 'POST', - data: optionsData, - success: () => { - if (process.env.NODE_ENV === 'development') { - console.log('stat request success'); - } - }, - fail: (e) => { - if (process.env.NODE_ENV === 'development') { - console.log('stat request fail', e); - } - if (++this._retry < 3) { - setTimeout(() => { - this.request(data); - }, 1000); - } + uni.request({ + url: STAT_URL, + method: 'POST', + // header: { + // 'content-type': 'application/json' // 默认值 + // }, + data: optionsData, + success: () => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request success'); } - }); - }, 200) + }, + fail: (e) => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request fail', e); + } + if (++this._retry < 3) { + setTimeout(() => { + this.request(data); + }, 1000); + } + } + }); } /** -- GitLab