// wisprint地址 function getWisPrintUrl() { var url = document.location.toString(); var arrUrl = url.split("//"); return arrUrl[0]+"//"+document.domain+'/wisprint'; } // moreCloud地址 function getMoreCloudUrl() { return 'https://cloud.morewis.com/web/login'; } // N-TALK用户签名串地址 function getUserSignature() { // return 'https://sntalk.morewiscloud.com/gateway'; return "https://ntalk.morewiscloud.com/gateway"; } //防注入替换 function checkData(v) { var entry = { "'": ''', '"': '"', '<': '<', '>': '>' }; if (v) { v = v.replace(/(['")-><&\\\/\.])/g, function ($0) { return entry[$0] || $0; }); } return v; } /*单双 引号 转义*/ function escapeHTML(str) { if (str != null && str.length > 0) { return str.replace(/"/g, '"').replace(/'/g, '''); } else { return str; } } // 加载 var mcLoad = { isShow: false, text: 'Loading...', show(text) { this.toggle(true, text) }, hide(text) { this.toggle(false, text) }, toggle(flag, text = this.text, hasTop = true) { var target = hasTop ? top.document : document var dom = $(target.body).find('.mc-shade.mc-load') const isFirst = !dom.length // 渲染加载容器 if (!dom.length) { let html = `
` $(target.body).append(html) dom = $(target.body).find('.mc-shade.mc-load') } // 渲染加载文字 if (text !== this.text || isFirst) { this.text = text dom.find('.k-letter-holder') .empty() .append( text .split('') .map((v, i) => `
${v}
`) .join('') ) } this.isShow = flag === undefined ? !this.isShow : flag dom.toggle(this.isShow) }, // 切换方法 在保存中使用 toggleFn(fn, text = this.text) { this.show(text) // 重绘过程会被阻塞 setTimeout(() => { this.toggle(fn(), text) }) } } /** * 数据反转义 * @method getAntisenseInfo * @param text 数据 * @param isEscape 是否单双引号转义,默认为是 * @author wzy 2020-05-29 * 如: '=》. */ function getAntisenseInfo(text, isEscape = 1) { var temp = document.createElement('div'); temp.innerHTML = text; var output = temp.innerText || temp.textContent; temp = null; if (isEscape == 1) { output = escapeHTML(output); } return output; } /** * 数据转义 * @method getEscapeInfo * @param html 数据 * @author wzy 2020-05-29 * 如:. =》 ' */ function getEscapeInfo(html) { var temp = document.createElement('div'); temp.textContent != null ? (temp.textContent = html) : (temp.innerText = html); var output = temp.innerHTML; temp = null; return output; } //获取根目录(工程名) var getProjectName = function () { var pathName = window.document.location.pathname; var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); return projectName; }; // 获取url地址参数方法 function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (pair[0] == variable) { return pair[1]; } } return false; } /** * @function: 数组去重 * @param {Array} arr * @return {Array} */ function arrRemoveRepeat(arr) { return Array.from(new Set([...arr])); } /** * @function 提示 * @description 初始化提示 * @version 1.0.0 */ function initTooltip() { // 添加提示容器 if (!document.getElementsByClassName('com-tooltip-content').length) { document.body.insertAdjacentHTML( 'beforeend', '' ); } // 获取页面上需要提示的节点 // var dom = document.getElementsByClassName('com-tooltip'); var dom = document.querySelectorAll('[data-tooltip]'); for (var i = 0, l = dom.length; i < l; ++i) { dom[i].style.cursor = 'pointer'; dom[i].addEventListener('mousemove', function (e) { // 获取当前节点的信息 var { top, left, width, height } = this.getBoundingClientRect(); // 获取当前body的位置 防止滚动后提示位置错误 var { top: bodyTop, left: bodyLeft } = document.body.getBoundingClientRect(); var tooltip = document.getElementsByClassName('com-tooltip-content')[0]; tooltip.innerText = this.dataset.tooltip; tooltip.style.opacity = 1; tooltip.style.display = 'block'; // 获取当前赋值后提示宽度 var tooltipWidth = parseInt(window.getComputedStyle(tooltip).width); tooltip.style.top = top + height - bodyTop + 'px'; var tooltipLeft = left - (tooltipWidth - width) / 2 - bodyLeft; // 如果提示超出屏幕则为0 tooltipLeft = tooltipLeft < 0 ? 0 : tooltipLeft; tooltip.style.left = tooltipLeft + 'px'; }); dom[i].addEventListener('mouseleave', function (e) { var tooltip = document.getElementsByClassName('com-tooltip-content')[0]; tooltip.style.display = 'none'; tooltip.style.opacity = 0; }); } } // 打开标签页 function judgIsOpen(title, url, id = Date.parse(new Date())) { var flag = true; $(window.parent.document) .find('#tag1') .siblings() .each(function (seq, item) { //打开过的标签不再重复打开 if (title == $(item).attr('title')) { var count = item.id.substring(3); $(window.parent.document) .find('#iframe' + count) .attr('src', url); top.switchTag(item.id, 'content' + count, url); flag = false; return; } }); if (flag) { showPopWinFp(url, 800, 400, null, title, id, 1); } } /** * @function 弹窗提示 * @param msg {String} 提示信息 * @param option {Object} 可选值 * @param option.status {String} 弹窗状态 1:成功 2:失败 3:警告 默认为成功 * @param option.animate {Boolean} 是否开启动画 * @param option.confirm {Function} 确定回调 * @param option.confirmText {Function} 确定按钮内文字 * @param option.cancel {Function} 取消回调,有回调才会显示按钮 * @param option.close {Function} 关闭回调 * scmAlert(msg, { status: 2 }) * scmAlert(msg, { status: 3, confirm: function(){}) */ function scmAlert(msg, option = {}) { let { confirm, confirmText = '确定', cancel, close, status = '1', animate = false } = option; let imgUrlArr = ['success', 'error', 'warning'], imgSrc = getProjectName() + '/plf/page/fp/img/' + imgUrlArr[+status - 1] + '.png'; $('#scm-alert').parents('.scm-shade').remove(); if (!$('#scm-alert').length) { $(document.body).append( '
' + '
提示×
' + '注:' + msg + '
' + '' + (cancel ? '' : '') + '
' ); $('#scm-alert').draggable({ handle: '.msg-hd' }); // 添加关闭窗口事件 $('#scm-alert') .find('.msg-close') .click(function () { close && close(); if (animate) { animate && $('#scm-alert') .parents('.scm-shade') .addClass('animate__fadeOut') .removeClass('animate__fadeIn'); animate && $('#scm-alert').addClass('animate__zoomOut').removeClass('animate__zoomIn'); setTimeout(function () { $('#scm-alert').parents('.scm-shade').remove(); }, 1000); return; } $('#scm-alert').parents('.scm-shade').remove(); }); $('#scm-alert') .find('.confirm') .click(function () { $('#scm-alert').find('.msg-close').click(); if (confirm) return confirm(); }); $('#scm-alert') .find('.close') .click(function () { cancel && cancel(); }); } animate && $('#scm-alert').parents('.scm-shade').addClass('animate__fadeIn').removeClass('animate__fadeOut'); animate && $('#scm-alert').addClass('animate__zoomIn').removeClass('animate__zoomOut'); $('#scm-alert').parents('.scm-shade').show(); } /** * @function 公用ajax * @description 只有code为200(number) 才会调用success * @param {Object} option ajax的参数 * @param {String} option.id mc的方法id 必填 * @example * mesAjax({ * id: 'xxxx', * success: function() {} * }) */ function mcAjax(option) { const mcPath = _GLO_ROOTPATH + 'buss/bussModel_exeFunc.ms?funcMId='; let funcId = option.id; let success = option.success; let error = option.error; delete option.id; delete option.success; option.type = option.type || 'POST'; option.dataType = option.dataType || 'json'; $.ajax({ url: mcPath + funcId, ...option, success: function ({ ajaxMap, _sessionTimeOutGoToUrl }) { if (_sessionTimeOutGoToUrl) { top.location.href = _sessionTimeOutGoToUrl; return; } if (ajaxMap.code !== 200) { if (error && error(ajaxMap)) return; top.utilsFp.confirmIcon(3, '提示', '', '', ajaxMap.msg, 0, '300', ''); return; } success(ajaxMap); }, error: function (err) { top.utilsFp.confirmIcon(3, '提示', '', '', err, 0, '300', ''); console.error('funcId' + funcId + ':' + err); error && error(err); } }); } /** * @function 警告 * @param {fn,params,tip} * @return undefined */ function mcConfirm(fn, tip, ...params) { var world = '是否确认删除'; tip = tip || (top && top.utilsFp ? top.utilsFp.getLangShow(world) : world) + '?'; utilsFp.confirmIcon(1, '', 'confirmCallback', '', tip, '1', '260', ''); window.confirmCallback = () => { if (typeof fn === 'string') return window[fn](...params) fn(...params) } } /** * @function ajax下载文件 * @param {String} url * @param {String} fileName */ function ajaxDownloadFile({ url, fileName, callback }) { var xhr = new XMLHttpRequest(); //创建新的XHR对象 xhr.open('post', url); //指定获取数据的方式和url地址 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); //设置请求头(不同属性值传递的方式不同) xhr.responseType = 'blob'; //以blob的形式接收数据,一般文件内容比较大 xhr.onload = function () { var reader = new FileReader(); var _this = this; reader.onload = function (event) { var content = reader.result; //内容就在这里 if (isJSON(content)) { const res = JSON.parse(content); utilsFp.confirmIcon(3, '提示', '', '', res.ajaxMap.msg, 0, '300', ''); callback && callback(res); } else { var content = _this.response; //Blob数据 var elink = document.createElement('a'); // 创建一个a标签用于下载 elink.download = fileName; //规定被下载的超链接目标名字 elink.style.display = 'none'; //标签隐藏 var blob = new Blob([content]); elink.href = URL.createObjectURL(blob); //规定链接指向的页面的URL document.body.appendChild(elink); elink.click(); //原生dom触发 document.body.removeChild(elink); callback && callback(); } }; reader.readAsText(this.response); }; xhr.send(); } function isJSON(str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); return true; } catch (e) { return false; } } console.log('It is not a string!'); } //弹出图片方法 //W:图片宽度 H:图片高度 //top:距上边的距离 left:距左边的距离 right:距右边的距离 bottom:距下边的距离 //(上下同时设置以上为准,左右同时设置以左为准,若为负值则不生效) //picUrl:图片地址 href:点击图片的链接地址 function newPic(W,H,top,left,right,bottom,picUrl,href,position,title){ $("
").css('height',H + 'px').css('width',W + 'px').attr('title',title).appendTo('body'); if(top != ""){ $('.popPic:last').css('top',top); } if(left != ""){ $('.popPic:last').css('left',left); } if(right != ""){ $('.popPic:last').css('right',right); } if(bottom != ""){ $('.popPic:last').css('bottom',bottom); } $("
").appendTo('.popPic:last'); /*if(!href){ $("").appendTo('.popPic:last'); }else{ $("").appendTo('.popPic:last'); }*/ $('').css('height',H + 'px').css('width',W + 'px').attr('src',picUrl).appendTo('.popPic:last'); } function closePic(obj){ $(obj).parents('.popPic').remove(); } function fixPx(p){ if(p==undefined||p==null){ return ''; }else{ return p+'px'; } } function replaceAll(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); }