var gPopFrameMap = []; var popupFrameId = "popupFrameFpId"; var popcount = 1; var parentPop = "parentPopId"; var _flag_ = false; var _formId_ = null; var _iframeId_ = null; var _flagForPrint = false;//条码打印标识 function winControl(blnVal) { // //cjd 页面数据正在加装中 禁用esc、空格、回车等 在iframe加装完,iframe中正常使用 begin 2017-12-15 if (blnVal) $(document).unbind("keydown"); else $(document).bind("keydown", function(e) { return blnVal; }) // //cjd 页面数据正在加装中 禁用esc、空格、回车等 在iframe加装完,iframe中正常使用 end2017-12-15 } var controlWinMark = 10; var popupFrameIdWin = null; function checkPopupFrameIdWin() { if (popupFrameIdWin != null) if (!$(popupFrameIdWin).is(":hidden")) { popupFrameIdWin = null; controlWinMark = 10; winControl(true); } else { controlWinMark = 20; winControl(false); } else { controlWinMark = 10; winControl(true); } setTimeout(checkPopupFrameIdWin, 10) } $(function() { checkPopupFrameIdWin(); }); //获取当前tab中打开的iframe 的id或者name function getCurTabIfameName(){ var cur_iframe_name; //获取当前tab中的iframe对象的window var tab_cur = $(mcGetTop().document).find("a.slick-slide.cur").parent(".item").attr("id"); var tab_num = tab_cur.replace(/[^0-9]/ig,""); cur_iframe_name = "iframe"+tab_num; //当前tab中iframe的id和iframe的name 他们值一样 return cur_iframe_name; } //获取当前tab中打开的iframe 中的弹层 zIndex function getIframePopZIndex(showPosition){ //判断top是否有 top.popConfig 没有的话top创建一个 适配window.open场景 if( !top.popConfig ){ top.popConfig={ "mainFrame":{"zIndex":10000,"popIframe":[]} }; } if(showPosition == "main-top" || showPosition == "tab-top"){ //return ++top.popConfig["mainFrame"]["zIndex"]; return ++top.zcount; //统一走 showPopWinFp()的层级 } if(showPosition == "tab-in") { var cur_iframe_name = getCurTabIfameName(); for(var key in top.popConfig){ if(cur_iframe_name == key){ return ++top.popConfig[cur_iframe_name]["zIndex"]; } } } } //设置顶层弹层存储的json /** * { * iframeId:"xxx", * showPosition: "tab-top/ tab-in / main-top" * } */ function setPopConfig(obj){ if(obj != null){ if(obj.showPosition == "main-top"){ top.popConfig["mainFrame"]["popIframe"].push(obj); } if(obj.showPosition == "tab-top" || obj.showPosition == "tab-in"){ top.popConfig[getCurTabIfameName()]["popIframe"].push(obj); } } } //获取父级弹窗 暂时弃用,请参照 mcGetUpPop() function _mcGetUpPop(parentIframeId){ var iframeId = window.frameElement.id; //获取当前弹层的 iframeId var showPosition = window.frameElement.getAttribute('data-showPosition');//获取当前弹层的打开方式 showPosition var popIframe = []; //获取当前所有弹层 //如果有指定参数parentIframeId则根据参数获取iframe window if(parentIframeId && showPosition){ if(showPosition == "main-top"){ return top.document.getElementById(parentIframeId).contentWindow; } if(showPosition == "tab-top" || showPosition == "tab-in"){ var _iframeId; try{ _iframeId = getCurTabIfameName(); //判断弹层传递的是不是tab中iframe的id if(parentIframeId==_iframeId){ return top.document.getElementById(getCurTabIfameName()).contentWindow; } else { //从 popIframe中拿到指定的parent return top.document.getElementById(getCurTabIfameName()).contentWindow.document.getElementById(parentIframeId).contentWindow; } } catch(err){ console.log(err); } } } //如果是自己写的iframe则获取不到showPosition 递归获取 if(!showPosition) { getPropShowPosition(window.frameElement); showPosition = top.getPropShowPositionArr[0]; if(showPosition){ iframeId = top.getPropIframeIdArr[0]; //获取到有 showPosition 的iframe的id } //新旧弹层混用场景 。下拉 创建并编辑 打开的弹层还是旧的 顶级弹层 这个时候获取到的showPosition 还是空 //默认从当前打开的tab中 获取弹层数组 中获取父级 if(!showPosition){ popIframe = top.popConfig[getCurTabIfameName()]["popIframe"]; } } if(iframeId && showPosition){ if(showPosition == "main-top"){ popIframe = top.popConfig["mainFrame"]["popIframe"]; } if(showPosition == "tab-in" || showPosition=="tab-top"){ popIframe = top.popConfig[getCurTabIfameName()]["popIframe"]; } } if( popIframe && popIframe.length > 0 ){ for(var i=0; i 0 说明获取上一个弹层 if(i > 0){ //mainFrame.jsp if(showPosition == "main-top"){ var _iframeId = popIframe[_index-1]["iframeId"]; return top.document.getElementById(_iframeId).contentWindow; } //tab中的iframe if(showPosition == "tab-top" || showPosition == "tab-in"){ var _pre_iframeId = popIframe[_index-1]["iframeId"]; //上一个弹层iframeid var _pre_showPosition = popIframe[_index-1]["showPosition"]; //上一个弹层的showPosition if(_pre_showPosition == "tab-top"){ //直接从最外层取父弹层 return top.document.getElementById(_pre_iframeId).contentWindow; } if(_pre_showPosition == "tab-in"){ //要在tab里面取父弹层 return top.document.getElementById(getCurTabIfameName()).contentWindow.document.getElementById(_pre_iframeId).contentWindow; } } } } } } } //获取父级弹窗 里面判断tab-in/tab-top 情况下匹配里面弹层json逻辑 function isRightPop(popIframe,parentIframeId){ if( popIframe && popIframe.length > 0 ){ for(var i=0; i 0){ //判断弹层不能以数字开头 /* var patt = /^[0-9]+[\s\S]*$/; if(patt.test(parentIframeId)){ utilsFp.confirmIcon(1,"","","", "iframe的id不能以数字开头!",0,"300",""); return; } */ var showPosition = mcGetCurIframeAttrShowPosition(); //当前弹层弹出方式 //如果有自己写的iframe则获取不到showPosition 递归获取 if(!showPosition) { getPropShowPosition(window.frameElement); showPosition = top.getPropShowPositionArr[0]; } if(showPosition){ //当前是新弹层 var popIframe; //新弹层中的管控的弹层json if(showPosition == "tab-in" || showPosition=="tab-top"){ popIframe = top.popConfig[getCurTabIfameName()]["popIframe"]; return isRightPop(popIframe,parentIframeId); } if(showPosition == "main-top"){ if(top.document.getElementById(parentIframeId)){ return top.document.getElementById(parentIframeId).contentWindow; } } } else { //当前弹层是旧弹层 //1、先从当前打开的tab中拿到管控的弹层json中判断 当做上层是tab-in / tab-top中判断 var popIframe; //新弹层中的管控的弹层json try{ popIframe = top.popConfig[getCurTabIfameName()]["popIframe"]; return isRightPop(popIframe,parentIframeId); } catch(err){ console.log(err); } //2、直接从顶层中拿 if(top.document.getElementById(parentIframeId)){ return top.document.getElementById(parentIframeId).contentWindow; } } } //获取上层弹层 if(!parentIframeId){ var parentIframeId; //拿到父级的id try{ parentIframeId= mcGetParentIframeId(); if(parentIframeId){ mcGetUpPop(parentIframeId); } } catch(err){ console.log(err); } } } //递归获取iframe中的属性 data-showPosition 对多级iframe嵌套的情况 /** * * */ function getPropShowPosition(iframeContext,positionflag){ if(!positionflag){ positionflag = 0; //保存到顶层 弹层打开方式 top.getPropShowPositionArr = []; //保存到顶层 有打开方式的层对应的ifarmeId top.getPropIframeIdArr = []; } try{ var showposition; var iframeId; showposition = $(iframeContext).attr('data-showposition'); iframeId = $(iframeContext).attr('id'); if(!showposition){ iframeContext = window.parent.frameElement; //默认向上最多获取5层 if(positionflag == 5){ return; } positionflag++; getPropShowPosition(iframeContext,positionflag) } top.getPropIframeIdArr.push(iframeId); return top.getPropShowPositionArr.push(showposition); } catch(err){ console.log(err) } } /** * 获取当前弹层中iframe的属性data-showPosition */ function mcGetCurIframeAttrShowPosition(){ var showPosition = ""; try{ showPosition = window.frameElement.getAttribute('data-showposition'); if(!showPosition){ showPosition = ""; } } catch(err){ showPosition = ""; } return showPosition; } /** * 获取父级弹层的id * 新弹层:" + ""; var tmpDiv = temp.createElement("div"); //添加记忆保持div var divMenu=""; tmpDiv.innerHTML = divStr+divMenu; var body = temp.getElementsByTagName("body")[0]; body.appendChild(tmpDiv); //给iframe 设置src gPopFrameMap[popupFrameId] = temp.getElementById(popupFrameId); gPopFrameMap[popupFrameId].src = url; //新开弹层数据更新到顶层保存的json popConfig中。 var _popConfig = new Object(); _popConfig.iframeId = popupFrameId; _popConfig.showPosition = showPosition; setPopConfig(_popConfig); //设置顶层弹层存储的json if(ExternalReferences){ top.$("#"+frameId+"pop").css("z-index","1203"); top.$("#"+frameId+"shadow").css("z-index","1202"); } popupFrameIdWin = $("#"+tempPopupFrameId); $("#"+popupFrameId).keydown(function(e) { return false; }); /* body.oncontextmenu = function(){   return false; } */ _top.$("#" + shadowPopupFrameId).show(); _top.$("#" + tempPopupFrameId).draggable({ containment : "body", iframeFix: true, handle: '.dialog-hd', cursor: "move", stop: function(){ if( parseInt( $(this).css('top') )<0 ){ $(this).css('top','0px'); } } }); } } /** * *******************************弹出iframe * BEGIN************************************************* */ /** * 弹出iframe * * @argument width - int in pixels * @argument height - int in pixels * @argument url - url to display * @argument returnFunc - function to call when returning true from the window. * @argument title - 弹出层的标题(如果为空,则取引入页面标签内的值) * @argument frameId 弹窗ID(建议自己定义,不要用默认的,否则容易冲突) * @argument showPosition 显示位置:为空或是0,则在当前页显示,否则在标签页显示 */ function showPopWinFp(url, width, height, returnFunc, title, frameId, showPosition,flag) { winControl(false); if (controlWinMark == 20) return; controlWinMark = 20; //解决回车和空格再次触发按钮点击事件问题 document.onkeydown = function () { if(document.activeElement){ var focusDom = document.activeElement; if(focusDom.nodeName.toLowerCase() == 'button'){ $(focusDom).blur(); } } }; if (window.frameElement != undefined && window.frameElement != null) { parentPop = window.frameElement.id; } if (null == title || "" == title) { title = document.title; } if (null != frameId && "" != frameId) { popupFrameId = frameId; } // 如果该参数为空或是0,则在当前页显示,否则在标签页显示 if (showPosition == null || showPosition == "" || showPosition == "0") { var ExternalReferences = false; var tempPopupFrameId = popupFrameId + "pop"; var shadowPopupFrameId = popupFrameId + "shadow"; var temp = top.document; width=typeof width =="string" && width.includes("%")?$(temp).width()*parseFloat(width)/100:parseFloat(width); height=typeof height =="string" && height.includes("%")?$(temp).height()*parseFloat(height)/100:parseFloat(height); if (height > $(temp).height()) { height = $(temp).height(); } if (width > $(temp).width()) { width = $(temp).width(); } var iTop; var zIndexNum; try { iTop = (top.getHeight() - height) / 2 - 20; } catch (e) { if(frameId && !flag){ iTop = ($(window).height() ) / 2 +20; ExternalReferences = true; }else{ iTop = ($(window).height()- height ) / 2 - 20; } $(".search-box").css("z-index","998"); } //var iTop = (top.getHeight() - height) / 2 - 20;// top.getHeight()在mainFrame中,获取最外层高度 if(iTop<=0){//判断出现负数的情况 iTop=5; } var iLeft = ($(temp).width() - width) / 2; // alert("screenWidth"+window.screen.availWidth+"screenHeight"+window.screen.availHeight+"docWidth:"+$(temp).width()+"docHeight:"+$(temp).height()+"iTop"+iTop // +"iLeft:"+iLeft+"height:"+height+"width:"+width); var divStr = "
" + "
" + "

