From 1d7a1e521d7a65307d3dfdfe36d7c5fe384d2e73 Mon Sep 17 00:00:00 2001
From: mehaotian <490272692@qq.com>
Date: Wed, 13 Nov 2024 18:41:11 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E8=AE=A1=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B=EF=BC=8C=E6=94=BE=E5=BC=80=E7=BB=9F?=
=?UTF-8?q?=E8=AE=A1=E5=85=A5=E5=8F=A3=EF=BC=8C=E7=BB=9F=E8=AE=A1debug?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BAtrue=20=EF=BC=8C=E5=8F=91=E7=89=88?=
=?UTF-8?q?=E5=90=8E=E5=8F=AF=E5=85=B3=E9=97=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
App.uvue | 68 +++++------
main.uts | 28 ++---
pages.json | 1 +
pages/API/report/report.test.js | 31 +++++
pages/API/report/report.uvue | 110 +++++++++++++++---
uni_modules/uni-stat/plugin.uts | 4 +-
.../uni-stat/utssdk/common/core/report.uts | 2 -
7 files changed, 179 insertions(+), 65 deletions(-)
create mode 100644 pages/API/report/report.test.js
diff --git a/App.uvue b/App.uvue
index e5f89232..d630033f 100644
--- a/App.uvue
+++ b/App.uvue
@@ -49,15 +49,15 @@
// 统计上报 - 应用启动
// #ifdef APP-ANDROID || APP-IOS || WEB
- // uni.report({
- // name: 'uni-app-launch',
- // options: res,
- // success(res_data) {
- // console.log(res_data);
- // }, fail(err) {
- // console.log(err);
- // }
- // })
+ uni.report({
+ name: 'uni-app-launch',
+ options: res,
+ success(res_data) {
+ console.log(res_data);
+ }, fail(err) {
+ console.log(err);
+ }
+ })
// #endif
// #ifdef APP
if (process.env.NODE_ENV !== 'development') { //真机运行可以注释此条件
@@ -90,14 +90,14 @@
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用显示
- // uni.report({
- // name: 'uni-app-show',
- // success(res_data) {
- // console.log(res_data);
- // }, fail(err) {
- // console.log(err);
- // }
- // })
+ uni.report({
+ name: 'uni-app-show',
+ success(res_data) {
+ console.log(res_data);
+ }, fail(err) {
+ console.log(err);
+ }
+ })
// #endif
},
onHide: function () {
@@ -107,14 +107,14 @@
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用进入后台
- // uni.report({
- // name: 'uni-app-hide',
- // success(res) {
- // console.log(res);
- // }, fail(err) {
- // console.log(err);
- // }
- // })
+ uni.report({
+ name: 'uni-app-hide',
+ success(res) {
+ console.log(res);
+ }, fail(err) {
+ console.log(err);
+ }
+ })
// #endif
},
// #ifdef APP-ANDROID
@@ -144,15 +144,15 @@
// console.log('App onError', err)
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用发生错误
- // uni.report({
- // name: 'uni-app-error',
- // options: err,
- // success(res) {
- // console.log(res);
- // }, fail(err) {
- // console.log(err);
- // }
- // })
+ uni.report({
+ name: 'uni-app-error',
+ options: err,
+ success(res) {
+ console.log(res);
+ }, fail(err) {
+ console.log(err);
+ }
+ })
// #endif
},
methods: {
diff --git a/main.uts b/main.uts
index 03df6e0b..3c691bc4 100644
--- a/main.uts
+++ b/main.uts
@@ -1,27 +1,27 @@
// 仅测试 console.log 时机问题
import './test-main-console.uts'
-// // #ifdef APP-ANDROID || APP-IOS || WEB
-// import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
-// // #endif
+// #ifdef APP-ANDROID || APP-IOS || WEB
+import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
+// #endif
import App from './App.uvue'
import { createSSRApp } from 'vue'
-// // 统计配置
-// const uniStatcollectItems = {
-// uniStatPageLog: true
-// }
+// 统计配置
+const uniStatcollectItems = {
+ uniStatPageLog: true
+}
-// const uniStatOptions = {
-// debug: true,
-// collectItems: uniStatcollectItems,
-// }
+const uniStatOptions = {
+ debug: true,
+ collectItems: uniStatcollectItems,
+}
export function createApp() {
const app = createSSRApp(App)
- // // #ifdef APP-ANDROID || APP-IOS || WEB
- // app.use(uniStat, uniStatOptions)
- // // #endif
+ // #ifdef APP-ANDROID || APP-IOS || WEB
+ app.use(uniStat, uniStatOptions)
+ // #endif
// app.mixin({
// onReady() {
// setTimeout(() => {
diff --git a/pages.json b/pages.json
index e1fd969b..7a0a4fe0 100644
--- a/pages.json
+++ b/pages.json
@@ -1218,6 +1218,7 @@
},
{
"path": "pages/API/report/report",
+ "group": "1,17,0",
"style": {
"navigationBarTitleText": "report | 统计采集上报"
}
diff --git a/pages/API/report/report.test.js b/pages/API/report/report.test.js
new file mode 100644
index 00000000..fab75293
--- /dev/null
+++ b/pages/API/report/report.test.js
@@ -0,0 +1,31 @@
+const PAGE_PATH = '/pages/API/report/report'
+const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
+const isAndroid = platformInfo.startsWith('android')
+
+describe('report', () => {
+ let page = null
+ beforeAll(async () => {
+ page = await program.navigateTo(PAGE_PATH)
+ await page.waitFor('view')
+ })
+ it('Report - onLaunch', async () => {
+ await page.callMethod('handleAppLaunch')
+ const msg = await page.data('msg')
+ expect(msg).toBe('onLaunch --> report:ok')
+ })
+ it('Report - onShow', async () => {
+ await page.callMethod('handleAppShow')
+ const msg = await page.data('msg')
+ expect(msg).toBe('onAppShow --> report:ok')
+ })
+ it('Report - onHide', async () => {
+ await page.callMethod('handleAppHide')
+ const msg = await page.data('msg')
+ expect(msg).toBe('onAppHide --> report:ok')
+ })
+ it('Report - onError', async () => {
+ await page.callMethod('handleAppError')
+ const msg = await page.data('msg')
+ expect(msg).toBe('onAppError --> report:ok')
+ })
+})
diff --git a/pages/API/report/report.uvue b/pages/API/report/report.uvue
index 2a940d80..58701501 100644
--- a/pages/API/report/report.uvue
+++ b/pages/API/report/report.uvue
@@ -2,12 +2,30 @@
-
- 当前页面调用API均为模拟,请查看文档,在特定场景下使用以下 API。请在main.uts中设置统计debug配置为true,并点击按钮查控制台输出。
-
-
+
+
+
+ 调用信息:
+ {{msg}}
+
+
+
+
+
+
+
+
+ 当前页面调用API均为模拟,请查看文档,在特定场景下使用以上 API。请在main.uts中设置统计debug配置为true,并点击按钮查控制台输出。
+
+
@@ -18,29 +36,93 @@
export default {
data() {
return {
-
+ msg: '点击按钮,测试上报'
}
},
methods: {
- handleAppLunch() {
- const options = uni.getLaunchOptionsSync()
+ handleAppLaunch() {
+ const options = uni.getLaunchOptionsSync()
uni.report({
name: 'uni-app-launch',
options: options,
- success(data) {
- console.log(data);
- }, fail(err) {
+ success:(res)=> {
+ this.msg = 'onLaunch --> ' + res.errMsg
+ console.log(res);
+ }, fail:(err)=> {
+ this.msg = 'onLaunch --> ' + err.errMsg
console.log(err);
}
})
- }
+ },
+ handleAppHide() {
+ uni.report({
+ name: 'uni-app-hide',
+ success:(res)=> {
+ this.msg = 'onAppHide --> ' + res.errMsg
+ console.log(res);
+ }, fail:(err)=> {
+ this.msg = 'onAppHide --> ' + err.errMsg
+ console.log(err);
+ }
+ })
+ },
+ handleAppShow() {
+ // const options = uni.getLaunchOptionsSync()
+ uni.report({
+ name: 'uni-app-show',
+ success:(res)=> {
+ this.msg = 'onAppShow --> ' + res.errMsg
+ console.log(res);
+ }, fail:(err)=> {
+ this.msg = 'onAppShow --> ' + err.errMsg
+ console.log(err);
+ }
+ })
+ },
+ handleAppError() {
+ const errmsg = '测试错误'
+ uni.report({
+ name: 'uni-app-error',
+ options: errmsg,
+ success:(res)=> {
+ this.msg = 'onAppError --> ' + res.errMsg
+ console.log(res);
+ }, fail:(err)=> {
+ this.msg = 'onAppError --> ' + err.errMsg
+ console.log(err);
+ }
+ })
+ },
}
}
diff --git a/uni_modules/uni-stat/plugin.uts b/uni_modules/uni-stat/plugin.uts
index 809870c2..c95b88bc 100644
--- a/uni_modules/uni-stat/plugin.uts
+++ b/uni_modules/uni-stat/plugin.uts
@@ -11,11 +11,11 @@ const lifecycle = defineMixin({
stat_instance.onLoad(this)
},
// @ts-ignore
- onPageShow() {
+ onShow() {
stat_instance.onShow(this)
},
// @ts-ignore
- onPageHide() {
+ onHide() {
stat_instance.onHide(this)
},
// @ts-ignore
diff --git a/uni_modules/uni-stat/utssdk/common/core/report.uts b/uni_modules/uni-stat/utssdk/common/core/report.uts
index 2c21089b..8f3b5b25 100644
--- a/uni_modules/uni-stat/utssdk/common/core/report.uts
+++ b/uni_modules/uni-stat/utssdk/common/core/report.uts
@@ -291,8 +291,6 @@ export class Report {
}
appError(em : any) {
- console.log('发生了错误123');
- console.log(em);
let errmsg : string
// #ifdef APP-ANDROID
// @ts-ignore
--
GitLab