//允许分享的页面路由数组 var showShareUrls = [‘pages/index/index‘, //首页 ‘pages/other/aboutUs‘, //关于我们 ]; //无需登录页面 var noLogins = [ ‘pages/my/bind‘, ]; noLogins = noLogins.concat(showShareUrls); ! function () { //获取页面配置并进行页面分享配置 var PageTmp = Page Page = function (pageConfig) { //全局关闭分享 var pageOnLoad = pageConfig.onLoad; var pageOnShow = pageConfig.onShow; pageConfig = Object.assign(pageConfig, { //暂存页面加载事件 pageOnLoad: pageOnLoad, //重写页面加载事件和onShow onLoad: function (options) { var that = this; //获取当前页面路由 let pages = getCurrentPages(); let currPage = null; if (pages.length) { currPage = pages[pages.length - 1]; } // console.log("新onLoad"); //当前页面是否不允许分享 if (!showShareUrls.some(function (url) { return currPage.route.includes(url); })) { //禁止分享 wx.hideShareMenu(); } //执行页面中的加载事件 if (that.pageOnLoad) that.pageOnLoad(options); //为页面的data添加属性 //在线静态图片存放位置 that.setData({ImgDomain:"https://***.***.com"}); }, pageOnShow: pageOnShow, //重写onShow onShow: function (options) { // console.log("新onShow"); var that = this; //获取当前页面路由 let pages = getCurrentPages(); let currPage = null; if (pages.length) { currPage = pages[pages.length - 1]; } if (that.pageOnShow) that.pageOnShow(options); } }); // 配置页面模板执行 PageTmp(pageConfig); } }();