From d1157a775f5fb12827b8a3e2b208955d7dc92074 Mon Sep 17 00:00:00 2001 From: Espoir-L <413308430@qq.com> Date: Tue, 18 Sep 2018 14:04:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20mip-ad-ecom=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=9B=BA=E5=AE=9A=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mip-ad-ecom/mip-ad-ecom.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mip-ad-ecom/mip-ad-ecom.less b/src/mip-ad-ecom/mip-ad-ecom.less index a9909f320..5c5ab67e3 100644 --- a/src/mip-ad-ecom/mip-ad-ecom.less +++ b/src/mip-ad-ecom/mip-ad-ecom.less @@ -7,7 +7,7 @@ mip-ad-ecom { background-color: #fff; font-size: 14px; - min-height: 343px; + // min-height: 343px; /*由于广告定高,图片内容栅格布局,为适配大屏增加宽度限制*/ max-width: 414px; [mip-ad-ecom-container] { From fc3e7fdc5573750357b52a679f74836fd5e1ec13 Mon Sep 17 00:00:00 2001 From: Espoir-L <413308430@qq.com> Date: Thu, 11 Oct 2018 14:51:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=AE=9A=E5=88=B6=E5=8C=96?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=BF=AE=E6=94=B9=E4=B8=8E=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E7=9A=84=E5=8F=8C=E5=90=91=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9B=91=E5=90=AC=E7=9A=84=E6=96=B9=E6=A1=88=20#1259?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mip-custom/mip-custom.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/mip-custom/mip-custom.js b/src/mip-custom/mip-custom.js index 538c79390..a09bd4a62 100644 --- a/src/mip-custom/mip-custom.js +++ b/src/mip-custom/mip-custom.js @@ -65,22 +65,32 @@ define(function () { dom.addPlaceholder.apply(this); // 判断是否是MIP2的环境,配合小说shell,由小说shell去控制custom的请求是否发送 if (window.MIP.version && +window.MIP.version === 2) { - // 监听小说shell播放的广告请求的事件 - window.addEventListener('showAdvertising', handler); - // 当小说shell优先加载时——向小说shell发送custom已经ready的状态以方便后续事件的执行 - var shellWindow = window.MIP.viewer.page.isRootPage ? window : window.parent; - window.MIP.viewer.page.emitCustomEvent(shellWindow, false, { - name: 'customReady', - data: { - customPageId: window.MIP.viewer.page.currentPageId - } - }) + var currentWindow = getCurrentWindow(); + var isRootPage = currentWindow.MIP.viewer.page.isRootPage; + var rootWindow = isRootPage ? window : window.parent; + if (rootWindow.MIP.mipshellXiaoshuo != null) { + // 监听小说shell播放的广告请求的事件 + window.addEventListener('showAdvertising', handler); + } + else { + this.initElement(dom) + } } else { this.initElement(dom) } }; + /** + * 在MIP2的小说中会涉及不到不同的window,需要获取当前页的window + * + */ + function getCurrentWindow () { + let pageId = window.MIP.viewer.page.currentPageId + let pageInfo = window.MIP.viewer.page.getPageById(pageId) + return pageInfo.targetWindow + } + /** * 发出请求+渲染页面 * From efc0afe4173f717e45ccfffe61e457cf04b40f90 Mon Sep 17 00:00:00 2001 From: Espoir-L <413308430@qq.com> Date: Thu, 11 Oct 2018 16:07:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=AE=9A=E5=88=B6=E5=8C=96?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=BF=AE=E6=94=B9=E4=B8=8E=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E7=9A=84=E5=8F=8C=E5=90=91=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9B=91=E5=90=AC=E7=9A=84=E6=96=B9=E6=A1=88=20#1259?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mip-custom/mip-custom.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mip-custom/mip-custom.js b/src/mip-custom/mip-custom.js index a09bd4a62..f7623b35f 100644 --- a/src/mip-custom/mip-custom.js +++ b/src/mip-custom/mip-custom.js @@ -86,8 +86,8 @@ define(function () { * */ function getCurrentWindow () { - let pageId = window.MIP.viewer.page.currentPageId - let pageInfo = window.MIP.viewer.page.getPageById(pageId) + var pageId = window.MIP.viewer.page.currentPageId; + var pageInfo = window.MIP.viewer.page.getPageById(pageId); return pageInfo.targetWindow } @@ -287,6 +287,8 @@ define(function () { var performance = {}; performance.fetchStart = new Date() - 0; var paramUrl = url + + // 小说的特殊参数——novelData和fromSearch if (me.novelData) { var novelData = encodeURIComponent(JSON.stringify(me.novelData)) paramUrl = paramUrl + '&novelData=' + novelData From 491269af6708de293fe06329a8b54d82196b0d7f Mon Sep 17 00:00:00 2001 From: Espoir-L <413308430@qq.com> Date: Mon, 15 Oct 2018 15:58:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E5=AE=9A=E5=88=B6=E5=8C=96?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=BF=AE=E6=94=B9=E4=B8=8E=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E7=9A=84=E5=8F=8C=E5=90=91=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9B=91=E5=90=AC=E7=9A=84=E6=96=B9=E6=A1=88=20#1259?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mip-custom/mip-custom.js | 95 ++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/src/mip-custom/mip-custom.js b/src/mip-custom/mip-custom.js index f7623b35f..3ae5d9c8a 100644 --- a/src/mip-custom/mip-custom.js +++ b/src/mip-custom/mip-custom.js @@ -68,13 +68,15 @@ define(function () { var currentWindow = getCurrentWindow(); var isRootPage = currentWindow.MIP.viewer.page.isRootPage; var rootWindow = isRootPage ? window : window.parent; - if (rootWindow.MIP.mipshellXiaoshuo != null) { - // 监听小说shell播放的广告请求的事件 - window.addEventListener('showAdvertising', handler); - } - else { - this.initElement(dom) - } + window.addEventListener('mipShellReady', function () { + if (window.MIP.mipshellXiaoshuo != null) { + // 监听小说shell播放的广告请求的事件 + window.addEventListener('showAdvertising', handler); + } + else { + this.initElement(dom) + } + }); } else { this.initElement(dom) @@ -222,6 +224,15 @@ define(function () { // dom 渲染 dom.render(element, tplData, container); } + + // 广告插入页面时,增加渐显效果 + var mipCustomContainers = document.querySelectorAll('[mip-custom-container]'); + for (var i = mipCustomContainers.length - 1; i >= 0; i--) { + var mipCustomContainer = mipCustomContainers[i]; + mipCustomContainer.classList.add('fadein'); + } + // 移除广告占位符号 + dom.removePlaceholder.apply(this); }; /** @@ -326,43 +337,10 @@ define(function () { me.element.remove(); return; } - + // 模板的前端渲染 callback && callback(data.data, element); - // 广告插入页面时,增加渐显效果 - var mipCustomContainers = document.querySelectorAll('[mip-custom-container]'); - for (var i = mipCustomContainers.length - 1; i >= 0; i--) { - var mipCustomContainer = mipCustomContainers[i]; - mipCustomContainer.classList.add('fadein'); - } - // 性能日志:按照流量 1/500 发送日志 - var random500 = Math.random() * 500; - if (random500 < 1) { - // 性能日志:emptyTime-广告未显示时间 - performance.renderEnd = new Date() - 0; // 渲染结束时间戳 - performance.emptyTime = performance.renderEnd - performance.fetchStart; // 页面空白毫秒数 - performance.frontendRender = performance.renderEnd - performance.responseEnd; - - // 前端打点时间 - var frontendData = { - duration: performance.duration, - emptyTime: performance.emptyTime, - frontendRender: performance.frontendRender - }; - // 加入后端打点时间 - var frontAndServerData; - if (data.data.responseTime) { - frontAndServerData = util.fn.extend(frontendData, data.data.responseTime); - } - else { - frontAndServerData = frontendData; - } - // 加入默认统计参数 - performanceData.params.info = JSON.stringify(util.fn.extend(performanceData.params.info, frontAndServerData, 1)); - log.sendLog(performanceData.host, performanceData.params); - } - - dom.removePlaceholder.apply(me); + me.setPerformanceLogs(performance); }, function (error) { log.sendLog(logData.host, util.fn.extend(logData.error, logData.params, errorData)); me.element.remove(); @@ -373,6 +351,39 @@ define(function () { }); }; + /** + * 性能日志:按照流量 1/500 发送日志 + * + * @param {Object} performance 性能参数 + */ + customElement.prototype.setPerformanceLogs = function (performance) { + var random500 = Math.random() * 500; + if (random500 < 1) { + // 性能日志:emptyTime-广告未显示时间 + performance.renderEnd = new Date() - 0; // 渲染结束时间戳 + performance.emptyTime = performance.renderEnd - performance.fetchStart; // 页面空白毫秒数 + performance.frontendRender = performance.renderEnd - performance.responseEnd; + + // 前端打点时间 + var frontendData = { + duration: performance.duration, + emptyTime: performance.emptyTime, + frontendRender: performance.frontendRender + }; + // 加入后端打点时间 + var frontAndServerData; + if (data.data.responseTime) { + frontAndServerData = util.fn.extend(frontendData, data.data.responseTime); + } + else { + frontAndServerData = frontendData; + } + // 加入默认统计参数 + performanceData.params.info = JSON.stringify(util.fn.extend(performanceData.params.info, frontAndServerData, 1)); + log.sendLog(performanceData.host, performanceData.params); + } + }; + /** * 缓存异步数据 *