jQuery MiniUI

 找回密码
 立即注册
查看: 1867|回复: 2
打印 上一主题 下一主题

求大神指点mini.open该如何封装 [复制链接]

匿名
跳转到指定楼层
楼主
匿名  发表于 2020-1-19 10:56:30 |倒序浏览
  1. openDialog: function (options) {
  2.         if (!options){
  3.             return;
  4.         }
  5.         if (!options.url){
  6.             return;
  7.         }
  8.         var defaultOptions = {
  9.             type: 0,
  10.             targetWindow: '',
  11.             title: "",
  12.             url: "",
  13.             width: "",
  14.             height: "",
  15.             iconCls: '',
  16.             showHeader: true,
  17.             cls: '',
  18.             borderStyle: '',
  19.             allowResize: false,
  20.             allowDrag: true,
  21.             showCloseButton: true,
  22.             showMaxButton: false,
  23.             showModal: true,
  24.             loadOnRefresh: false,
  25.             onload: null,     //弹出页面加载完成
  26.             ondestroy: null  //弹出页面关闭前
  27.         };
  28.         options = $.extend('', defaultOptions, options);
  29.         if(options.type == 0) {  //弹出自定义大小窗口
  30.             options.width = options.width || 500;
  31.             options.height = options.height || 400;
  32.         } else if (options.type == 1 || options.type == 2){ //1弹出ifram窗口, //2弹出顶级全屏窗口
  33.             options.showHeader= false;
  34.             options.cls = 'showMaxCenter';
  35.             options.borderStyle= 'border:0';
  36.             options.allowDrag= false;
  37.             options.allowResize= false;
  38.             if(options.type == 1){
  39.                 options.targetWindow= window;
  40.             }
  41.         }
  42.         if(options.url.indexOf("http") == -1) {
  43.             options.url = ROOTPATH + options.url;
  44.         }
  45.         console.log(options.url);
  46.         var win = mini.open({
  47.             targetWindow: options.targetWindow,   //页面对象。默认是顶级页面。
  48.             url: options.url,                      //页面地址
  49.             showHeader: options.showHeader,       //显示头部
  50.             title: options.title,                 //标题
  51.             cls: options.cls,                      //样式
  52.             borderStyle: options.borderStyle,    //边框
  53.             iconCls: options.iconCls,             //标题图标
  54.             width: options.width,                 //宽度
  55.             height: options.height,               //高度
  56.             allowResize: options.allowResize,    //允许尺寸调节
  57.             allowDrag:  options.allowDrag,         //允许拖拽位置
  58.             showCloseButton: options.showCloseButton,   //显示关闭按钮
  59.             showMaxButton: options.showMaxButton,     //显示最大化按钮
  60.             showModal: options.showModal,         //显示遮罩
  61.             loadOnRefresh: options.loadOnRefresh,       //true每次刷新都激发onload事件
  62.             onload: typeof options.onload === "function" ? options.onload : function() {
  63.                 var iframe = this.getIFrameEl();
  64.                 if(typeof iframe.contentWindow.setData == "function" && options.data){
  65.                     iframe.contentWindow.setData(options.data);
  66.                 }
  67.             },
  68.             ondestroy: typeof options.ondestroy === "function" ? options.ondestroy : function(action) {
  69.                 if(action == "ok" && typeof options.onOkClick === "function"){
  70.                     options.onOkClick()
  71.                 }
  72.                 if(action == "cancle" && typeof options.onCancleclick === "function"){
  73.                     options.onCancleclick()
  74.                 }
  75.                 if(action == "close" && typeof options.onCloseclick === "function"){
  76.                     options.onCloseclick()
  77.                 }
  78.             }
  79.         });
  80.         if(options.type == 1 || options.type == 2) {
  81.             win.max();
  82.         }
  83.     },
复制代码
上面是我封装的,看上去不怎么简洁,然后调用这个方法的时候窗口好像加载的慢了,该如何修改一下

Rank: 8Rank: 8

沙发
发表于 2020-1-19 13:56:50 |只看该作者
此帖仅作者可见
匿名
板凳
匿名  发表于 2020-1-19 14:44:20
此帖仅作者可见

Archiver|普加软件

GMT+8, 2024-7-3 00:46 , Processed in 1.039141 second(s), 9 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部