信达小程序
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.
 
 
 
 

58 lines
1.5 KiB

/**
* 使用方法:
* 1、app.js 引入此文件:const page = require('xx/xx/page);
* 2、app.js onLaunch 的时候 Page = page
*/
const originalComponent = Component;
function component(
config: WechatMiniprogram.Component.Instance<
WechatMiniprogram.Component.DataOption,
WechatMiniprogram.Component.PropertyOption,
WechatMiniprogram.Component.MethodOption,
WechatMiniprogram.Component.BehaviorOption
>,
) {
if (config?.lifetimes?.attached) {
const originalOnAttached = config.lifetimes.attached;
config.lifetimes.attached = function (options) {
setImageParams(this);
getApp().getMenuInfo(this);
if (originalOnAttached) {
originalOnAttached.call(this, options);
}
};
} else {
const originalOnAttached = config.attached;
config.attached = function (options) {
setImageParams(this);
getApp().getMenuInfo(this);
if (originalOnAttached) {
originalOnAttached.call(this, options);
}
};
}
return originalComponent(config);
}
function setImageParams(
currPage: WechatMiniprogram.Component.Instance<
WechatMiniprogram.Component.DataOption,
WechatMiniprogram.Component.PropertyOption,
WechatMiniprogram.Component.MethodOption,
WechatMiniprogram.Component.BehaviorOption
>,
) {
const date = new Date();
const Timestamp = date.getTime();
currPage.setData({
imageUrl: getApp().globalData.imageUrl,
Timestamp,
});
}
export default component;