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.5 KiB
90 lines
2.5 KiB
|
11 months ago
|
/**
|
||
|
|
* 使用方法:
|
||
|
|
* 1、app.js 引入此文件:const page = require('xx/xx/page);
|
||
|
|
* 2、app.js onLaunch 的时候 Page = page
|
||
|
|
*/
|
||
|
|
|
||
|
|
const originalPage = Page;
|
||
|
|
|
||
|
|
function page(config: WechatMiniprogram.Page.Instance<WechatMiniprogram.IAnyObject, WechatMiniprogram.IAnyObject>) {
|
||
|
|
const originalOnLoad = config.onLoad;
|
||
|
|
config.onLoad = function (options) {
|
||
|
|
setImageParams(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) {
|
||
|
|
console.log(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];
|
||
|
|
const url = currentPage.route;
|
||
|
|
const options = currentPage.options;
|
||
|
|
let urlWithArgs = url + "?";
|
||
|
|
for (let key in options) {
|
||
|
|
const value = options[key];
|
||
|
|
urlWithArgs += `${key}=${value}&`;
|
||
|
|
}
|
||
|
|
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1);
|
||
|
|
|
||
|
|
if (url.includes('doctor/pages')) {
|
||
|
|
return {
|
||
|
|
title: "重症肌无力加油站,重拾生活掌控感!",
|
||
|
|
path: "/doctor/pages/d_home/index",
|
||
|
|
// imageUrl: `${getApp().globalData.imageUrl}1/1.png?t=${Timestamp}`,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
title: "重症肌无力加油站,重拾生活掌控感!",
|
||
|
|
path: "/pages/index/index",
|
||
|
|
// imageUrl: `${getApp().globalData.imageUrl}1/1.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: Timestamp,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export default page;
|