From 6a4ee9261971d04b683bde622233dc5b8d1c31ba Mon Sep 17 00:00:00 2001 From: luqianyu Date: Tue, 8 Dec 2020 10:03:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E7=BA=A7=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 7 +++ pages/API/app-level-event/app-level-event.js | 60 +++++++++++++++++++ .../API/app-level-event/app-level-event.json | 3 + .../API/app-level-event/app-level-event.wxml | 22 +++++++ .../API/app-level-event/app-level-event.wxss | 7 +++ pages/API/index/index.js | 5 +- pages/API/launch-options/launch-options.wxml | 2 +- 7 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 pages/API/app-level-event/app-level-event.js create mode 100644 pages/API/app-level-event/app-level-event.json create mode 100644 pages/API/app-level-event/app-level-event.wxml create mode 100644 pages/API/app-level-event/app-level-event.wxss 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 @@ + + + + +