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.
121 lines
3.8 KiB
121 lines
3.8 KiB
2 years ago
|
__AJAX_LOCK = {lock: false};
|
||
|
|
||
|
// 返回 layer.index
|
||
|
function startLoading() {
|
||
|
return layer.load(1, {
|
||
|
shade: [0.4, '#000'] //0.1透明度的白色背景
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$.fn.extend({
|
||
|
/**
|
||
|
*
|
||
|
* @param option
|
||
|
* @param successExpr 默认值 1 == resp.dataList[0]
|
||
|
* 后台返回成功表达式 ,当后台返回成功后,如果是 iframe 弹层,需要禁用除返回按钮!以防多次提交
|
||
|
*/
|
||
|
wrapAjaxSubmit: function (option, successExpr) {
|
||
|
var t = $(this);
|
||
|
if (option == null) {
|
||
|
console.log('ajaxSubmit 参数不能为空!!');
|
||
|
return;
|
||
|
}
|
||
|
var index = startLoading();
|
||
|
var temp = option.complete;
|
||
|
|
||
|
option.complete = function () {
|
||
|
if (temp != null) {
|
||
|
temp();
|
||
|
}
|
||
|
layer.close(index);
|
||
|
};
|
||
|
|
||
|
var tempSuccess = option.success;
|
||
|
option.success = function (resp) {
|
||
|
if (parent) {
|
||
|
if (parent.layer) {
|
||
|
// 父窗口 含有 layerd 对象 , 要关闭弹层
|
||
|
successExpr = successExpr || '1 == resp.dataList[0]';
|
||
|
try {
|
||
|
if (eval(successExpr)) {
|
||
|
t.find('button').each(function () {
|
||
|
var content = $(this).text().trim();
|
||
|
// 内容不为空
|
||
|
if (content) {
|
||
|
// 关闭 frame 字段,不需要 禁用
|
||
|
if (content == '返回' || content == '关闭' || content == '取消') {
|
||
|
// nothing to do 什么也不做
|
||
|
} else {
|
||
|
// 禁用按钮
|
||
|
$(this).attr('disabled', 'disabled');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
} catch (e) {
|
||
|
console.log('返回结果判断表达式错误!表达式:' + successExpr + ' , ' + e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
tempSuccess(resp);
|
||
|
};
|
||
|
|
||
|
$(this).ajaxSubmit(option);
|
||
|
},
|
||
|
disableButtons: function () {
|
||
|
|
||
|
},
|
||
|
renderTable: function (option) {
|
||
|
|
||
|
var opt = option || {};
|
||
|
|
||
|
var t = $(this);
|
||
|
t.opt = opt;
|
||
|
var clazz = 'focus';
|
||
|
t.find('tr').click(function () {
|
||
|
if (opt.checkbox == true) {
|
||
|
|
||
|
var checkbox = $(this).find('input[type=checkbox]')[0];
|
||
|
$(this).toggleClass(clazz);
|
||
|
if ($(this).hasClass(clazz)) {
|
||
|
checkbox.checked = true;
|
||
|
} else {
|
||
|
checkbox.checked = false;
|
||
|
}
|
||
|
} else {
|
||
|
t.find('tr.' + clazz).removeClass(clazz);
|
||
|
$(this).addClass(clazz);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
t.find('tr input[type=checkbox]').change(function () {
|
||
|
var tr = $(this).parents('tr');
|
||
|
if (this.checked) {
|
||
|
if (!tr.hasClass(clazz)) {
|
||
|
tr.addClass(clazz);
|
||
|
}
|
||
|
} else {
|
||
|
tr.removeClass(clazz);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
selectAll: function () {
|
||
|
var opt = $(this).opt;
|
||
|
var clazz = 'focus';
|
||
|
$(this).find('tr').each(function () {
|
||
|
if (!$(this).hasClass(clazz)) {
|
||
|
$(this).addClass(clazz);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
cancelAll: function () {
|
||
|
var opt = $(this).opt;
|
||
|
var clazz = 'focus';
|
||
|
$(this).find('tr.' + clazz).each(function () {
|
||
|
if ($(this).hasClass(clazz)) {
|
||
|
$(this).removeClass(clazz);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|