- // 对话框数组
- var dialogArray = [];
-
- function openDialog(args, cb) {
- console.log("args", args);
- var height = args.height || (args.full ? window.innerHeight : 500);
- var width = args.width || (args.full ? window.innerWidth : 660);
- //var rootFontSize = parseInt($("html").css('fontSize'));
-
- if (height.toString().indexOf('%') === -1) {
- // window.devicePixelRatio是浏览器缩放比例
- height = (height / window.devicePixelRatio);
- // debugger
- if (height > window.innerHeight) {
- height = window.innerHeight - 20;
- }
-
- height = height + "px";
- }
- if (width.toString().indexOf('%') === -1) {
- width = (width / window.devicePixelRatio);
-
- if (width > window.innerWidth) {
- width = window.innerWidth - 20;
- }
-
- width = width + "px";
- }
- var closeBtn = 1;
- if (args.closeBtn === 0) {
- closeBtn = 0;
- }
-
- //右上角关闭时候是否提示
- var isConfirm = 0;
- if (args.isConfirm === 1) {
- isConfirm = 1;
- }
-
- var maxmin = false;
- if (args.maxmin === true) {
- maxmin = true;
- }
-
- var moveEl = ".layui-layer-title";
- if (args.move == false) {
- moveEl = false;
- }
-
- var resize = true;
- if (args.resize == false) {
- resize = false;
- }
-
- // 格式化Url
- try {
- // 将..替换成全路径
- if (getRootUrl && typeof (getRootUrl) == "function") {
- args.url = args.url.replace("../", getRootUrl());
- }
- } catch (e) {
-
- }
-
- var type = typeof (args.url) === "string" ? 2 : 1;
- var index = clayer.open({
- type: type,
- title: args.title || "",
- maxmin: maxmin,
- moveType: 1, //拖拽风格,0是默认,1是传统拖动
- move: moveEl, //是否允许拖动
- resize: resize, //是否允许拉伸
- shift: 0, //0-6的动画形式,-1不开启
- shadeClose: false, //是否点击遮罩关闭
- area: [width, height],
- content: args.url || "",
- closeBtn: closeBtn,
- end:args.end,
- success: function (layero, index) {
- // 关闭loading...
- hideLoad();
-
- },
- cancel: function (index) {
- // 维护dialogArray中数据
- if (isConfirm == 1) {
- layer.confirm('确定关闭吗?', function (index2) {
- console.log("关闭");
- layer.close(index2);
-
- if (args.cancel) {
- args.cancel();
- }
- var start = -1;
- $.each(dialogArray, function (i, value) {
- if (value.index == index) {
- start = i;
- }
- });
- // 如果搜索出数据,则进行删除
- if (start != -1) {
- dialogArray.splice(start, 1);
- }
-
- layer.close(index);
- });
- return false;
- } else {
- if (args.cancel) {
- args.cancel();
- }
- var start = -1;
- $.each(dialogArray, function (i, value) {
- if (value.index == index) {
- start = i;
- }
- });
- // 如果搜索出数据,则进行删除
- if (start != -1) {
- dialogArray.splice(start, 1);
- }
-
- }
- }
- });
-
- dialogArray.push({
- index: index,
- callback: cb
- });
- //console.log("dialogArray", dialogArray);
- // 显示loading...
- //showLoad();
- //if (type != 1) {
- // clayer.load();
- //}
- }
-
- function _closeDialog(b) {
- //移除最后一个数组元素
- //console.log("dialogArray1", dialogArray);
- var dialog = dialogArray.pop();
- //console.log("dialogArray2", dialogArray);
-
- console.log("dialog", dialog);
- if (dialog === undefined)
- return;
-
- try {
- dialog.callback & dialog.callback(b);
- } catch (e) {
-
- }
- layer.close(dialog.index);
- }
-
- var clayer = window.layer || window.parent.layer || {};
-
- if (window.parent.openDialog) {
- //console.log("main.window.parent", window.parent.openDialog);
- window._closeDialog = window.parent._closeDialog;
- window.openDialog = window.parent.openDialog;
- window.clayer = window.parent.clayer;
- }
-
- function showLoad() {
- try {
- clayer && clayer.load(1, {
- shade: [0.5, '#000'] //0.5透明度的黑色背景
- });
- } catch (e) {
-
- }
- }
-
- function hideLoad() {
- try {
- // 关闭所有的加载层
- if (clayer) {
- clayer.closeAll('loading');
- // clayer.closeAll();
- } else {
- console.log("hideLoad,未取到clayer");
- }
- } catch (e) {
-
- }
- }
-
- function closeAllLayer() {
- try {
- // 关闭所有的加载层
- if (clayer) {
- clayer.closeAll();
- } else {
- console.log("closeAllLayer,未取到clayer");
- }
- } catch (e) {
-
- }
- }