diff --git a/app.js b/app.js
index b545190..61317bc 100644
--- a/app.js
+++ b/app.js
@@ -32,6 +32,13 @@ App({
}
}
})
+
+ wx.onAppShow((res) => {
+ console.log('onAppShow', res);
+ })
+ wx.onAppHide((res) => {
+ console.log('onAppHide', res);
+ })
},
globalData: {
userInfo: null
diff --git a/pages/API/app-level-event/app-level-event.js b/pages/API/app-level-event/app-level-event.js
new file mode 100644
index 0000000..be36723
--- /dev/null
+++ b/pages/API/app-level-event/app-level-event.js
@@ -0,0 +1,60 @@
+Page({
+
+ data: {
+ type: 'unset',
+ launchOptions: {},
+ items: [
+ 'path', 'scene', 'query', 'shareTicket', 'referrerInfo',
+ ],
+ },
+
+ created() {
+ const that = this;
+ wx.onAppShow((res) => {
+ console.log('wx.onAppShow', res);
+ that.setData({
+ launchOptions: res,
+ type: 'onAppShow'
+ })
+ })
+ wx.onAppHide((res) => {
+ console.log('wx.onAppHide', res);
+ that.setData({
+ launchOptions: {},
+ type: 'onAppHide'
+ })
+ })
+ },
+
+ getLaunchOptions() {
+ const that = this
+ const result = wx.getLaunchOptionsSync()
+ console.log('wx.getLaunchOptionsSync', result)
+ for(const key in result) {
+ if(typeof result[key] === 'object') {
+ result[key] = JSON.stringify(result[key])
+ }
+ }
+ that.setData({
+ launchOptions: result
+ })
+ },
+ getEnterOptionsSync() {
+ const that = this
+ const result = wx.getEnterOptionsSync()
+ console.log('wx.getEnterOptionsSync', result)
+ for(const key in result) {
+ if(typeof result[key] === 'object') {
+ result[key] = JSON.stringify(result[key])
+ }
+ }
+ that.setData({
+ launchOptions: result
+ })
+ },
+ clear() {
+ this.setData({
+ launchOptions: {}
+ })
+ }
+})
diff --git a/pages/API/app-level-event/app-level-event.json b/pages/API/app-level-event/app-level-event.json
new file mode 100644
index 0000000..507e012
--- /dev/null
+++ b/pages/API/app-level-event/app-level-event.json
@@ -0,0 +1,3 @@
+{
+ "launchOptions": "获取小程序启动时的参数"
+}
diff --git a/pages/API/app-level-event/app-level-event.wxml b/pages/API/app-level-event/app-level-event.wxml
new file mode 100644
index 0000000..6bd620b
--- /dev/null
+++ b/pages/API/app-level-event/app-level-event.wxml
@@ -0,0 +1,22 @@
+
+
+
+
+
+ 打开这个页面,将小程序切换到后台,期望wx.onAppHide被正确调用
+ 打开这个页面,将小程序切换回前台,期望wx.onAppShow被正确调用
+
+
+
+ {{type}}
+
+
+ {{item}}: {{launchOptions[item]}}
+
+
+
+
+
+
+
+
diff --git a/pages/API/app-level-event/app-level-event.wxss b/pages/API/app-level-event/app-level-event.wxss
new file mode 100644
index 0000000..2860688
--- /dev/null
+++ b/pages/API/app-level-event/app-level-event.wxss
@@ -0,0 +1,7 @@
+.page-body-info {
+ height: 180px;
+}
+
+.btn-area {
+ width: 100%;
+}
diff --git a/pages/API/index/index.js b/pages/API/index/index.js
index 7a41505..eeaec94 100644
--- a/pages/API/index/index.js
+++ b/pages/API/index/index.js
@@ -19,7 +19,10 @@ Page({
zh: '获取小程序启动参数',
url: 'launch-options/launch-options'
},
-
+ {
+ zh: '应用级事件',
+ url: 'app-level-event/app-level-event'
+ },
],
},
{
diff --git a/pages/API/launch-options/launch-options.wxml b/pages/API/launch-options/launch-options.wxml
index b122e1c..2e2d5fd 100644
--- a/pages/API/launch-options/launch-options.wxml
+++ b/pages/API/launch-options/launch-options.wxml
@@ -19,7 +19,7 @@
-
+