You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 组件pageLifetimes处理需在页面生命周期里调用
* @param {Object} node
* @param {Object} lifeName
*/
function handlePageLifetime(node, lifeName) {
node.$children.map(child => {
if (typeof child[lifeName] == 'function') child[lifeName]()
handlePageLifetime(child, lifeName)
})
}
export const pageLifetimes = {
onLoad() {
// uni.onWindowResize(CALLBACK) 监听窗口尺寸变化事件
// 平台差异说明
// App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序 飞书小程序 QQ小程序
// √ √ √ x x x √ √
// #ifdef H5 || MP-LARK || MP-QQ
uni.onWindowResize((res) => {
handlePageLifetime(this, "handlePageResize")
})
// #endif
},
onShow() {
handlePageLifetime(this, "handlePageShow")
},
onHide() {
handlePageLifetime(this, "handlePageHide")
},
onResize() {
//onResize 监听窗口尺寸变化 App、微信小程序、快手小程序
// #ifdef APP || MP-WEIXIN || MP-KUAISHOU
handlePageLifetime(this, "handlePageResize")
// #endif
}
};