pal画布界面去掉浏览、下载监听
This commit is contained in:
parent
c2540118d3
commit
78ff42c8d2
@ -662,147 +662,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 页面停留时间统计
|
|
||||||
class PageStayTimeTracker {
|
|
||||||
constructor() {
|
|
||||||
this.startTime = null;
|
|
||||||
this.lastReportTime = null;
|
|
||||||
this.reportInterval = 60000; // 60秒报告一次
|
|
||||||
this.isPageVisible = true; // 默认页面是可见的
|
|
||||||
this.visibilityBound = false; // 是否已绑定可见性事件
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 延迟绑定可见性事件
|
|
||||||
bindVisibilityEvents() {
|
|
||||||
if (this.visibilityBound) return;
|
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
||||||
this.visibilityBound = true;
|
|
||||||
|
|
||||||
// 初始检查页面可见状态
|
|
||||||
this.isPageVisible = !document.hidden;
|
|
||||||
if (!this.isPageVisible) {
|
|
||||||
this.lastReportTime = new Date(); // 更新最后记录时间
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 开始跟踪
|
|
||||||
startTracking() {
|
|
||||||
if (this.isActive) return;
|
|
||||||
|
|
||||||
this.startTime = new Date();
|
|
||||||
this.lastReportTime = this.startTime;
|
|
||||||
this.isActive = true;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 设置定时器
|
|
||||||
this.intervalId = setInterval(() => {
|
|
||||||
if (this.isPageVisible) {
|
|
||||||
this.reportStayTime();
|
|
||||||
}
|
|
||||||
}, this.reportInterval);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 页面卸载前发送剩余时间
|
|
||||||
window.addEventListener('beforeunload', this.finalReport.bind(this));
|
|
||||||
|
|
||||||
|
|
||||||
// 延迟绑定可见性事件(在用户首次交互后)
|
|
||||||
const bindOnInteraction = () => {
|
|
||||||
this.bindVisibilityEvents();
|
|
||||||
// 移除所有交互监听器
|
|
||||||
['click', 'scroll', 'keydown', 'mousemove', 'touchstart'].forEach(event => {
|
|
||||||
window.removeEventListener(event, bindOnInteraction);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 添加多种交互监听
|
|
||||||
['click', 'scroll', 'keydown', 'mousemove', 'touchstart'].forEach(event => {
|
|
||||||
window.addEventListener(event, bindOnInteraction, { once: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 报告停留时间
|
|
||||||
reportStayTime() {
|
|
||||||
const now = new Date();
|
|
||||||
const elapsed = now - this.lastReportTime;
|
|
||||||
this.totalStayTime += elapsed;
|
|
||||||
this.lastReportTime = now;
|
|
||||||
|
|
||||||
this.sendStayTimeToServer(elapsed, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 最终报告
|
|
||||||
finalReport() {
|
|
||||||
if (!this.isActive) return;
|
|
||||||
if (this.isPageVisible) {
|
|
||||||
const now = new Date();
|
|
||||||
const elapsed = now - this.lastReportTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.sendStayTimeToServer(elapsed, false);
|
|
||||||
this.cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理页面可见性变化
|
|
||||||
handleVisibilityChange() {
|
|
||||||
var now = new Date();
|
|
||||||
if (document.hidden) {
|
|
||||||
if (this.isPageVisible) {
|
|
||||||
this.isPageVisible = false;
|
|
||||||
// 页面不可见,暂停计时
|
|
||||||
const now = new Date();
|
|
||||||
const elapsed = now - this.lastReportTime;
|
|
||||||
this.totalStayTime += elapsed;
|
|
||||||
this.sendStayTimeToServer(elapsed, false);
|
|
||||||
clearInterval(this.intervalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// 页面恢复可见
|
|
||||||
if (!this.isPageVisible) {
|
|
||||||
this.lastReportTime = now; // 重置最后记录时间
|
|
||||||
}
|
|
||||||
this.isPageVisible = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送数据到服务器
|
|
||||||
sendStayTimeToServer(elapsedMs,isActive) {
|
|
||||||
$.ajax({
|
|
||||||
type : "POST",
|
|
||||||
url : "./w?sid=" + encodeURIComponent($('#sid').val()) + "&cmd=com.awspaas.user.apps.browsing_data.service.insertReadingLog",
|
|
||||||
data : "userId="+userId+"&userName="+userName+"&ruuid="+ruuid+"&fileName="+fileName+"&startTime="+new Date(this.startTime).getTime()+"¤tTime="+new Date().getTime()+"&browserId="+browserId+"&isActive="+isActive,
|
|
||||||
success : function(msg) {
|
|
||||||
if (msg.result == "error") {
|
|
||||||
$.simpleAlert("新增失败", "error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理资源
|
|
||||||
cleanUp() {
|
|
||||||
clearInterval(this.intervalId);
|
|
||||||
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
|
|
||||||
window.removeEventListener('beforeunload', this.finalReport);
|
|
||||||
this.isActive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例
|
|
||||||
const tracker = new PageStayTimeTracker();
|
|
||||||
tracker.startTracking();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -455,38 +455,6 @@ function delFileAll(callback) { //删除全部文件
|
|||||||
function downloadFile(url,type) {
|
function downloadFile(url,type) {
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
|
|
||||||
var downloadsource;
|
|
||||||
if(type=='s'){
|
|
||||||
downloadsource="数据属性";
|
|
||||||
}else{
|
|
||||||
downloadsource="文件属性";
|
|
||||||
}
|
|
||||||
var queryString = url.split('?')[1];
|
|
||||||
var params = new URLSearchParams(queryString);
|
|
||||||
var fileName = params.get('fileName');
|
|
||||||
var fileExtension = fileName.substring(fileName.lastIndexOf('.')+1);
|
|
||||||
var subFileName=fileName.substring(0,fileName.lastIndexOf("."));
|
|
||||||
|
|
||||||
var params = {
|
|
||||||
"modelId": pl_uuid,
|
|
||||||
"modelName": parent.fileName,
|
|
||||||
"downloadType": fileExtension,
|
|
||||||
"fileName":subFileName,
|
|
||||||
"recordSource": "PAL画布-附件下载",
|
|
||||||
"downloadsource": downloadsource
|
|
||||||
}
|
|
||||||
jQuery.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.awspaas.user.apps.browsing_data.service.downloadRecord",
|
|
||||||
data: params,
|
|
||||||
success: function(msg) {
|
|
||||||
$.simpleAlert("close");
|
|
||||||
|
|
||||||
},
|
|
||||||
err: function(msg) {
|
|
||||||
$.simpleAlert("close");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user