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.
90 lines
2.3 KiB
90 lines
2.3 KiB
|
5 days ago
|
const originalPage = Page
|
||
|
|
|
||
|
|
const noSharePath: string[] = []
|
||
|
|
|
||
|
|
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'
|
||
|
|
}
|
||
|
|
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 opts = currentPage.options
|
||
|
|
let urlWithArgs = `${url}?`
|
||
|
|
for (const key in opts) {
|
||
|
|
const value = opts[key]
|
||
|
|
urlWithArgs += `${key}=${value}&`
|
||
|
|
}
|
||
|
|
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
|
||
|
|
|
||
|
|
const isNoShare = noSharePath.some((path) => url.includes(path))
|
||
|
|
|
||
|
|
let imageUrl = ''
|
||
|
|
if (isNoShare) {
|
||
|
|
urlWithArgs = 'pages/start/index'
|
||
|
|
imageUrl = `${getApp().globalData.imageUrl}share.png?t=${Timestamp}`
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
title: '校园小程序',
|
||
|
|
path: urlWithArgs,
|
||
|
|
imageUrl,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
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
|