重构代码:所有脚本移除数据保存/删除后swal的操作提示,统一使用toastr提示

This commit is contained in:
Argo-MacBookPro 2018-09-09 01:48:00 +08:00
parent b64a5a80f3
commit d2784fec55
14 changed files with 50 additions and 71 deletions

View File

@ -39,10 +39,9 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="value"></param>
[HttpDelete]
[Authorize(Roles = "Administrators")]
public object Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<int> value)
{
var result = DictHelper.DeleteDict(value);
return new { result, msg = result ? "成功!" : "失败" };
return DictHelper.DeleteDict(value);
}
}
}

View File

@ -24,7 +24,7 @@
nestMenu: function (callback) {
var $this = $(this);
$.bc({
id: 0, url: Menu.url, data: { type: "user" }, swal: false,
id: 0, url: Menu.url, data: { type: "user" },
callback: function (result) {
var html = "";
if ($.isArray(result)) html = cascadeMenu(result);
@ -47,7 +47,6 @@
var that = this;
$.bc({
url: Notifications.url,
swal: false,
method: 'GET',
callback: function (result) {
$('#logoutNoti').text(result.NewUsersCount === 0 ? "" : result.NewUsersCount);

View File

@ -24,7 +24,7 @@
// autocomplete
$.bc({
url: "api/Category", swal: false, method: 'get',
url: "api/Category", method: 'get',
callback: function (result) {
var data = result.map(function (ele, index) { return ele.Category; });
$('#txt_dict_cate').typeahead({

View File

@ -36,7 +36,7 @@
$('#btn_view').on('click', function (row) {
$.bc({
url: Exceptions.url, swal: false,
url: Exceptions.url,
callback: function (result) {
var html = result.map(function (ele) {
return $.format('<div class="form-group col-lg-3 col-md-3 col-sm-4 col-6"><a class="logfile" data-toggle="tooltip" title="{0}" href="#"><i class="fa fa-file-text-o"></i><span>{0}</span></a></div>', ele);
@ -54,7 +54,7 @@
$errorDetail.show();
$dataFormDetail.html('<div class="text-center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>');
$.bc({
url: Exceptions.url, method: "PUT", swal: false, data: { FileName: fileName },
url: Exceptions.url, method: "PUT", data: { FileName: fileName },
callback: function (result) {
$dataFormDetail.html(result);
}

View File

@ -17,7 +17,7 @@
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "group" }, swal: false,
id: row.Id, url: Role.url, data: { type: "group" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -33,7 +33,7 @@
},
'#btn_assignUser': function (row) {
$.bc({
id: row.Id, url: User.url, data: { type: "group" }, swal: false,
id: row.Id, url: User.url, data: { type: "group" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -52,14 +52,14 @@
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: groupId, url: Role.url, method: "PUT", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
$.bc({ id: groupId, url: Role.url, method: "PUT", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: '#dialogRole', info: true });
},
'#btnSubmitUser': function (row) {
var groupId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: groupId, url: User.url, method: "PUT", data: { type: "group", userIds: userIds }, title: User.title, modal: '#dialogUser' });
$.bc({ id: groupId, url: User.url, method: "PUT", data: { type: "group", userIds: userIds }, title: User.title, modal: '#dialogUser', info: true });
}
}
},

View File

@ -17,7 +17,6 @@
url: 'api/New',
data: { UserName: $('#userName').val(), Password: $('#password').val(), DisplayName: $('#displayName').val(), Description: $('#description').val() },
modal: '#dialogNew',
swal: false,
callback: function (result) {
var title = result ? "提交成功<br/>等待管理员审批" : "提交失败";
swal({ html: true, showConfirmButton: false, showCancelButton: false, timer: 1500, title: title, type: result ? "success" : "error" });

View File

@ -122,18 +122,17 @@
method: "post",
htmlTemplate: '<div class="form-group col-md-3 col-sm-4 col-6"><div class="form-check"><label class="form-check-label" title="{3}" data-toggle="tooltip"><input type="checkbox" class="form-check-input" value="{0}" {2}/><span>{1}</span></label></div></div>',
title: "",
swal: true,
modal: null,
loading: false,
loadingTimeout: 10000,
callback: null,
$element: null,
async: true,
toastr: false
info: false
}, options);
if (!options.url || options.url === "") {
lgbSwal({ title: '参数错误', text: '未设置请求地址Url', type: 'error' });
toastr.error('参数错误: 未设置请求地址Url');
return;
}
@ -160,31 +159,21 @@
success(result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (options.toastr && toastr) {
options.toastr = $.extend({ msg: "未设置", title: "系统错误" }, options.toastr);
toastr.error(options.toastr.msg, options.toastr.title);
}
success(false);
}
});
}
function success(result) {
var interval = 10;
if ($.isFunction(options.callback)) {
options.callback.call(options.$element === null ? options : options.$element, result);
}
if (options.modal !== null && (result || options.loading)) {
$(options.modal).modal('hide');
interval = 400;
}
window.setTimeout(function () {
if (options.swal) {
lgbSwal({ title: options.title + (result ? "成功" : "失败"), type: result ? 'success' : 'error' });
}
if ($.isFunction(callback)) {
callback.call(options.$element === null ? this : options.$element);
}
}, interval);
if (options.info) toastr[result ? 'success' : 'error'](options.title + (result ? "成功" : "失败"));
if ($.isFunction(callback)) {
callback.call(options.$element === null ? this : options.$element);
}
}
},
lgbSwal: function (options) {
@ -274,7 +263,14 @@
editField: "Id",
queryButton: false
}, options.smartTable);
if (settings.edit) settings.columns.unshift({ title: settings.editTitle, field: settings.editField, events: bsa.idEvents(), formatter: DataTable.idFormatter });
if (settings.edit) settings.columns.unshift({
title: settings.editTitle,
field: settings.editField,
events: bsa.idEvents(),
formatter: function (value, row, index) {
return "<a class='edit' title='" + value + "' href='javascript:void(0)'>" + this.title + "</a>";
}
});
if (settings.checkbox) settings.columns.unshift({ checkbox: true });
return this.smartTable(settings);
},
@ -329,8 +325,6 @@
$.bc({
url: uri,
id: this.sendMessage,
swal: false,
toastr: false,
callback: function (result) {
if (!result) {
that.errorHandler.call(that.target);

View File

@ -145,10 +145,6 @@
$.bc({
url: options.url, data: iDs, method: 'DELETE', title: '删除数据',
callback: function (result) {
if ($.isPlainObject(result)) {
lgbSwal({ title: result.msg, type: result.result ? "success" : "error" });
result = result.result;
}
if (result) $(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, null, element, { oper: 'del', success: result });
}
@ -162,7 +158,7 @@
var that = this;
var options = $.extend(true, {}, this.options, { data: this.dataEntity.get() });
$.bc({
url: options.url, data: options.data, title: "保存数据", modal: options.modal,
url: options.url, data: options.data, title: "保存数据", modal: options.modal, info: true,
callback: function (result) {
if (result) {
var finalData = null;
@ -194,10 +190,6 @@
}
};
DataTable.idFormatter = function (value, row, index) {
return "<a class='edit' title='" + value + "' href='javascript:void(0)'>编辑</a>";
};
DataTable.prototype = {
constructor: DataTable,
idEvents: function () {

View File

@ -42,7 +42,7 @@
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "menu" }, swal: false,
id: row.Id, url: Role.url, data: { type: "menu" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -61,7 +61,7 @@
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: menuId, url: Role.url, method: "PUT", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
$.bc({ id: menuId, url: Role.url, method: "PUT", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: '#dialogRole', info: true });
}
},
callback: function (result) {
@ -235,7 +235,6 @@
$.bc({
url: Menu.iconView,
swal: false,
contentType: 'text/html',
dataType: 'html',
method: 'GET',

View File

@ -2,7 +2,7 @@
function loadData() {
$.bc({
url: Messages.url, method: 'GET', swal: false,
url: Messages.url, method: 'GET',
callback: function (result) {
if (result) {
$('#s_inbox').text(result.inboxCount);
@ -18,19 +18,19 @@
function listData(options) {
$.bc({
id: options.id, url: Messages.url, method: 'GET', swal: false,
id: options.id, url: Messages.url, method: 'GET',
callback: function (result) {
if (result) {
var content = result.map(function (mail) {
if (mail.Status == '0')
if (mail.Status === '0')
mailStatus = 'class="unread"';
else
mailStatus = " "
if (mail.Mark == '1')
mailStatus = " ";
if (mail.Mark === '1')
mailMark = "inbox-started";
else
mailMark = " ";
if (mail.Label == '0')
if (mail.Label === '0')
mailLabel = 'label-success';
else
mailLabel = 'label-warning';
@ -47,5 +47,5 @@
$('#mailBox').on('click', 'a', function () {
listData({ Id: $(this).attr('data-id') });
})
});
});

View File

@ -23,7 +23,7 @@
events: {
'#btn_assignUser': function (row) {
$.bc({
id: row.Id, url: User.url, data: { type: "role" }, swal: false,
id: row.Id, url: User.url, data: { type: "role" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -39,7 +39,7 @@
},
'#btn_assignGroup': function (row) {
$.bc({
id: row.Id, url: Group.url, data: { type: "role" }, swal: false,
id: row.Id, url: Group.url, data: { type: "role" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -55,7 +55,7 @@
},
'#btn_assignMenu': function (row) {
$.bc({
id: row.Id, url: Menu.url, data: { type: "role" }, swal: false,
id: row.Id, url: Menu.url, data: { type: "role" },
callback: function (result) {
$dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName));
$btnSubmitMenu.data('type', 'menu');
@ -76,14 +76,14 @@
var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: roleId, url: User.url, method: "PUT", data: { type: "role", userIds: userIds }, modal: '#dialogUser', title: User.title });
$.bc({ id: roleId, url: User.url, method: "PUT", data: { type: "role", userIds: userIds }, modal: '#dialogUser', title: User.title, info: true });
},
'#btnSubmitGroup': function (row) {
var roleId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: roleId, url: Group.url, method: "PUT", data: { type: "role", groupIds: groupIds }, modal: '#dialogGroup', title: Group.title });
$.bc({ id: roleId, url: Group.url, method: "PUT", data: { type: "role", groupIds: groupIds }, modal: '#dialogGroup', title: Group.title, info: true });
},
'#btnSubmitMenu': function (row) {
var roleId = row.Id;
@ -97,7 +97,7 @@
default:
break;
}
$.bc({ id: roleId, url: Menu.url, method: "PUT", data: { type: "role", menuIds: menuIds }, modal: '#dialogMenu', title: Menu.title });
$.bc({ id: roleId, url: Menu.url, method: "PUT", data: { type: "role", menuIds: menuIds }, modal: '#dialogMenu', title: Menu.title, info: true });
}
}
},

View File

@ -51,7 +51,6 @@
$.bc({
url: Settings.url,
method: 'GET',
swal: false,
callback: function (urls) {
if (urls && $.isArray(urls)) {
$.each(urls, function (index, item) {
@ -62,7 +61,6 @@
xhrFields: {
withCredentials: true
},
swal: false,
callback: function (result) {
if ($.isArray(result)) {
var html = '<div class="cache-item"><i class="fa fa-ellipsis-v"></i><div><span data-toggle="tooltip" title="{2}">{2}</span><span class="badge badge-pill badge-success">{0}</span></div><span title="{3}">{3}</span><div><span>{7}</span><button class="btn btn-danger" title="{1}" data-url="{5}?cacheKey={1}" data-toggle="tooltip" data-self="{6}" data-placement="left"><i class="fa fa-trash-o"></i></button></div></div>';
@ -75,7 +73,7 @@
$sortable.append(content);
$sortable.find('[data-toggle="tooltip"]').tooltip();
}
if (index == urls.length - 1) $refresh.removeClass('fa-spin');
if (index === urls.length - 1) $refresh.removeClass('fa-spin');
}
});
});
@ -83,15 +81,14 @@
else $refresh.removeClass('fa-spin');
}
});
}
};
var listCache = function (options) {
$.bc({
url: options.url,
xhrFields: {
withCredentials: true
},
swal: false
}
});
};
$('a[data-method]').on('click', function (e) {
@ -115,4 +112,4 @@
});
var $css = $('#dictCssDefine').dropdown('val');
})
});

View File

@ -7,7 +7,7 @@
var that = $(this);
that.toggleClass('fa-spin');
$.bc({
url: Tasks.url, method: 'GET', swal: false,
url: Tasks.url, method: 'GET',
callback: function (result) {
if (result) {
var content = result.map(function (task) {

View File

@ -19,7 +19,7 @@
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "user" }, swal: false,
id: row.Id, url: Role.url, data: { type: "user" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -35,7 +35,7 @@
},
'#btn_assignGroup': function (row) {
$.bc({
id: row.Id, url: Group.url, data: { type: "user" }, swal: false,
id: row.Id, url: Group.url, data: { type: "user" },
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
@ -54,14 +54,14 @@
var roleIds = $dialogRole.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: userId, url: Role.url, method: 'PUT', data: { type: "user", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
$.bc({ id: userId, url: Role.url, method: 'PUT', data: { type: "user", roleIds: roleIds }, title: Role.title, info: true, modal: '#dialogRole' });
},
'#btnSubmitGroup': function (row) {
var userId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: userId, url: Group.url, method: 'PUT', data: { type: "user", groupIds: groupIds }, title: Group.title, modal: '#dialogGroup' });
$.bc({ id: userId, url: Group.url, method: 'PUT', data: { type: "user", groupIds: groupIds }, title: Group.title, info: true, modal: '#dialogGroup' });
}
},
callback: function (data) {