1.需求背景
由于客户系统中的数据比较敏感,避免泄漏出去,故提出禁止复制粘贴的功能(针对各个类型的报表)。
2.实现方案
通过宏资源包的形式实现,针对每个类型报表添加一个宏资源包
以下宏在IE,google,火狐浏览器下测试基本上都可以正常使用
2.1 电子表格宏
非照相机功能制作的报表,可使用宏如下:
类型:ClientSide(客户端宏) 对象:spreadsheetReport 事件:onRender
function main(spreadsheetReport) {
var doc = spreadsheetReport.elemSheetFrame.contentWindow.document;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
带有通过照相机功能实现的报表,可使用宏如下:
类型:ClientSide(客户端宏) 对象:spreadsheetReport 事件:onRender
function main(spreadsheetReport) {
preventContextMenu(spreadsheetReport.elemSheetFrame);
}
function preventContextMenu(iframe) {
var doc = iframe.contentWindow.document;
var list = doc.getElementsByTagName("IFRAME");
for (var i = 0; i < list.length; i++) {
function x(subIFrame) {
preventContextMenu(subIFrame);
subIFrame.onload = function() {
preventContextMenu(subIFrame);
}
};
x(list[i]);
}
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
2.2 灵活分析宏
类型:ClientSide(客户端宏) 对象:simpleReport 事件:onRender
function main(simpleReport, simpleReportContext) {
var div = simpleReport.content;
var doc = div.ownerDocument;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
2.3 组合分析宏
类型:ClientSide(客户端宏) 对象:simpleReport 事件:onRender
function main(simpleReport, simpleReportContext) {
var div = simpleReport.content;
var doc = div.ownerDocument;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
2.4 透视分析宏
类型:ClientSide(客户端宏) 对象:INSIGHT 事件:onRender
function main(insight) {
var div = insight.container;
var doc = div.ownerDocument;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
2.5 多维分析宏
类型:ClientSide(客户端宏) 对象:olapQuery 事件:onRender
function main(olapQuery) {
var div = olapQuery.frameViewContainer;
var doc = div.ownerDocument;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
}
2.6 页面宏
类型:ClientSide(客户端宏) 对象:page 事件:onRenderPage
function main(page, pageContext) {
document.documentElement.oncontextmenu = document.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
document.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
document.ondragstart = function() {
return false; //禁止拖拽
};
var pList = page.dashletList;
for(var i=0;i<pList.length;i++){
var dashletType = pList[i].dashletType;
if(dashletType=="SPREADSHEET_REPORT"){
spreadsheetReport = pList[i].currentPortlet.queryCmd.spreadsheetReport;
spreadsheetReport.onAfterRefresh.subscribe(function(spreadsheetReport) {debugger;
var doc = spreadsheetReport.elemSheetFrame.contentWindow.document;
doc.documentElement.oncontextmenu = doc.body.oncontextmenu = function() {
return false; //禁止鼠标右键
};
doc.onkeydown = function(e) {
var ev = e || window.event;
if (ev && ev.ctrlKey && ev.keyCode == 67) { // Ctrl + C
return false;
}
};
doc.ondragstart = function() {
return false; //禁止拖拽
};
});
}
}
}