Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
a41a8adf
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a41a8adf
编写于
7月 29, 2022
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(stat): reportInterval
上级
6846cb50
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
225 addition
and
58 deletion
+225
-58
packages/uni-stat/dist/uni-cloud-stat.cjs.js
packages/uni-stat/dist/uni-cloud-stat.cjs.js
+45
-9
packages/uni-stat/dist/uni-cloud-stat.es.js
packages/uni-stat/dist/uni-cloud-stat.es.js
+45
-9
packages/uni-stat/dist/uni-stat.cjs.js
packages/uni-stat/dist/uni-stat.cjs.js
+38
-8
packages/uni-stat/dist/uni-stat.es.js
packages/uni-stat/dist/uni-stat.es.js
+38
-8
packages/uni-stat/lib/uni.plugin.js
packages/uni-stat/lib/uni.plugin.js
+6
-3
packages/uni-stat/src/core/report.js
packages/uni-stat/src/core/report.js
+9
-12
packages/uni-stat/src/core/stat.js
packages/uni-stat/src/core/stat.js
+3
-3
packages/uni-stat/src/plugin/index.ts
packages/uni-stat/src/plugin/index.ts
+7
-5
packages/uni-stat/src/utils/pageInfo.js
packages/uni-stat/src/utils/pageInfo.js
+34
-1
未找到文件。
packages/uni-stat/dist/uni-cloud-stat.cjs.js
浏览文件 @
a41a8adf
...
...
@@ -14,6 +14,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const
OPERATING_TIME
=
10
;
// 数据上报时间 单位s
const
DIFF_TIME
=
60
*
1000
*
60
*
24
;
// 获取 manifest.json 中统计配置
const
uniStatisticsConfig
=
process
.
env
.
UNI_STATISTICS_CONFIG
;
let
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -471,7 +473,8 @@ const is_debug = debug;
* 日志输出
* @param {*} data
*/
const
log
=
(
data
)
=>
{
const
log
=
(
data
,
type
)
=>
{
let
msg_type
=
''
;
switch
(
data
.
lt
)
{
case
'
1
'
:
...
...
@@ -494,11 +497,41 @@ const log = (data) => {
msg_type
=
'
PUSH
'
;
break
}
// #ifdef APP
// 在 app 中,日志转为 字符串
if
(
typeof
data
===
'
object
'
)
{
data
=
JSON
.
stringify
(
data
);
}
// #endif
if
(
type
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
return
}
if
(
msg_type
)
{
console
.
log
(
`=== 统计数据采集:
${
msg_type
}
===`
);
console
.
log
(
data
);
console
.
log
(
`=== 采集结束 ===`
);
}
};
/**
* 获取上报时间间隔
* @param {*} defaultTime 默认上报间隔时间 单位s
*/
const
get_report_Interval
=
(
defaultTime
)
=>
{
let
time
=
uniStatisticsConfig
.
reportInterval
;
// 如果上报时间配置为0 相当于立即上报
if
(
Number
(
time
)
===
0
)
return
0
time
=
time
||
defaultTime
;
let
reg
=
/
(
^
[
1-9
]\d
*$
)
/
;
// 如果不是整数,则默认为上报间隔时间
if
(
!
reg
.
test
(
time
))
return
defaultTime
return
Number
(
time
)
};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
...
...
@@ -672,6 +705,7 @@ const get_residence_time = (type) => {
}
};
const
eport_Interval
=
get_report_Interval
(
OPERATING_TIME
);
// 统计数据默认值
let
statData
=
{
uuid
:
get_uuid
(),
// 设备标识
...
...
@@ -1131,7 +1165,7 @@ class Report {
log
(
data
);
}
// 判断时候到达上报时间 ,默认 10 秒上报
if
(
page_residence_time
<
OPERATING_TIME
&&
!
type
)
return
if
(
page_residence_time
<
eport_Interval
&&
!
type
)
return
// 时间超过,重新获取时间戳
set_page_residence_time
();
...
...
@@ -1167,7 +1201,9 @@ class Report {
sendRequest
(
optionsData
)
{
{
if
(
!
uni
.
__stat_uniCloud_space
)
{
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
);
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
);
return
}
...
...
@@ -1181,9 +1217,7 @@ class Report {
.
report
(
optionsData
)
.
then
(()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
optionsData
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
optionsData
,
true
);
}
})
.
catch
((
err
)
=>
{
...
...
@@ -1204,9 +1238,7 @@ class Report {
let
options
=
get_sgin
(
get_encodeURIComponent_options
(
data
)).
options
;
image
.
src
=
STAT_H5_URL
+
'
?
'
+
options
;
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
data
,
true
);
}
});
}
...
...
@@ -1254,6 +1286,10 @@ class Stat extends Report {
// '=== 当前绑定的统计服务空间spaceId:' +
// uni.__stat_uniCloud_space.config.spaceId
// )
}
else
{
console
.
error
(
'
应用未关联服务空间,请在uniCloud目录右键关联服务空间
'
);
}
}
}
...
...
packages/uni-stat/dist/uni-cloud-stat.es.js
浏览文件 @
a41a8adf
...
...
@@ -12,6 +12,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const
OPERATING_TIME
=
10
;
// 数据上报时间 单位s
const
DIFF_TIME
=
60
*
1000
*
60
*
24
;
// 获取 manifest.json 中统计配置
const
uniStatisticsConfig
=
process
.
env
.
UNI_STATISTICS_CONFIG
;
let
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -469,7 +471,8 @@ const is_debug = debug;
* 日志输出
* @param {*} data
*/
const
log
=
(
data
)
=>
{
const
log
=
(
data
,
type
)
=>
{
let
msg_type
=
''
;
switch
(
data
.
lt
)
{
case
'
1
'
:
...
...
@@ -492,11 +495,41 @@ const log = (data) => {
msg_type
=
'
PUSH
'
;
break
}
// #ifdef APP
// 在 app 中,日志转为 字符串
if
(
typeof
data
===
'
object
'
)
{
data
=
JSON
.
stringify
(
data
);
}
// #endif
if
(
type
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
return
}
if
(
msg_type
)
{
console
.
log
(
`=== 统计数据采集:
${
msg_type
}
===`
);
console
.
log
(
data
);
console
.
log
(
`=== 采集结束 ===`
);
}
};
/**
* 获取上报时间间隔
* @param {*} defaultTime 默认上报间隔时间 单位s
*/
const
get_report_Interval
=
(
defaultTime
)
=>
{
let
time
=
uniStatisticsConfig
.
reportInterval
;
// 如果上报时间配置为0 相当于立即上报
if
(
Number
(
time
)
===
0
)
return
0
time
=
time
||
defaultTime
;
let
reg
=
/
(
^
[
1-9
]\d
*$
)
/
;
// 如果不是整数,则默认为上报间隔时间
if
(
!
reg
.
test
(
time
))
return
defaultTime
return
Number
(
time
)
};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
...
...
@@ -670,6 +703,7 @@ const get_residence_time = (type) => {
}
};
const
eport_Interval
=
get_report_Interval
(
OPERATING_TIME
);
// 统计数据默认值
let
statData
=
{
uuid
:
get_uuid
(),
// 设备标识
...
...
@@ -1129,7 +1163,7 @@ class Report {
log
(
data
);
}
// 判断时候到达上报时间 ,默认 10 秒上报
if
(
page_residence_time
<
OPERATING_TIME
&&
!
type
)
return
if
(
page_residence_time
<
eport_Interval
&&
!
type
)
return
// 时间超过,重新获取时间戳
set_page_residence_time
();
...
...
@@ -1165,7 +1199,9 @@ class Report {
sendRequest
(
optionsData
)
{
{
if
(
!
uni
.
__stat_uniCloud_space
)
{
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
);
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
);
return
}
...
...
@@ -1179,9 +1215,7 @@ class Report {
.
report
(
optionsData
)
.
then
(()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
optionsData
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
optionsData
,
true
);
}
})
.
catch
((
err
)
=>
{
...
...
@@ -1202,9 +1236,7 @@ class Report {
let
options
=
get_sgin
(
get_encodeURIComponent_options
(
data
)).
options
;
image
.
src
=
STAT_H5_URL
+
'
?
'
+
options
;
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
data
,
true
);
}
});
}
...
...
@@ -1252,6 +1284,10 @@ class Stat extends Report {
// '=== 当前绑定的统计服务空间spaceId:' +
// uni.__stat_uniCloud_space.config.spaceId
// )
}
else
{
console
.
error
(
'
应用未关联服务空间,请在uniCloud目录右键关联服务空间
'
);
}
}
}
...
...
packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
a41a8adf
...
...
@@ -14,6 +14,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const
OPERATING_TIME
=
10
;
// 数据上报时间 单位s
const
DIFF_TIME
=
60
*
1000
*
60
*
24
;
// 获取 manifest.json 中统计配置
const
uniStatisticsConfig
=
process
.
env
.
UNI_STATISTICS_CONFIG
;
let
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -450,7 +452,8 @@ const is_debug = debug;
* 日志输出
* @param {*} data
*/
const
log
=
(
data
)
=>
{
const
log
=
(
data
,
type
)
=>
{
let
msg_type
=
''
;
switch
(
data
.
lt
)
{
case
'
1
'
:
...
...
@@ -473,11 +476,41 @@ const log = (data) => {
msg_type
=
'
PUSH
'
;
break
}
// #ifdef APP
// 在 app 中,日志转为 字符串
if
(
typeof
data
===
'
object
'
)
{
data
=
JSON
.
stringify
(
data
);
}
// #endif
if
(
type
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
return
}
if
(
msg_type
)
{
console
.
log
(
`=== 统计数据采集:
${
msg_type
}
===`
);
console
.
log
(
data
);
console
.
log
(
`=== 采集结束 ===`
);
}
};
/**
* 获取上报时间间隔
* @param {*} defaultTime 默认上报间隔时间 单位s
*/
const
get_report_Interval
=
(
defaultTime
)
=>
{
let
time
=
uniStatisticsConfig
.
reportInterval
;
// 如果上报时间配置为0 相当于立即上报
if
(
Number
(
time
)
===
0
)
return
0
time
=
time
||
defaultTime
;
let
reg
=
/
(
^
[
1-9
]\d
*$
)
/
;
// 如果不是整数,则默认为上报间隔时间
if
(
!
reg
.
test
(
time
))
return
defaultTime
return
Number
(
time
)
};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
...
...
@@ -651,6 +684,7 @@ const get_residence_time = (type) => {
}
};
const
eport_Interval
=
get_report_Interval
(
OPERATING_TIME
);
// 统计数据默认值
let
statData
=
{
uuid
:
get_uuid
(),
// 设备标识
...
...
@@ -1117,7 +1151,7 @@ class Report {
log
(
data
);
}
// 判断时候到达上报时间 ,默认 10 秒上报
if
(
page_residence_time
<
OPERATING_TIME
&&
!
type
)
return
if
(
page_residence_time
<
eport_Interval
&&
!
type
)
return
// 时间超过,重新获取时间戳
set_page_residence_time
();
...
...
@@ -1167,9 +1201,7 @@ class Report {
data
:
optionsData
,
success
:
()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
optionsData
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
optionsData
,
true
);
}
},
fail
:
(
e
)
=>
{
...
...
@@ -1197,9 +1229,7 @@ class Report {
let
options
=
get_sgin
(
get_encodeURIComponent_options
(
data
)).
options
;
image
.
src
=
STAT_H5_URL
+
'
?
'
+
options
;
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
data
,
true
);
}
});
}
...
...
packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
a41a8adf
...
...
@@ -12,6 +12,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const
OPERATING_TIME
=
10
;
// 数据上报时间 单位s
const
DIFF_TIME
=
60
*
1000
*
60
*
24
;
// 获取 manifest.json 中统计配置
const
uniStatisticsConfig
=
process
.
env
.
UNI_STATISTICS_CONFIG
;
let
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
};
...
...
@@ -448,7 +450,8 @@ const is_debug = debug;
* 日志输出
* @param {*} data
*/
const
log
=
(
data
)
=>
{
const
log
=
(
data
,
type
)
=>
{
let
msg_type
=
''
;
switch
(
data
.
lt
)
{
case
'
1
'
:
...
...
@@ -471,11 +474,41 @@ const log = (data) => {
msg_type
=
'
PUSH
'
;
break
}
// #ifdef APP
// 在 app 中,日志转为 字符串
if
(
typeof
data
===
'
object
'
)
{
data
=
JSON
.
stringify
(
data
);
}
// #endif
if
(
type
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
return
}
if
(
msg_type
)
{
console
.
log
(
`=== 统计数据采集:
${
msg_type
}
===`
);
console
.
log
(
data
);
console
.
log
(
`=== 采集结束 ===`
);
}
};
/**
* 获取上报时间间隔
* @param {*} defaultTime 默认上报间隔时间 单位s
*/
const
get_report_Interval
=
(
defaultTime
)
=>
{
let
time
=
uniStatisticsConfig
.
reportInterval
;
// 如果上报时间配置为0 相当于立即上报
if
(
Number
(
time
)
===
0
)
return
0
time
=
time
||
defaultTime
;
let
reg
=
/
(
^
[
1-9
]\d
*$
)
/
;
// 如果不是整数,则默认为上报间隔时间
if
(
!
reg
.
test
(
time
))
return
defaultTime
return
Number
(
time
)
};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
...
...
@@ -649,6 +682,7 @@ const get_residence_time = (type) => {
}
};
const
eport_Interval
=
get_report_Interval
(
OPERATING_TIME
);
// 统计数据默认值
let
statData
=
{
uuid
:
get_uuid
(),
// 设备标识
...
...
@@ -1115,7 +1149,7 @@ class Report {
log
(
data
);
}
// 判断时候到达上报时间 ,默认 10 秒上报
if
(
page_residence_time
<
OPERATING_TIME
&&
!
type
)
return
if
(
page_residence_time
<
eport_Interval
&&
!
type
)
return
// 时间超过,重新获取时间戳
set_page_residence_time
();
...
...
@@ -1165,9 +1199,7 @@ class Report {
data
:
optionsData
,
success
:
()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
optionsData
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
optionsData
,
true
);
}
},
fail
:
(
e
)
=>
{
...
...
@@ -1195,9 +1227,7 @@ class Report {
let
options
=
get_sgin
(
get_encodeURIComponent_options
(
data
)).
options
;
image
.
src
=
STAT_H5_URL
+
'
?
'
+
options
;
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
);
console
.
log
(
data
);
console
.
log
(
`=== 上报结束 ===`
);
log
(
data
,
true
);
}
});
}
...
...
packages/uni-stat/lib/uni.plugin.js
浏览文件 @
a41a8adf
...
...
@@ -58,7 +58,9 @@ var index = () => [
isEnable
=
statConfig
.
enable
===
true
;
if
(
isEnable
)
{
const
uniCloudConfig
=
statConfig
.
uniCloud
||
{};
statVersion
=
statConfig
.
version
===
'
2
'
?
'
2
'
:
'
1
'
;
// 获取manifest.json 统计配置,插入环境变量中
process
.
env
.
UNI_STATISTICS_CONFIG
=
JSON
.
stringify
(
statConfig
);
statVersion
=
Number
(
statConfig
.
version
)
===
2
?
'
2
'
:
'
1
'
;
process
.
env
.
UNI_STAT_UNI_CLOUD
=
JSON
.
stringify
(
uniCloudConfig
);
process
.
env
.
UNI_STAT_DEBUG
=
statConfig
.
debug
?
'
true
'
:
'
false
'
;
if
(
process
.
env
.
NODE_ENV
===
'
production
'
)
{
...
...
@@ -91,8 +93,9 @@ var index = () => [
return
{
define
:
{
'
process.env.UNI_STAT_TITLE_JSON
'
:
process
.
env
.
UNI_STAT_TITLE_JSON
,
'
process.env.UNI_STAT_UNI_CLOUD
'
:
process
.
env
.
UNI_STAT_UNI_CLOUD
||
JSON
.
stringify
({}),
'
process.env.UNI_STAT_DEBUG
'
:
process
.
env
.
UNI_STAT_DEBUG
||
'
false
'
,
'
process.env.UNI_STAT_UNI_CLOUD
'
:
process
.
env
.
UNI_STAT_UNI_CLOUD
,
'
process.env.UNI_STAT_DEBUG
'
:
process
.
env
.
UNI_STAT_DEBUG
,
'
process.env.UNI_STATISTICS_CONFIG
'
:
process
.
env
.
UNI_STATISTICS_CONFIG
,
},
};
},
...
...
packages/uni-stat/src/core/report.js
浏览文件 @
a41a8adf
...
...
@@ -29,6 +29,7 @@ import {
get_page_vm
,
is_debug
,
log
,
get_report_Interval
,
}
from
'
../utils/pageInfo.js
'
import
{
sys
}
from
'
../utils/util.js
'
...
...
@@ -41,7 +42,7 @@ import {
}
from
'
../config.ts
'
import
{
dbSet
,
dbGet
,
dbRemove
}
from
'
../utils/db.js
'
const
eport_Interval
=
get_report_Interval
(
OPERATING_TIME
)
// 统计数据默认值
let
statData
=
{
uuid
:
get_uuid
(),
// 设备标识
...
...
@@ -508,7 +509,7 @@ export default class Report {
log
(
data
)
}
// 判断时候到达上报时间 ,默认 10 秒上报
if
(
page_residence_time
<
OPERATING_TIME
&&
!
type
)
return
if
(
page_residence_time
<
eport_Interval
&&
!
type
)
return
// 时间超过,重新获取时间戳
set_page_residence_time
()
...
...
@@ -551,7 +552,9 @@ export default class Report {
sendRequest
(
optionsData
)
{
if
(
__STAT_VERSION__
===
'
2
'
)
{
if
(
!
uni
.
__stat_uniCloud_space
)
{
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
)
console
.
error
(
'
应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.
'
)
return
}
...
...
@@ -565,9 +568,7 @@ export default class Report {
.
report
(
optionsData
)
.
then
(()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
)
console
.
log
(
optionsData
)
console
.
log
(
`=== 上报结束 ===`
)
log
(
optionsData
,
true
)
}
})
.
catch
((
err
)
=>
{
...
...
@@ -586,9 +587,7 @@ export default class Report {
data
:
optionsData
,
success
:
()
=>
{
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
)
console
.
log
(
optionsData
)
console
.
log
(
`=== 上报结束 ===`
)
log
(
optionsData
,
true
)
}
},
fail
:
(
e
)
=>
{
...
...
@@ -616,9 +615,7 @@ export default class Report {
let
options
=
get_sgin
(
get_encodeURIComponent_options
(
data
)).
options
image
.
src
=
STAT_H5_URL
+
'
?
'
+
options
if
(
is_debug
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
)
console
.
log
(
data
)
console
.
log
(
`=== 上报结束 ===`
)
log
(
data
,
true
)
}
})
}
...
...
packages/uni-stat/src/core/stat.js
浏览文件 @
a41a8adf
...
...
@@ -34,9 +34,9 @@ class Stat extends Report {
// uni.__stat_uniCloud_space.config.spaceId
// )
}
else
{
//
console.error(
// '当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!
'
//
)
console
.
error
(
'
应用未关联服务空间,请在uniCloud目录右键关联服务空间
'
)
}
}
}
...
...
packages/uni-stat/src/plugin/index.ts
浏览文件 @
a41a8adf
...
...
@@ -55,8 +55,9 @@ export default () => [
if
(
isEnable
)
{
const
uniCloudConfig
=
statConfig
.
uniCloud
||
{}
statVersion
=
statConfig
.
version
===
'
2
'
?
'
2
'
:
'
1
'
// 获取manifest.json 统计配置,插入环境变量中
process
.
env
.
UNI_STATISTICS_CONFIG
=
JSON
.
stringify
(
statConfig
)
statVersion
=
Number
(
statConfig
.
version
)
===
2
?
'
2
'
:
'
1
'
process
.
env
.
UNI_STAT_UNI_CLOUD
=
JSON
.
stringify
(
uniCloudConfig
)
process
.
env
.
UNI_STAT_DEBUG
=
statConfig
.
debug
?
'
true
'
:
'
false
'
if
(
process
.
env
.
NODE_ENV
===
'
production
'
)
{
...
...
@@ -89,9 +90,10 @@ export default () => [
return
{
define
:
{
'
process.env.UNI_STAT_TITLE_JSON
'
:
process
.
env
.
UNI_STAT_TITLE_JSON
,
'
process.env.UNI_STAT_UNI_CLOUD
'
:
process
.
env
.
UNI_STAT_UNI_CLOUD
||
JSON
.
stringify
({}),
'
process.env.UNI_STAT_DEBUG
'
:
process
.
env
.
UNI_STAT_DEBUG
||
'
false
'
,
'
process.env.UNI_STAT_UNI_CLOUD
'
:
process
.
env
.
UNI_STAT_UNI_CLOUD
,
'
process.env.UNI_STAT_DEBUG
'
:
process
.
env
.
UNI_STAT_DEBUG
,
'
process.env.UNI_STATISTICS_CONFIG
'
:
process
.
env
.
UNI_STATISTICS_CONFIG
,
},
}
},
...
...
packages/uni-stat/src/utils/pageInfo.js
浏览文件 @
a41a8adf
...
...
@@ -2,6 +2,8 @@ import { sys } from './util.js'
import
{
STAT_URL
,
STAT_VERSION
,
DIFF_TIME
}
from
'
../config.ts
'
// 获取 manifest.json 中统计配置
const
uniStatisticsConfig
=
process
.
env
.
UNI_STATISTICS_CONFIG
let
statConfig
=
{
appid
:
process
.
env
.
UNI_APP_ID
,
}
...
...
@@ -478,7 +480,8 @@ export const is_debug = debug
* 日志输出
* @param {*} data
*/
export
const
log
=
(
data
)
=>
{
export
const
log
=
(
data
,
type
)
=>
{
let
msg_type
=
''
switch
(
data
.
lt
)
{
case
'
1
'
:
...
...
@@ -501,9 +504,39 @@ export const log = (data) => {
msg_type
=
'
PUSH
'
break
}
// #ifdef APP
// 在 app 中,日志转为 字符串
if
(
typeof
data
===
'
object
'
)
{
data
=
JSON
.
stringify
(
data
)
}
// #endif
if
(
type
)
{
console
.
log
(
`=== 统计队列数据上报 ===`
)
console
.
log
(
data
)
console
.
log
(
`=== 上报结束 ===`
)
return
}
if
(
msg_type
)
{
console
.
log
(
`=== 统计数据采集:
${
msg_type
}
===`
)
console
.
log
(
data
)
console
.
log
(
`=== 采集结束 ===`
)
}
}
/**
* 获取上报时间间隔
* @param {*} defaultTime 默认上报间隔时间 单位s
*/
export
const
get_report_Interval
=
(
defaultTime
)
=>
{
let
time
=
uniStatisticsConfig
.
reportInterval
// 如果上报时间配置为0 相当于立即上报
if
(
Number
(
time
)
===
0
)
return
0
time
=
time
||
defaultTime
let
reg
=
/
(
^
[
1-9
]\d
*$
)
/
// 如果不是整数,则默认为上报间隔时间
if
(
!
reg
.
test
(
time
))
return
defaultTime
return
Number
(
time
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录