123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- function watermark(settings) {
- //默认设置
- var defaultSettings={
- watermarl_element:"body",
- watermark_txt:"",
- watermark_x:20,//水印起始位置x轴坐标
- watermark_y:20,//水印起始位置Y轴坐标
- watermark_rows:2000,//水印行数
- watermark_cols:2000,//水印列数
- watermark_x_space:70,//水印x轴间隔
- watermark_y_space:30,//水印y轴间隔
- watermark_color:'#aaa',//水印字体颜色
- watermark_alpha:0.4,//水印透明度
- watermark_fontsize:'15px',//水印字体大小
- watermark_font:'微软雅黑',//水印字体
- watermark_width:300,//水印宽度
- watermark_height:200,//水印长度
- watermark_angle:0,//水印倾斜度数
- watermark_num:0
- };
- //采用配置项替换默认值,作用类似jquery.extend
- if(arguments.length===1&&typeof arguments[0] ==="object" )
- {
- var src=arguments[0]||{};
- for(key in src)
- {
- if(src[key]&&defaultSettings[key]&&src[key]===defaultSettings[key])
- continue;
- else if(src[key])
- defaultSettings[key]=src[key];
- }
- }
- var oTemp = document.createDocumentFragment();
- var maskElement = document.getElementById(defaultSettings.watermarl_element) || document.body;
- //获取页面最大宽度
- //var page_width = Math.max(maskElement.scrollWidth,maskElement.clientWidth);
- var page_width = $(window).width();
- //获取页面最大高度
- //var page_height = Math.max(maskElement.scrollHeight, maskElement.clientHeight);
- var page_height = $(window).height();
- //角度
- var watermark_angle = 360 * Math.atan(page_height / page_width) / (2 * Math.PI)
- //水印数量自适应元素区域尺寸
- defaultSettings.watermark_cols=Math.ceil(page_width/(defaultSettings.watermark_x_space+defaultSettings.watermark_width));
- defaultSettings.watermark_rows = Math.ceil(page_height / (defaultSettings.watermark_y_space + defaultSettings.watermark_height));
- var x;
- var y;
- if (defaultSettings.watermark_num == 0) {
- for (var i = 0; i < defaultSettings.watermark_cols - 2; i++) {
- y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
- for (var j = 0; j < defaultSettings.watermark_cols - 1; j++) {
- x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;
- var mask_div = document.createElement('div');
- mask_div.id = 'mask_div' + i + j;
- mask_div.className = 'mask_div';
- //mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
- mask_div.innerHTML = (defaultSettings.watermark_txt);
- //设置水印div倾斜显示
- mask_div.style.webkitTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.MozTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.msTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.OTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.transform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.visibility = "";
- mask_div.style.position = "absolute";
- mask_div.style.left = (x + 50) + 'px';
- mask_div.style.top = (y + 50) + 'px';
- mask_div.style.overflow = "hidden";
- mask_div.style.zIndex = "9999";
- mask_div.style.pointerEvents = 'none';//pointer-events:none 让水印不遮挡页面的点击事件
- //mask_div.style.border="solid #eee 1px"; //兼容IE9以下的透明度设置 mask_div.style.filter="alpha(opacity=50)";
- mask_div.style.opacity = defaultSettings.watermark_alpha;
- mask_div.style.fontSize = defaultSettings.watermark_fontsize;
- mask_div.style.fontFamily = defaultSettings.watermark_font;
- mask_div.style.color = defaultSettings.watermark_color;
- mask_div.style.textAlign = "center";
- mask_div.style.width = defaultSettings.watermark_width + 'px';
- mask_div.style.height = defaultSettings.watermark_height + 'px';
- mask_div.style.paddingTop = "10px";
- mask_div.style.display = "block";
- mask_div.style["word-break"] = "break-all";
- mask_div.style["word-wrap"] = "break-word";
- oTemp.appendChild(mask_div);
- };
- }
- } else {
- var xi = 0, yi = -1, xt = Math.round(window.innerWidth / (defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space)))
- for (var i = 0; i < defaultSettings.watermark_num; i++) {
- xi = i % xt;
- if (xi == 0) {
- yi = yi + 1;
- }
- x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * xi;
- y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * yi;
- var mask_div = document.createElement('div');
- mask_div.id = 'mask_div' + i;
- mask_div.className = 'mask_div';
- //mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
- mask_div.innerHTML = (defaultSettings.watermark_txt);
- //设置水印div倾斜显示
- mask_div.style.webkitTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.MozTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.msTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.OTransform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.transform = "rotate(-" + watermark_angle + "deg)";
- mask_div.style.visibility = "";
- mask_div.style.position = "absolute";
- mask_div.style.left = (x + 50) + 'px';
- mask_div.style.top = (y + 50) + 'px';
- mask_div.style.overflow = "hidden";
- mask_div.style.zIndex = "9999";
- mask_div.style.pointerEvents = 'none';//pointer-events:none 让水印不遮挡页面的点击事件
- //mask_div.style.border="solid #eee 1px"; //兼容IE9以下的透明度设置 mask_div.style.filter="alpha(opacity=50)";
- mask_div.style.opacity = defaultSettings.watermark_alpha;
- mask_div.style.fontSize = defaultSettings.watermark_fontsize;
- mask_div.style.fontFamily = defaultSettings.watermark_font;
- mask_div.style.color = defaultSettings.watermark_color;
- mask_div.style.textAlign = "center";
- mask_div.style.width = defaultSettings.watermark_width + 'px';
- mask_div.style.height = defaultSettings.watermark_height + 'px';
- mask_div.style.paddingTop = "10px";
- mask_div.style.display = "block";
- mask_div.style["word-break"] = "break-all";
- mask_div.style["word-wrap"] = "break-word";
- oTemp.appendChild(mask_div);
- }
- }
- maskElement.appendChild(oTemp);
- }
- $.ajax({
- type: "post",
- url: apiurljs.login + "g2app/dataabase/queryDataByCol",
- contentType: "application/json",
- headers: {
- Authorization: "Bearer " + localStorage.getItem("GlWorkPlatform-AccessToken"),
- },
- dataType: "json",
- data: JSON.stringify({
- data: s4.encryptData_CBC(JSON.stringify({
- tablename: "SHUIYIN",
- colums: "*",
- order: "ID",
- sqlwhere: { SORTID: 1 },
- sqlinwhere: "",
- sqllikewhere: ""
- }))
- }),
- success: (function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- console.log(res)
- if (res.data.length != 0) {
- if (res.data[0].STATUS == "true") {
- watermark({
- "watermarl_element": "app",
- "watermark_txt": s4.encryptData_CBC(res.data[0].CNAME + ($.cookie("GlWorkPlatform-chineseName") != null ? " " + $.cookie("GlWorkPlatform-chineseName") + " " : " ") + sp.myIP()),
- "watermark_width": 300,
- "watermark_height": 200,
- "watermark_num": parseInt(res.data[0].SHULIANG)
- })
- }
- $("head").append("<style> html,body{overflow:hidden !important;}</style>")
- }
- })
- })
|