" + title + "

" + "
"; if (_flag_) { divStr += " " }if(_flagForPrint){ divStr+=" " }else if(!_flag_&&!_flagForPrint){ divStr += " " } _flag_ = false; _flagForPrint=false; divStr += "
" + " " + "
" + "
";// src=\"plf/page/fp/loading.jsp\" // +"
"; // if($(".dialog-mask").length == 0){ divStr += "
"; top.zcount++; // } var tmpDiv = temp.createElement("div"); //添加记忆保持div var divMenu=""; tmpDiv.innerHTML = divStr+divMenu; var body = temp.getElementsByTagName("body")[0]; body.appendChild(tmpDiv); /* body.oncontextmenu = function(){   return false; } */ gPopFrameMap[popupFrameId] = temp.getElementById(popupFrameId); if(ExternalReferences){ top.$("#"+frameId+"pop").css("z-index","1203"); top.$("#"+frameId+"shadow").css("z-index","1202"); } // if(gPopFrameMap[popupFrameId].src!=url) gPopFrameMap[popupFrameId].src = url; popupFrameIdWin = $(tempPopupFrameId) $(popupFrameId).keydown(function(e) { return false; }); $(gPopFrameMap[popupFrameId]).load(function() { // cjd frameId 没有值说明根页面 有值说明子页面有回调 2017-12-18 begin // if(frameId!=null) // cjd frameId 没有值说明根页面 有值说明子页面有回调 2017-12-18 emd }); top.$("#" + shadowPopupFrameId).show(); top.$("#" + tempPopupFrameId).draggable({ containment : "body", iframeFix: true, handle: '.dialog-hd', cursor: "move", stop: function(){ if( parseInt( $(this).css('top') )<0 ){ $(this).css('top','0px'); } } }); // $(".dialog").draggable(); // $("#popWinFpId0").resizable();未引jquery-ui.css无法生效 // $("#popWinFpId0").click(function(){ // $(".dialog-mask").hide(); // }); // alert(popupFrameId+":"+popcount); popcount++; } else { mcGetTop().addTab(url, title, popupFrameId); } } function showPopWinFpForSubmit(url, width, height, returnFunc, title, frameId, showPosition, submitForm, iframeId) { _flag_ = true; _formId_ = submitForm; _iframeId_ = iframeId; showPopWinFp(url, width, height, returnFunc, title, frameId, showPosition) } //tab中的iframe 关闭 by tangws function mcClosePopWinFp(popupFrameId,showPosition) { //将顶层json中对应的弹层删除 var popIframe = []; if(showPosition == "main-top"){ popIframe = top.popConfig["mainFrame"]["popIframe"]; } if(showPosition == "tab-top" || showPosition == "tab-in"){ popIframe = top.popConfig[getCurTabIfameName()]["popIframe"]; } //将数组中对应的iframeId = popupFrameId 对象移除 if( popIframe && popIframe.length > 0 ){ for(var i=0; i标签内的值) * @argument divId 弹出层ID * @argument contentHtml 内容 */ var popupDivId = "popupDivFpId"; var parentPopDiv = "parentPopDivId"; function showPopDivFp(width, height, returnFunc, title, divId, contentHtml) { if (null == title || "" == title) { title = document.title; } if (null != divId && "" != divId) { popupDivId = divId; } var tempPopupDivId = popupDivId + "pop"; var shadowPopupDivId = popupDivId + "shadow"; var temp = top.document; if (height > $(temp).height()) { height = $(temp).height(); } if (width > $(temp).width()) { width = $(temp).width(); } var iTop = ($(document).height() - height) / 2; var iLeft = ($(temp).width() - width) / 2; // alert("screenWidth"+window.screen.availWidth+"screenHeight"+window.screen.availHeight+"docWidth:"+$(temp).width()+"docHeight:"+$(temp).height()+"iTop"+iTop // +"iLeft:"+iLeft+"height:"+height+"width:"+width); var divStr = "
" + "
" + "

