提交 cbe40e14 编写于 作者: M mehaotian 提交者: d-u-a

fix(stat) : 报数前咨询服务器,是否长久未登录,若是,则本地设置24小时内不上报

上级 2981847d
......@@ -7,6 +7,7 @@ const PAGE_PVER_TIME = 1800;
const APP_PVER_TIME = 300;
const OPERATING_TIME = 10;
const statConfig = require('uni-stat-config').default || require('uni-stat-config');
const UUID_KEY = '__DC_STAT_UUID';
const UUID_VALUE = '__DC_UUID_VALUE';
......@@ -85,7 +86,7 @@ const getPackName = () => {
let packName = '';
if (getPlatformName() === 'wx' || getPlatformName() === 'qq') {
// 兼容微信小程序低版本基础库
if(uni.canIUse('getAccountInfoSync')){
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || '';
}
}
......@@ -255,7 +256,7 @@ const getPageRoute = (self) => {
if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is + str;
} else {
return (_self.$scope && _self.$scope.route + str )|| (_self.$mp && _self.$mp.page.route + str);
return (_self.$scope && _self.$scope.route + str) || (_self.$mp && _self.$mp.page.route + str);
}
};
......@@ -268,7 +269,7 @@ const getPageTypes = (self) => {
const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if(!eventName){
if (!eventName) {
console.error(`uni.report 缺少 [eventName] 参数`);
return true
}
......@@ -297,8 +298,75 @@ const calibration = (eventName, options) => {
}
};
const Report_Data_Time = 'Report_Data_Time';
const isReportData = () => {
return new Promise((resolve, reject) => {
let start_time = '';
let end_time = new Date().getTime();
let diff_time = 60 * 1000 * 60 * 24;
try {
start_time = uni.getStorageSync(Report_Data_Time);
} catch (e) {
start_time = '';
}
if (!start_time) {
uni.setStorageSync(Report_Data_Time, end_time);
start_time = end_time;
}
if ((end_time - start_time) > diff_time) {
requestData(({
enable
}) => {
uni.setStorageSync(Report_Data_Time, end_time);
if (enable === 1) {
resolve();
}
});
}
})
};
const Report_Status = 'Report_Status';
const requestData = (done) => {
let formData = {
usv: STAT_VERSION,
conf: encodeURIComponent({
ak: statConfig.appid
})
};
uni.request({
url: STAT_URL,
method: 'GET',
data: formData,
success: (res) => {
const {data} = res;
if (data.ret === 0) {
typeof done === 'function' && done({
enable: data.enable
});
}
},
fail: (e) => {
let report_status_code = 1;
try {
report_status_code = uni.getStorageSync(Report_Status);
} catch (e) {
report_status_code = 1;
}
if (report_status_code === 1) {
typeof done === 'function' && done({
enable: res.enable
});
}
// console.error('统计请求错误');
}
});
};
const PagesJson = require('uni-pages?{"type":"style"}').default;
const statConfig = require('uni-stat-config').default || require('uni-stat-config');
const statConfig$1 = require('uni-stat-config').default || require('uni-stat-config');
const resultOptions = uni.getSystemInfoSync();
......@@ -328,7 +396,7 @@ class Util {
uuid: getUuid(),
ut: getPlatformName(),
mpn: getPackName(),
ak: statConfig.appid,
ak: statConfig$1.appid,
usv: STAT_VERSION,
v: getVersion(),
ch: getChannel(),
......@@ -353,6 +421,10 @@ class Util {
}
getIsReportData(){
return isReportData()
}
_applicationShow() {
if (this.__licationHide) {
getLastTime();
......@@ -547,7 +619,7 @@ class Util {
}
getLocation() {
if (statConfig.getLocation) {
if (statConfig$1.getLocation) {
uni.getLocation({
type: 'wgs84',
geocode: true,
......@@ -642,6 +714,7 @@ class Util {
this._sendRequest(optionsData);
}
_sendRequest(optionsData) {
this.getIsReportData().then(()=>{
uni.request({
url: STAT_URL,
method: 'POST',
......@@ -662,6 +735,7 @@ class Util {
}
}
});
});
}
/**
* h5 请求
......@@ -869,7 +943,7 @@ const lifecycle = {
function main() {
if (process.env.NODE_ENV === 'development') {
uni.report = function(type, options) {};
}else{
} else {
const Vue = require('vue');
(Vue.default || Vue).mixin(lifecycle);
uni.report = function(type, options) {
......
......@@ -42,7 +42,7 @@ const lifecycle = {
function main() {
if (process.env.NODE_ENV === 'development') {
uni.report = function(type, options) {};
}else{
} else {
const Vue = require('vue');
(Vue.default || Vue).mixin(lifecycle);
uni.report = function(type, options) {
......
import {
PAGE_PVER_TIME,
APP_PVER_TIME
APP_PVER_TIME,
STAT_URL,
STAT_VERSION
} from './config';
const statConfig = require('uni-stat-config').default || require('uni-stat-config');
const UUID_KEY = '__DC_STAT_UUID';
const UUID_VALUE = '__DC_UUID_VALUE';
......@@ -81,7 +83,7 @@ export const getPackName = () => {
let packName = ''
if (getPlatformName() === 'wx' || getPlatformName() === 'qq') {
// 兼容微信小程序低版本基础库
if(uni.canIUse('getAccountInfoSync')){
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || '';
}
}
......@@ -254,7 +256,7 @@ export const getPageRoute = (self) => {
if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is + str;
} else {
return (_self.$scope && _self.$scope.route + str )|| (_self.$mp && _self.$mp.page.route + str);
return (_self.$scope && _self.$scope.route + str) || (_self.$mp && _self.$mp.page.route + str);
}
};
......@@ -267,7 +269,7 @@ export const getPageTypes = (self) => {
export const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if(!eventName){
if (!eventName) {
console.error(`uni.report 缺少 [eventName] 参数`);
return true
}
......@@ -295,3 +297,70 @@ export const calibration = (eventName, options) => {
return true
}
}
const Report_Data_Time = 'Report_Data_Time'
export const isReportData = () => {
return new Promise((resolve, reject) => {
let start_time = ''
let end_time = new Date().getTime()
let diff_time = 60 * 1000 * 60 * 24
try {
start_time = uni.getStorageSync(Report_Data_Time)
} catch (e) {
start_time = ''
}
if (!start_time) {
uni.setStorageSync(Report_Data_Time, end_time)
start_time = end_time
}
if ((end_time - start_time) > diff_time) {
requestData(({
enable
}) => {
uni.setStorageSync(Report_Data_Time, end_time)
if (enable === 1) {
resolve();
}
});
}
})
}
const Report_Status = 'Report_Status'
const requestData = (done) => {
let formData = {
usv: STAT_VERSION,
conf: encodeURIComponent({
ak: statConfig.appid
})
}
uni.request({
url: STAT_URL,
method: 'GET',
data: formData,
success: (res) => {
const {data} = res
if (data.ret === 0) {
typeof done === 'function' && done({
enable: data.enable
})
}
},
fail: (e) => {
let report_status_code = 1
try {
report_status_code = uni.getStorageSync(Report_Status)
} catch (e) {
report_status_code = 1
}
if (report_status_code === 1) {
typeof done === 'function' && done({
enable: res.enable
})
}
// console.error('统计请求错误');
}
});
}
......@@ -22,7 +22,8 @@ import {
getPageRoute,
getRoute,
getPageTypes,
calibration
calibration,
isReportData
} from './parameter';
import {
......@@ -85,6 +86,10 @@ class Util {
}
getIsReportData(){
return isReportData()
}
_applicationShow() {
if (this.__licationHide) {
getLastTime();
......@@ -374,6 +379,7 @@ class Util {
this._sendRequest(optionsData)
}
_sendRequest(optionsData) {
this.getIsReportData().then(()=>{
uni.request({
url: STAT_URL,
method: 'POST',
......@@ -394,6 +400,7 @@ class Util {
}
}
});
})
}
/**
* h5 请求
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册