基于easyui的弹出窗口,自己留个以后用

 
/**
 * @deprecated 弹出窗口组件,基于easyui-1.3.2+,
 * @author caonq
 * @version 0.1
 */
var popWin={
 setupNum:1,
 buttons:[],
 //初始化组件。
 init:function(){
   if(parent.$("#_pop_winParent").length>0){
    parent.$("#_pop_winParent").remove();
   }
   $('<div id="_pop_winParent"><div id="_pop_win"></div></div>').appendTo(window.top.document.body);
 },
 //初始化消息列表组件
 initMsgList:function(){
  if($("#_pop_winParent").length>0){
   $("#_pop_winParent").remove();
  }
  $('<div id="_pop_winParent"><div id="showMsgList"><div id="msgDetail"></div></div></div>').appendTo("body");
 },
 /**
  * 多条提示信息以列表的方式显示
  * @param msg 已格式化的提示信息
  * @param width 宽度 默认600
  * @param height 高度 默认300
  */
 popMsgList:function(msg,width,height){
  popWin.initMsgList();
  $("#msgDetail").append(msg);
  $("#showMsgList").dialog({
   closed:true,
   closable:false,
   title:"提示消息",
   resizable:true,
   maximizable:false,
   modal:true,
   width:width==undefined?'600':width,
   height:height==undefined?'300':height,
   buttons: [{
     text:'关闭',
     handler:function(){
       $("#showMsgList").dialog("destroy").remove();  
       }
      }]
   });
   $("#showMsgList").dialog("open");
 },
 init_1:function(){
  if(parent.$("#_pop_winParent_1").length>0){
   parent.$("#_pop_winParent_1").remove();
  }
  $('<div id="_pop_winParent_1"><div id="_pop_win_1"></div></div>').appendTo(window.top.document.body);
 },
 //打开明细画面。只有关闭按钮
 popView:function(url,title,width,height){
  popWin.init();
  var content = '<iframe id="_dialogFrame" name="_dialogFrame" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>';
   parent.$("#_pop_win").dialog({
   closed:true,
   closable:false,
   title:" ",
   content: content,
   resizable:true,
   maximizable:true,
   modal:true,
   width:width==undefined?'800':width,
   height:height==undefined?'600':height,
   buttons: [{
      text:'关闭',
   iconCls:'icon-cancel',
   handler:function(){
     popWin.close();
       }
      }]
   });
   parent.$("#_pop_win").dialog("open");
 },
 //打开明细画面,被打开的页面js有效,有提交和关闭按钮
 popEdit:function(url,title,width,height){
  popWin.init();
   var content = '<iframe id="_dialogFrame" name="_dialogFrame" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>';
   parent.$("#_pop_win").dialog({
    closed:true,
    closable:false,
    title:" ",
    content: content,
    maximizable:true,
    resizable:true,
    modal:true,
    width:width==undefined?'800':width,
    height:height==undefined?'600':height,
    buttons: [{
       text:'提交',
       id:'save-button',
       iconCls:'icon-save',
       handler:function(){
        popWin.submit();
       }
      },{
       text:'关闭',
       iconCls:'icon-cancel',
       id:'close-button',
       handler:function(){
        popWin.close();
       }
      }]
   });
  parent.$("#_pop_win").dialog("open");
 },
 //有下一步的弹出窗口
 popNext:function(url,title,steps,width,height){
  popWin.init();
  if(steps==undefined||steps==1){
   popWin.popEdit(url,title,width,height);
  }else{
   if(popWin.setupNum<steps){
    var content = '<iframe id="_dialogFrame" name="_dialogFrame" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>';
   parent.$("#_pop_win").dialog({
    closed:true,
    closable:false,
    title:" ",
    content: content,
    maximizable:true,
    resizable:true,
    modal:true,
    width:width==undefined?'800':width,
    height:height==undefined?'600':height,
    buttons: [{
       text:'上一步',
       id:'back-button',
       iconCls:'icon-back',
       handler:function(){
        popWin.backSubmit();
       }
      },
              {
       text:'跳过',
       id:'skip-button',
       iconCls:'icon-ok',
       handler:function(){
        popWin.skipSubmit();
       }
      },
              {
       text:'下一步',
       id:'save-button',
       iconCls:'icon-ok',
       handler:function(){
        if(popWin.setupNum!=steps){
         popWin.nextSubmit(steps);
        }else{
         popWin.submit();
        }
       }
      },{
       text:'取消',
       iconCls:'icon-cancel',
       id:'close-button',
       handler:function(){
        popWin.close();
       }
      }]
   });
  parent.$("#skip-button").hide();
  parent.$("#back-button").hide();
  parent.$("#_pop_win").dialog("open");
   }
  }

 },
 //内部调用,外部不需调用
 data:function(){
  var win = window.parent.document.getElementById('_dialogFrame').contentWindow; 
     var winHtml=win.document.body;
     var form=$(winHtml).find(".popWin");
     if(form.size()>0){
      var action=form.attr("action");
      var submitCheck=form.attr("submitCheck");
      var check;
      if(submitCheck==""||submitCheck==undefined){
       check=true;
       }else{
        check=eval("parent.$(\"#_dialogFrame\")[0].contentWindow."+submitCheck);
       }
      if(check){
       return {actionUrl:action,fromData:form.serialize()};
      } 
     }else{
      //$.messager.alert("错误信息","获取表单数据出错,请联系开发者!","error");
     }
  return null;
 },
 //带自定义按钮的dialog
 definedWin:function(url,title,width,height){
  popWin.init();
  var content = '<iframe id="_dialogFrame" name="_dialogFrame" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>';
  parent.$("#_pop_win").dialog({
   closed:true,
   closable:false,
   title:" ",
   content: content,
   maximizable:true,
   resizable:true,
   modal:true,
   width:width==undefined?'800':width,
   height:height==undefined?'600':height,
   buttons:popWin.buttons
  });
  parent.$("#_pop_win").dialog("open");
 },
 /**
  * 描述:
  * 用法:
  * @param url 需要在dialog中打开的页面的地址
  * @param title dialog的标题(目前无效,默认为空格)
  * @param width dialog的宽度,不定义的话默认800
  * @param height dialog的高度,不定义的话默认600
  */
 definedWin_1:function(url,title,width,height){
  popWin.init_1();
  var content = '<iframe id="_dialogFrame_1" name="_dialogFrame" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>';
  parent.$("#_pop_win_1").dialog({
   closed:true,
   closable:false,
   title:" ",
   content: content,
   maximizable:true,
   resizable:true,
   modal:true,
   width:width==undefined?'800':width,
   height:height==undefined?'600':height,
   buttons:popWin.buttons
  });
  parent.$("#_pop_win_1").dialog("open");
 },
 /**
  *  描述:执行dialog中的函数
  *  用法:在使用popWin.definedWin,popWin.popView,popWinEdit方法的页面中使用popWin.runFunc执行dialog中的方法。
  * @param func dialog中的函数
  * @returns
  */
 runFunc:function(func){
  return eval("parent.$(\"#_dialogFrame\")[0].contentWindow."+func);
 },
 /**
  * 描述:调用父页面的函数。
  * 用法:先定义popWin.pFunc,然后使用popWin.runParentfunc调用父页面的函数
  */
 runParentfunc:function(){
  return eval(popWin.pFunc);
 },
 /**
  * 描述:定义需调用父页面的函数
  * 用法:当使用popWin.definedWin,popWin.popView,popWinEdit方法前赋值,可以在打开的dialog中使用popWin.runParentfunc调用父页面的函数
  */
 pFunc:"",
 /**
  * 在使用popWin.definedWin_1的页面执行弹出的dialog中页面的函数。
  * @param func :弹出的dialog中页面的函数
  * @returns 函数的返回值
  */
 runFunc_1:function(func){
  return eval("parent.parent.$(\"#_dialogFrame_1\")[0].contentWindow."+func);
 },
 /**
  * 描述:关闭dialog。
  * 用法:当调用popWin.definedWin,popWin.popView,popWinEdit方法,需要关闭打开的dialog时使用popWin.close关闭dialog。
  */
 close:function(){
  parent.$("#_pop_win").dialog("destroy").remove();  
  this.setupNum=1;
 },
 /**
  * 描述:关闭dialog。
  * 用法:当调用popWin.definedWin_1方法,需要关闭打开的dialog时使用popWin.close_1关闭dialog。
  */
 close_1:function(){
  parent.$("#_pop_win_1").dialog("destroy").remove();  
  //parent.$("#_pop_winParent_1").append("<div id='_pop_win_1'></div>" );
  this.setupNum=1;
 },
 /**
 *描述:dialog-Toolbar的确认按钮按钮的动作,内部调用
 *用法:在有确认按钮的画面中,需要提交的表单增加form的属性:class='popWin' submitCheck='form表单提交校验的方法' action='提交动作的提交地址'
 *(提示:submitCheck的方法为校验方法,校验没过的请return false,校验过的话return true,不能只用return)'
 */
 submit:function(){
   var returnData=popWin.data();
   if(returnData!=null){
    $.ajax({
     url:returnData.actionUrl,
     data:returnData.fromData,
     async:false,
     type:"POST",
     success:function(data){
      top.$.messager.alert("提示信息",data.o_msg,"",function(data_){
       if(popWin.pFunc!=""){
        popWin.runParentfunc();
       }
      });
      popWin.close();
     },
     error:function(){
      top.$.messager.alert("错误信息","提交表单出错,请联系开发者!","error");
      popWin.close();
     }
    });
   }
 },
 /**
 *描述:dialog-Toolbar的下一步按钮按钮的动作,内部调用
 *用法:在有下一步按钮的画面中,需要提交的表单增加form的属性:class='popWin' submitFunc='下一步按钮的方法' action='下一步动作的提交地址'
 *(提示:submitFunc的方法为正常的form表单提交,校验没过的请return false,不要只return)'
 */
 nextSubmit:function (steps){
   ifr=parent.$('#_dialogFrame').contents();
   var form=parent.$(ifr).find(".popWin");
   var func=form.attr("submitFunc");
   subFg=eval("parent.$(\"#_dialogFrame\")[0].contentWindow."+func);
   if(subFg!=false){
    popWin.setupNum = popWin.setupNum+1;
    if(popWin.setupNum==steps){
     parent.$("#save-button").find(".l-btn-text").text("确定");
     parent.$("#save-button").find(".l-btn-icon.icon-next").attr("class","l-btn-icon icon-save");
     parent.$("#close-button").find(".l-btn-text").text("关闭");
     parent.$("#back-button").show();
    }
   }
  },
 /**
 *描述:dialog-Toolbar的上一步按钮的动作,内部调用
 *用法:在有上一步按钮的画面中,需要提交的表单增加form的属性:class='popWin' backFunc='上一步按钮的方法' action='上一步动作的提交地址'
 *(提示:backFunc的方法为正常的form表单提交,校验没过的请return false,不要只return。)'
 */
 backSubmit:function(){
  ifr=parent.$('#_dialogFrame').contents();
  var form=parent.$(ifr).find(".popWin");
  var func=form.attr("backFunc");
  subFg=eval("parent.$(\"#_dialogFrame\")[0].contentWindow."+func);
  if(subFg!=false){
   popWin.setupNum = popWin.setupNum-1;
  }
  parent.$("#save-button").show();
  if(popWin.setupNum > 1){
   parent.$("#back-button").show();
  }else{
   parent.$("#back-button").hide();
  }
  parent.$("#save-button").find(".l-btn-text").text("下一步");
 },
 /**
 *描述:dialog-Toolbar的跳过按钮的动作,内部调用
 *用法:在有跳过按钮的画面中,需要提交的表单增加form的属性:class='popWin' skipFunc='跳过按钮的方法 action='跳过动作的提交地址'
 *(提示:skipFunc的方法为正常的form表单提交,校验没过的请return false,不要只return)'
 */
 skipSubmit:function(){
  ifr=parent.$('#_dialogFrame').contents();
  var form=parent.$(ifr).find(".popWin");
  var func=form.attr("skipFunc");
  subFg=eval("parent.$(\"#_dialogFrame\")[0].contentWindow."+func);
  if(subFg!=false){
   popWin.setupNum = popWin.setupNum+1;
  }
 }
};

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dev_Arno

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值