" + title + "

" + "
" + " " + "
" + contentHtml + "
" + "
"; // +"
"; // if($(".dialog-mask").length == 0){ divStr += "
"; top.zcount++; // } var tmpDiv = temp.createElement("div"); tmpDiv.innerHTML = divStr; var body = temp.getElementsByTagName("body")[0]; body.appendChild(tmpDiv); top.$("#" + shadowPopupDivId).show(); top.$("#" + tempPopupDivId).draggable(); } // 提交数据 function submitDatas(iframeId, methodName, args) { $(window.parent.document).contents().find("#" + iframeId)[0].contentWindow.window[methodName] (args); } function closePopDivFp(tempPopupDivId) { $("#" + tempPopupDivId).parent().remove(); top.$("#" + tempPopupDivId).parent().remove(); // $("#"+shadowPopupDivId).remove(); } /** * *************************************弹出最外层DIV * END************************************************** */ /** * ************************************弹出普通DIV * BEGIN**************************************************** */ /** * 弹出DIV,非最外层 * * @argument width - int in pixels * @argument height - int in pixels * @argument returnFunc - function to call when returning true from the window. * @argument title - 弹出层的标题(如果为空,则取引入页面标签内的值) * @argument divId 弹出层ID * @argument contentHtml 内容 */ var divFpId = "divFpId"; function showDivFp(width, height, returnFunc, title, divId) { var copy_div=$("#" + divId).html(); copy_div=copy_div.replace('printset_tab','printset_tab_new')//打印设置 top.zcount=11000; if (null == title || "" == title) { title = document.title; } if (null != divId && "" != divId) { divFpId = divId; } var tempPopupDivId = divFpId + "pop"; var shadowPopupDivId = divFpId + "shadow"; if (height > $(window).height()) { height = $(window).height(); } if (width > $(window).width()) { width = $(window).width(); } var iTop = ($(window).height() - height) / 2; var iLeft = ($(window).width() - width) / 2; // alert("screenWidth"+window.screen.availWidth+"screenHeight"+window.screen.availHeight+"docWidth:"+$(temp).width()+"docHeight:"+$(temp).height()+"iTop"+iTop // +"iLeft:"+iLeft+"height:"+height+"width:"+width); var divStr = "
" + "
" + "

