diff --git a/packages/uni-stat/dist/uni-cloud-stat.cjs.js b/packages/uni-stat/dist/uni-cloud-stat.cjs.js index 5b4aec43f45bc94188129c1383d4d9f6ef7d40b4..0f628fd908edb83584391ee9fe97752cd228cb9f 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.cjs.js +++ b/packages/uni-stat/dist/uni-cloud-stat.cjs.js @@ -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目录右键关联服务空间' + ); } } } diff --git a/packages/uni-stat/dist/uni-cloud-stat.es.js b/packages/uni-stat/dist/uni-cloud-stat.es.js index a8ac843a56d1a058764232f68a2701038ba13c09..27ec6ed10cdb56090bdbc7564857bb0e099e50bc 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.es.js +++ b/packages/uni-stat/dist/uni-cloud-stat.es.js @@ -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目录右键关联服务空间' + ); } } } diff --git a/packages/uni-stat/dist/uni-stat.cjs.js b/packages/uni-stat/dist/uni-stat.cjs.js index ccc7d3a7a62c811fffe5451b4aca6861e0bb57f9..3a4b61d61c1dc02f4e59effb318a06cb91fa7cd6 100644 --- a/packages/uni-stat/dist/uni-stat.cjs.js +++ b/packages/uni-stat/dist/uni-stat.cjs.js @@ -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); } }); } diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index c053b24bbc6fcc4308196bfd350a7c68c3f7c029..389a66f8cd10c04937f6c664be687b54c80f77fd 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -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); } }); } diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index bfc9046cbfec351c35d52fdbe69052534e19ba59..89c7053cbc1c0f5b15eb4836a5e28d52f2a2989c 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -88,7 +88,9 @@ const plugins = [ RUN_BY_HBUILDERX: process.env.RUN_BY_HBUILDERX, UNI_AUTOMATOR_WS_ENDPOINT: JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT), UNI_STAT_UNI_CLOUD: process.env.UNI_STAT_UNI_CLOUD || '""', - UNI_STAT_DEBUG: process.env.UNI_STAT_DEBUG || '""' + UNI_STATISTICS_CONFIG: process.env.UNI_STATISTICS_CONFIG || '""', + UNI_STAT_DEBUG: process.env.UNI_STAT_DEBUG || '""', + UNI_COMPILER_VERSION: JSON.stringify(process.env.UNI_COMPILER_VERSION) } }), new webpack.BannerPlugin({ diff --git a/packages/vue-cli-plugin-uni/lib/chain-webpack.js b/packages/vue-cli-plugin-uni/lib/chain-webpack.js index ca3ded6c15af6a2933221a6ebd9b4d465e8e0a39..038402d71f470348ffc9f05fdf368afc02c29064 100644 --- a/packages/vue-cli-plugin-uni/lib/chain-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/chain-webpack.js @@ -104,8 +104,9 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { 'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG, 'process.env.RUN_BY_HBUILDERX': process.env.RUN_BY_HBUILDERX, 'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT), - '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, + '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_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION), 'process.env.UNI_APP_VERSION_NAME': JSON.stringify(process.env.UNI_APP_VERSION_NAME), 'process.env.UNI_APP_VERSION_CODE': JSON.stringify(process.env.UNI_APP_VERSION_CODE) diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 45652a277b39b696e71bef519fcf488d362f41f3..a8b151a51f9429fa8ed3c6d104024dff25d52207 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -324,8 +324,9 @@ if ((process.env.UNI_PLATFORM === 'mp-kuaishou' || process.env.UNI_PLATFORM === process.env.MERGE_VIRTUAL_HOST_ATTRIBUTES = (!!platformOptions.mergeVirtualHostAttributes).toString() -process.env.UNI_STAT_UNI_CLOUD = '' -process.env.UNI_STAT_DEBUG = '' +process.env.UNI_STATISTICS_CONFIG = '""' +process.env.UNI_STAT_UNI_CLOUD = '""' +process.env.UNI_STAT_DEBUG = '""' if ( process.env.UNI_USING_COMPONENTS || process.env.UNI_PLATFORM === 'h5' @@ -336,9 +337,10 @@ if ( ) if (uniStatistics.enable === true) { - process.env.UNI_USING_STAT = uniStatistics.version === '2' ? '2' : '1' + process.env.UNI_USING_STAT = Number(uniStatistics.version) === 2 ? '2' : '1' // 获取服务空间配置信息 const uniCloudConfig = uniStatistics.uniCloud || {} + process.env.UNI_STATISTICS_CONFIG = JSON.stringify(uniStatistics) process.env.UNI_STAT_UNI_CLOUD = JSON.stringify(uniCloudConfig) process.env.UNI_STAT_DEBUG = uniStatistics.debug === true ? 'true' : 'false'