Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 定制化组件修改与小说阅读器的双向事件监听的方案 #1259 #1263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions src/mip-custom/mip-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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);
};

/**
Expand Down Expand Up @@ -277,6 +286,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
Expand Down Expand Up @@ -314,43 +325,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();
Expand All @@ -361,6 +339,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);
}
};

/**
* 缓存异步数据
*
Expand Down