|
|
|
|
/**
|
|
|
|
|
* 使用方法:
|
|
|
|
|
* 1、app.js 引入此文件:const page = require('xx/xx/page);
|
|
|
|
|
* 2、app.js onLaunch 的时候 Page = page
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const originalPage = Page
|
|
|
|
|
const noSharePath = ['pages/login/index']
|
|
|
|
|
|
|
|
|
|
function page(config: WechatMiniprogram.Page.Instance<WechatMiniprogram.IAnyObject, WechatMiniprogram.IAnyObject>) {
|
|
|
|
|
const originalOnLoad = config.onLoad
|
|
|
|
|
config.onLoad = function (options) {
|
|
|
|
|
setImageParams(this)
|
|
|
|
|
setNavBar(this)
|
|
|
|
|
|
|
|
|
|
if (originalOnLoad) {
|
|
|
|
|
originalOnLoad.call(this, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const originalOnPageScroll = config.onPageScroll
|
|
|
|
|
config.onPageScroll = function (options): void {
|
|
|
|
|
const scrollTop = options?.scrollTop
|
|
|
|
|
let background = 'transparent'
|
|
|
|
|
if (Number(scrollTop) > 20) {
|
|
|
|
|
background = '#ffffff'
|
|
|
|
|
}
|
|
|
|
|
if (background !== this.data.background) {
|
|
|
|
|
this.setData({
|
|
|
|
|
background,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (originalOnPageScroll) {
|
|
|
|
|
originalOnPageScroll.call(this, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const originalOnShareAppMessage = config.onShareAppMessage
|
|
|
|
|
config.onShareAppMessage = function (options) {
|
|
|
|
|
if (originalOnShareAppMessage) {
|
|
|
|
|
return originalOnShareAppMessage.call(this, options)
|
|
|
|
|
} else {
|
|
|
|
|
const date = new Date()
|
|
|
|
|
const Timestamp = date.getTime()
|
|
|
|
|
|
|
|
|
|
const pages = getCurrentPages()
|
|
|
|
|
const currentPage = pages[pages.length - 1]
|
|
|
|
|
let url = currentPage.route
|
|
|
|
|
const options = currentPage.options
|
|
|
|
|
let urlWithArgs = `${url}?`
|
|
|
|
|
for (const key in options) {
|
|
|
|
|
const value = options[key]
|
|
|
|
|
urlWithArgs += `${key}=${value}&`
|
|
|
|
|
}
|
|
|
|
|
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
|
|
|
|
|
|
|
|
|
|
const isNoShare = noSharePath.some((path) => {
|
|
|
|
|
return url.includes(path)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (isNoShare) {
|
|
|
|
|
url = 'pages/start/index'
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
title: 'TED规范化诊治中心',
|
|
|
|
|
path: url,
|
|
|
|
|
imageUrl: `${getApp().globalData.imageUrl}share.png?t=${Timestamp}`,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config.handleMakePhoneCall = function () {
|
|
|
|
|
wx.makePhoneCall({
|
|
|
|
|
phoneNumber: '4008102299',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return originalPage(config)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setImageParams(
|
|
|
|
|
currPage: WechatMiniprogram.Page.Instance<WechatMiniprogram.IAnyObject, WechatMiniprogram.IAnyObject>,
|
|
|
|
|
) {
|
|
|
|
|
const date = new Date()
|
|
|
|
|
const Timestamp = date.getTime()
|
|
|
|
|
currPage.setData({
|
|
|
|
|
imageUrl: getApp().globalData.imageUrl,
|
|
|
|
|
Timestamp,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setNavBar(
|
|
|
|
|
currPage: WechatMiniprogram.Page.Instance<WechatMiniprogram.IAnyObject, WechatMiniprogram.IAnyObject>,
|
|
|
|
|
) {
|
|
|
|
|
currPage.setData({
|
|
|
|
|
background: 'transparent',
|
|
|
|
|
pageTop: wx.getMenuButtonBoundingClientRect().bottom,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default page
|