" + title + "

" + "
" + " " + "
" + copy_div + "
" + "
"; // +"
"; // if($(".dialog-mask").length == 0){ divStr += "
"; top.zcount++; // } var tmpDiv = document.createElement("div"); tmpDiv.innerHTML = divStr; var body = document.getElementsByTagName("body")[0]; body.appendChild(tmpDiv); // $("#"+divId).show(); $("#" + shadowPopupDivId).show(); $("#" + tempPopupDivId).draggable(); } function closeDivFp(tempPopupDivId) { $("#" + tempPopupDivId).parent().remove(); } /** * *************************************弹出普通DIV * END************************************************** */ //0418 CSJ 条码 function showPopWinFpForPrint(url, width, height, returnFunc,title,frameId,showPosition){ _flagForPrint=true; var tempIframeId=frameId; _iframeId_=tempIframeId; showPopWinFp(url, width, height, returnFunc,title,frameId,showPosition) } //0418 CSJ 条码 var closePopWinFpForPrintFrameId; function closePopWinFpForPrint(tempPopupFrameId,_formId_,_iframeId_){ closePopWinFpForPrintFrameId=tempPopupFrameId; if(localStorage.printStatus==1||localStorage.printStatus==0||localStorage.printStatus==""){ $("#"+tempPopupFrameId).parent().remove(); }else{// utilsFp.confirmIcon(3,"","isCloseWin","", _GLO_LABEL_PRINT_TIP,1,"","","","1"); } } //0418 CSJ 条码 function isCloseWin(){ $("#"+closePopWinFpForPrintFrameId).parent().remove(); } /** * 设置记忆值 * @param event * @param popupFrameFlag * @param object */ function showDigInfo(event,popupFrameFlag,object){ event.preventDefault(); if(event.button==2){ $("#smartMenu"+popupFrameFlag).show(); $("#smartMenu"+popupFrameFlag).css("left",event.x); $("#smartMenu"+popupFrameFlag).css("top",event.y); }else{ $("#smartMenu"+popupFrameFlag).hide(); } } /** * 添加子节目记忆值 * @param event * @param popupFrameFlag * @param object */ function addSaveMark(event,popupFrameFlag,object){ $("#smartMenu"+popupFrameFlag).hide(); popupFrameFlag="#"+popupFrameFlag; if (typeof $(popupFrameFlag)[0].contentWindow.saveMarkInfo === "function") { $(popupFrameFlag)[0].contentWindow.saveMarkInfo(); } } function getUrlObject(url) { url = url == null ? window.location.href : url; var search = url.substring(url.lastIndexOf("?") + 1); var obj = {}; var reg = /([^?&=]+)=([^?&=]*)/g; search.replace(reg, function (rs, $1, $2) { var name = decodeURIComponent($1); var val = decodeURIComponent($2); val = String(val); obj[name] = val; return rs; }); return obj; } /** * 当MC被别的系统嵌入的时候 top的获取 */ function mcGetTop(){ try{ if(top.EXTSYS_INCLUDE_MC == 'EXTSYS_INCLUDE_MC'){ if(top.document.getElementById("mcIncludeByIframe").contentWindow){ return top.document.getElementById("mcIncludeByIframe").contentWindow; } } else { //没有被嵌套 mainFrame.jsp return top; } } catch(err){ return top; } }