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 @@ + + + + +