You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.2 KiB

4 years ago
/*
* EasyCode EC管理后台
* 弹层基于layer.js-3.0.3
*/
(function ($, learun) {
"use strict";
$.extend(learun, {
// 询问框
layerConfirm: function (_msg, callback) {
top.learun.language.get(_msg, function (msg) {
top.layer.confirm(msg, {
btn: ['确认', '取消'],
title: "提示",
icon: 0,
skin: 'lr-layer',
success: function (layero, index) {
layero.find('.layui-layer-btn a').each(function () {
var $this = $(this);
var _text = $this.text();
top.learun.language.get(_text, function (text) {
$this.text(text);
});
});
layero.find('.layui-layer-title').each(function () {
var $this = $(this);
var _text = $this.text();
top.learun.language.get(_text, function (text) {
$this.text(text);
});
});
},
}, function (index) {
callback(true, index);
}, function (index) {
callback(false, index);
top.layer.close(index); //再执行关闭
});
});
},
// 自定义表单弹层
layerForm: function (op) {
var dfop = {
id: null,
title: '系统窗口',
width: 550,
height: 400,
url: 'error',
btn: ['确认', '关闭'],
callBack: false,
maxmin: false,
end: false,
};
$.extend(dfop, op || {});
/*适应窗口大小*/
dfop.width = dfop.width > $(window).width() ? $(window).width() - 10 : dfop.width;
dfop.height = dfop.height > $(window).height() ? $(window).height() - 10 : dfop.height;
if (op.url.indexOf('?') != -1) {
op.url += '&lraccount=' + top.$.lcoreUser.account;
}
else {
op.url += '?lraccount=' + top.$.lcoreUser.account;
}
var r = top.layer.open({
id: dfop.id,
maxmin: dfop.maxmin,
type: 2,//0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
title: dfop.title,
area: [dfop.width + 'px', dfop.height + 'px'],
btn: dfop.btn,
content: encodeURI(encodeURI(op.url)),
skin: dfop.btn == null ? 'lr-layer-nobtn' : 'lr-layer',
success: function (layero, index) {
top['layer_' + dfop.id] = learun.iframe($(layero).find('iframe').attr('id'), top.frames);
layero[0].learun_layerid = 'layer_' + dfop.id;
//如果底部有按钮添加-确认并关闭窗口勾选按钮
if (!!dfop.btn && layero.find('.lr-layer-btn-cb').length == 0) {
top.learun.language.get('确认并关闭窗口', function (text) {
layero.find('.layui-layer-btn').append('<div class="checkbox lr-layer-btn-cb" myIframeId="layer_' + dfop.id + '" ><label><input checked="checked" type="checkbox" >' + text + '</label></div>');
});
layero.find('.layui-layer-btn a').each(function () {
var $this = $(this);
var _text = $this.text();
top.learun.language.get(_text, function (text) {
$this.text(text);
});
});
}
layero.find('.layui-layer-title').each(function () {
var $this = $(this);
var _text = $this.text();
top.learun.language.get(_text, function (text) {
$this.text(text);
});
});
},
yes: function (index) {
var flag = true;
if (!!dfop.callBack) {
flag = dfop.callBack('layer_' + dfop.id);
}
if (!!flag) {
learun.layerClose('', index);
}
},
btn2: function (index) {
console.log('dfop.cancel', dfop.cancel);
var flag = true;
if (!!dfop.cancel) {
flag = dfop.cancel('layer_' + dfop.id);
}
if (!!flag) {
learun.layerClose('', index);
}
},
end: function () {
top['layer_' + dfop.id] = null;
if (!!dfop.end) {
dfop.end();
}
}
});
},
// 关闭弹层
layerClose: function (name, index) {
var _index;
if (!!index) {
_index = index;
}
else {
_index = top.layer.getFrameIndex(name);
}
var layero = top.$("#layui-layer" + _index);
var $IsClose = layero.find('.layui-layer-btn').find(".lr-layer-btn-cb input");
var IsClose = $IsClose.is(":checked");
if ($IsClose.length == 0) {
IsClose = true;
}
if (IsClose) {
top.layer.close(_index); //再执行关闭
} else {
top[layero[0].learun_layerid].location.reload();
}
}
});
})(window.jQuery, top.learun);