提交 cca287f8 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'dev' of https://github.com/dcloudio/uni-app into dev

...@@ -6,6 +6,7 @@ const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; ...@@ -6,6 +6,7 @@ const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; const PAGE_PVER_TIME = 1800;
const APP_PVER_TIME = 300; const APP_PVER_TIME = 300;
const OPERATING_TIME = 10; const OPERATING_TIME = 10;
const DIFF_TIME = 60 * 1000 * 60 * 24;
const statConfig = require('uni-stat-config').default || require('uni-stat-config'); const statConfig = require('uni-stat-config').default || require('uni-stat-config');
const UUID_KEY = '__DC_STAT_UUID'; const UUID_KEY = '__DC_STAT_UUID';
...@@ -299,12 +300,12 @@ const calibration = (eventName, options) => { ...@@ -299,12 +300,12 @@ const calibration = (eventName, options) => {
}; };
const Report_Data_Time = 'Report_Data_Time'; const Report_Data_Time = 'Report_Data_Time';
const Report_Status = 'Report_Status';
const isReportData = () => { const isReportData = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let start_time = ''; let start_time = '';
let end_time = new Date().getTime(); let end_time = new Date().getTime();
let diff_time = 60 * 1000 * 60 * 24; let diff_time = DIFF_TIME;
try { try {
start_time = uni.getStorageSync(Report_Data_Time); start_time = uni.getStorageSync(Report_Data_Time);
} catch (e) { } catch (e) {
...@@ -320,6 +321,7 @@ const isReportData = () => { ...@@ -320,6 +321,7 @@ const isReportData = () => {
enable enable
}) => { }) => {
uni.setStorageSync(Report_Data_Time, end_time); uni.setStorageSync(Report_Data_Time, end_time);
uni.setStorageSync(Report_Status, enable);
if (enable === 1) { if (enable === 1) {
resolve(); resolve();
} }
...@@ -328,11 +330,10 @@ const isReportData = () => { ...@@ -328,11 +330,10 @@ const isReportData = () => {
}) })
}; };
const Report_Status = 'Report_Status';
const requestData = (done) => { const requestData = (done) => {
let formData = { let formData = {
usv: STAT_VERSION, usv: STAT_VERSION,
conf: encodeURIComponent({ conf: JSON.stringify({
ak: statConfig.appid ak: statConfig.appid
}) })
}; };
...@@ -340,8 +341,10 @@ const requestData = (done) => { ...@@ -340,8 +341,10 @@ const requestData = (done) => {
url: STAT_URL, url: STAT_URL,
method: 'GET', method: 'GET',
data: formData, data: formData,
success: (res) => { success: (res) => {
const {data} = res; const {
data
} = res;
if (data.ret === 0) { if (data.ret === 0) {
typeof done === 'function' && done({ typeof done === 'function' && done({
enable: data.enable enable: data.enable
...@@ -420,11 +423,11 @@ class Util { ...@@ -420,11 +423,11 @@ class Util {
}; };
} }
getIsReportData(){ getIsReportData() {
return isReportData() return isReportData()
} }
_applicationShow() { _applicationShow() {
if (this.__licationHide) { if (this.__licationHide) {
getLastTime(); getLastTime();
...@@ -713,37 +716,39 @@ class Util { ...@@ -713,37 +716,39 @@ class Util {
} }
this._sendRequest(optionsData); this._sendRequest(optionsData);
} }
_sendRequest(optionsData) { _sendRequest(optionsData) {
this.getIsReportData().then(()=>{ this.getIsReportData().then(() => {
uni.request({ uni.request({
url: STAT_URL, url: STAT_URL,
method: 'POST', method: 'POST',
// header: { // header: {
// 'content-type': 'application/json' // 默认值 // 'content-type': 'application/json' // 默认值
// }, // },
data: optionsData, data: optionsData,
success: () => { success: () => {
// if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
// console.log('stat request success'); // console.log('stat request success');
// } // }
}, },
fail: (e) => { fail: (e) => {
if (++this._retry < 3) { if (++this._retry < 3) {
setTimeout(() => { setTimeout(() => {
this._sendRequest(optionsData); this._sendRequest(optionsData);
}, 1000); }, 1000);
} }
} }
}); });
}); });
} }
/** /**
* h5 请求 * h5 请求
*/ */
imageRequest(data) { imageRequest(data) {
let image = new Image(); this.getIsReportData().then(() => {
let options = getSgin(GetEncodeURIComponentOptions(data)).options; let image = new Image();
image.src = STAT_H5_URL + '?' + options; let options = getSgin(GetEncodeURIComponentOptions(data)).options;
image.src = STAT_H5_URL + '?' + options;
});
} }
sendEvent(key, value) { sendEvent(key, value) {
......
...@@ -8,3 +8,4 @@ export const STAT_KEY = 'qkTHEIegZGcL5iy3' ...@@ -8,3 +8,4 @@ export const STAT_KEY = 'qkTHEIegZGcL5iy3'
export const PAGE_PVER_TIME = 1800 export const PAGE_PVER_TIME = 1800
export const APP_PVER_TIME = 300 export const APP_PVER_TIME = 300
export const OPERATING_TIME = 10 export const OPERATING_TIME = 10
export const DIFF_TIME = 60 * 1000 * 60 * 24
...@@ -2,7 +2,8 @@ import { ...@@ -2,7 +2,8 @@ import {
PAGE_PVER_TIME, PAGE_PVER_TIME,
APP_PVER_TIME, APP_PVER_TIME,
STAT_URL, STAT_URL,
STAT_VERSION STAT_VERSION,
DIFF_TIME
} from './config'; } from './config';
const statConfig = require('uni-stat-config').default || require('uni-stat-config'); const statConfig = require('uni-stat-config').default || require('uni-stat-config');
const UUID_KEY = '__DC_STAT_UUID'; const UUID_KEY = '__DC_STAT_UUID';
...@@ -299,12 +300,12 @@ export const calibration = (eventName, options) => { ...@@ -299,12 +300,12 @@ export const calibration = (eventName, options) => {
} }
const Report_Data_Time = 'Report_Data_Time' const Report_Data_Time = 'Report_Data_Time'
const Report_Status = 'Report_Status'
export const isReportData = () => { export const isReportData = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let start_time = '' let start_time = ''
let end_time = new Date().getTime() let end_time = new Date().getTime()
let diff_time = 60 * 1000 * 60 * 24 let diff_time = DIFF_TIME
try { try {
start_time = uni.getStorageSync(Report_Data_Time) start_time = uni.getStorageSync(Report_Data_Time)
} catch (e) { } catch (e) {
...@@ -320,6 +321,7 @@ export const isReportData = () => { ...@@ -320,6 +321,7 @@ export const isReportData = () => {
enable enable
}) => { }) => {
uni.setStorageSync(Report_Data_Time, end_time) uni.setStorageSync(Report_Data_Time, end_time)
uni.setStorageSync(Report_Status, enable)
if (enable === 1) { if (enable === 1) {
resolve(); resolve();
} }
...@@ -328,11 +330,10 @@ export const isReportData = () => { ...@@ -328,11 +330,10 @@ export const isReportData = () => {
}) })
} }
const Report_Status = 'Report_Status'
const requestData = (done) => { const requestData = (done) => {
let formData = { let formData = {
usv: STAT_VERSION, usv: STAT_VERSION,
conf: encodeURIComponent({ conf: JSON.stringify({
ak: statConfig.appid ak: statConfig.appid
}) })
} }
...@@ -340,8 +341,10 @@ const requestData = (done) => { ...@@ -340,8 +341,10 @@ const requestData = (done) => {
url: STAT_URL, url: STAT_URL,
method: 'GET', method: 'GET',
data: formData, data: formData,
success: (res) => { success: (res) => {
const {data} = res const {
data
} = res
if (data.ret === 0) { if (data.ret === 0) {
typeof done === 'function' && done({ typeof done === 'function' && done({
enable: data.enable enable: data.enable
......
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
getPageRoute, getPageRoute,
getRoute, getRoute,
getPageTypes, getPageTypes,
calibration, calibration,
isReportData isReportData
} from './parameter'; } from './parameter';
...@@ -85,11 +85,11 @@ class Util { ...@@ -85,11 +85,11 @@ class Util {
} }
} }
getIsReportData(){ getIsReportData() {
return isReportData() return isReportData()
} }
_applicationShow() { _applicationShow() {
if (this.__licationHide) { if (this.__licationHide) {
getLastTime(); getLastTime();
...@@ -378,37 +378,39 @@ class Util { ...@@ -378,37 +378,39 @@ class Util {
} }
this._sendRequest(optionsData) this._sendRequest(optionsData)
} }
_sendRequest(optionsData) { _sendRequest(optionsData) {
this.getIsReportData().then(()=>{ this.getIsReportData().then(() => {
uni.request({ uni.request({
url: STAT_URL, url: STAT_URL,
method: 'POST', method: 'POST',
// header: { // header: {
// 'content-type': 'application/json' // 默认值 // 'content-type': 'application/json' // 默认值
// }, // },
data: optionsData, data: optionsData,
success: () => { success: () => {
// if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
// console.log('stat request success'); // console.log('stat request success');
// } // }
}, },
fail: (e) => { fail: (e) => {
if (++this._retry < 3) { if (++this._retry < 3) {
setTimeout(() => { setTimeout(() => {
this._sendRequest(optionsData); this._sendRequest(optionsData);
}, 1000); }, 1000);
} }
} }
}); });
}) })
} }
/** /**
* h5 请求 * h5 请求
*/ */
imageRequest(data) { imageRequest(data) {
let image = new Image(); this.getIsReportData().then(() => {
let options = getSgin(GetEncodeURIComponentOptions(data)).options; let image = new Image();
image.src = STAT_H5_URL + '?' + options let options = getSgin(GetEncodeURIComponentOptions(data)).options;
image.src = STAT_H5_URL + '?' + options
})
} }
sendEvent(key, value) { sendEvent(key, value) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册