You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Page扩展函数
|
|
|
|
|
*
|
|
|
|
|
* @param {*} Page 原生Page
|
|
|
|
|
*/
|
|
|
|
|
const pageExtend = Page => {
|
|
|
|
|
return object => {
|
|
|
|
|
|
|
|
|
|
// 导出原生Page传入的object参数中的生命周期函数
|
|
|
|
|
// 由于命名冲突,所以将onLoad生命周期函数命名成了onLoaded
|
|
|
|
|
const {
|
|
|
|
|
onLoad
|
|
|
|
|
} = object
|
|
|
|
|
|
|
|
|
|
// 公共的onLoad生命周期函数
|
|
|
|
|
object.onLoad = function (options) {
|
|
|
|
|
// 在onLoad中执行的代码
|
|
|
|
|
console.log('拦截页面参数:')
|
|
|
|
|
console.log(options)
|
|
|
|
|
|
|
|
|
|
if (options.cps) {
|
|
|
|
|
let cps = wx.getStorageSync("cps") || null
|
|
|
|
|
if (cps == null || options.cps !== cps.value) {
|
|
|
|
|
let vTime = new Date().getTime() + 1000 * 60 * 60 * 24 * 2
|
|
|
|
|
let cps = Object.assign({
|
|
|
|
|
value: options.cps
|
|
|
|
|
}, {
|
|
|
|
|
vTime: vTime
|
|
|
|
|
})
|
|
|
|
|
wx.setStorageSync('cps', cps)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行onLoaded生命周期函数
|
|
|
|
|
if (typeof onLoad === 'function') {
|
|
|
|
|
onLoad.call(this, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Page(object)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取原生Page
|
|
|
|
|
const originalPage = Page
|
|
|
|
|
// 定义一个新的Page,将原生Page传入Page扩展函数
|
|
|
|
|
Page = pageExtend(originalPage)
|