feat: 应用级事件页面
parent
997c3dbb7b
commit
6a4ee92619
7
app.js
7
app.js
|
@ -32,6 +32,13 @@ App({
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
wx.onAppShow((res) => {
|
||||
console.log('onAppShow', res);
|
||||
})
|
||||
wx.onAppHide((res) => {
|
||||
console.log('onAppHide', res);
|
||||
})
|
||||
},
|
||||
globalData: {
|
||||
userInfo: null
|
||||
|
|
|
@ -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: {}
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"launchOptions": "获取小程序启动时的参数"
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<import src="../../../common/head.wxml" />
|
||||
<import src="../../../common/foot.wxml" />
|
||||
|
||||
<view class="container">
|
||||
<template is="head" data="{{title: 'getLaunchOptionsSync'}}"/>
|
||||
<view>打开这个页面,将小程序切换到后台,期望wx.onAppHide被正确调用</view>
|
||||
<view>打开这个页面,将小程序切换回前台,期望wx.onAppShow被正确调用</view>
|
||||
<view class="page-body">
|
||||
<view class="page-section">
|
||||
<view class="page-body-info">
|
||||
<view class="page-body-title">{{type}}</view>
|
||||
<block>
|
||||
<view wx:for="{{items}}">
|
||||
<text class="page-body-text">{{item}}: {{launchOptions[item]}}</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<template is="foot" />
|
||||
</view>
|
|
@ -0,0 +1,7 @@
|
|||
.page-body-info {
|
||||
height: 180px;
|
||||
}
|
||||
|
||||
.btn-area {
|
||||
width: 100%;
|
||||
}
|
|
@ -19,7 +19,10 @@ Page({
|
|||
zh: '获取小程序启动参数',
|
||||
url: 'launch-options/launch-options'
|
||||
},
|
||||
|
||||
{
|
||||
zh: '应用级事件',
|
||||
url: 'app-level-event/app-level-event'
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<button type="primary" bindtap="getEnterOptionsSync">小程序本次启动参数</button>
|
||||
<button bindtap="clear">清空</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<template is="foot" />
|
||||
|
|
Loading…
Reference in New Issue