重构代码:所有脚本移除数据保存/删除后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> /// <param name="value"></param>
[HttpDelete] [HttpDelete]
[Authorize(Roles = "Administrators")] [Authorize(Roles = "Administrators")]
public object Delete([FromBody]IEnumerable<int> value) public bool Delete([FromBody]IEnumerable<int> value)
{ {
var result = DictHelper.DeleteDict(value); return DictHelper.DeleteDict(value);
return new { result, msg = result ? "成功!" : "失败" };
} }
} }
} }

View File

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

View File

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

View File

@ -36,7 +36,7 @@
$('#btn_view').on('click', function (row) { $('#btn_view').on('click', function (row) {
$.bc({ $.bc({
url: Exceptions.url, swal: false, url: Exceptions.url,
callback: function (result) { callback: function (result) {
var html = result.map(function (ele) { 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); 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(); $errorDetail.show();
$dataFormDetail.html('<div class="text-center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>'); $dataFormDetail.html('<div class="text-center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>');
$.bc({ $.bc({
url: Exceptions.url, method: "PUT", swal: false, data: { FileName: fileName }, url: Exceptions.url, method: "PUT", data: { FileName: fileName },
callback: function (result) { callback: function (result) {
$dataFormDetail.html(result); $dataFormDetail.html(result);
} }

View File

@ -17,7 +17,7 @@
events: { events: {
'#btn_assignRole': function (row) { '#btn_assignRole': function (row) {
$.bc({ $.bc({
id: row.Id, url: Role.url, data: { type: "group" }, swal: false, id: row.Id, url: Role.url, data: { type: "group" },
callback: function (result) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -33,7 +33,7 @@
}, },
'#btn_assignUser': function (row) { '#btn_assignUser': function (row) {
$.bc({ $.bc({
id: row.Id, url: User.url, data: { type: "group" }, swal: false, id: row.Id, url: User.url, data: { type: "group" },
callback: function (result) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -52,14 +52,14 @@
var roleIds = $dialogRole.find('input:checked').map(function (index, element) { var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).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) { '#btnSubmitUser': function (row) {
var groupId = row.Id; var groupId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) { var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).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', url: 'api/New',
data: { UserName: $('#userName').val(), Password: $('#password').val(), DisplayName: $('#displayName').val(), Description: $('#description').val() }, data: { UserName: $('#userName').val(), Password: $('#password').val(), DisplayName: $('#displayName').val(), Description: $('#description').val() },
modal: '#dialogNew', modal: '#dialogNew',
swal: false,
callback: function (result) { callback: function (result) {
var title = result ? "提交成功<br/>等待管理员审批" : "提交失败"; var title = result ? "提交成功<br/>等待管理员审批" : "提交失败";
swal({ html: true, showConfirmButton: false, showCancelButton: false, timer: 1500, title: title, type: result ? "success" : "error" }); swal({ html: true, showConfirmButton: false, showCancelButton: false, timer: 1500, title: title, type: result ? "success" : "error" });

View File

@ -122,18 +122,17 @@
method: "post", 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>', 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: "", title: "",
swal: true,
modal: null, modal: null,
loading: false, loading: false,
loadingTimeout: 10000, loadingTimeout: 10000,
callback: null, callback: null,
$element: null, $element: null,
async: true, async: true,
toastr: false info: false
}, options); }, options);
if (!options.url || options.url === "") { if (!options.url || options.url === "") {
lgbSwal({ title: '参数错误', text: '未设置请求地址Url', type: 'error' }); toastr.error('参数错误: 未设置请求地址Url');
return; return;
} }
@ -160,31 +159,21 @@
success(result); success(result);
}, },
error: function (XMLHttpRequest, textStatus, errorThrown) { 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); success(false);
} }
}); });
} }
function success(result) { function success(result) {
var interval = 10;
if ($.isFunction(options.callback)) { if ($.isFunction(options.callback)) {
options.callback.call(options.$element === null ? options : options.$element, result); options.callback.call(options.$element === null ? options : options.$element, result);
} }
if (options.modal !== null && (result || options.loading)) { if (options.modal !== null && (result || options.loading)) {
$(options.modal).modal('hide'); $(options.modal).modal('hide');
interval = 400;
} }
window.setTimeout(function () { if (options.info) toastr[result ? 'success' : 'error'](options.title + (result ? "成功" : "失败"));
if (options.swal) { if ($.isFunction(callback)) {
lgbSwal({ title: options.title + (result ? "成功" : "失败"), type: result ? 'success' : 'error' }); callback.call(options.$element === null ? this : options.$element);
} }
if ($.isFunction(callback)) {
callback.call(options.$element === null ? this : options.$element);
}
}, interval);
} }
}, },
lgbSwal: function (options) { lgbSwal: function (options) {
@ -274,7 +263,14 @@
editField: "Id", editField: "Id",
queryButton: false queryButton: false
}, options.smartTable); }, 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 }); if (settings.checkbox) settings.columns.unshift({ checkbox: true });
return this.smartTable(settings); return this.smartTable(settings);
}, },
@ -329,8 +325,6 @@
$.bc({ $.bc({
url: uri, url: uri,
id: this.sendMessage, id: this.sendMessage,
swal: false,
toastr: false,
callback: function (result) { callback: function (result) {
if (!result) { if (!result) {
that.errorHandler.call(that.target); that.errorHandler.call(that.target);

View File

@ -145,10 +145,6 @@
$.bc({ $.bc({
url: options.url, data: iDs, method: 'DELETE', title: '删除数据', url: options.url, data: iDs, method: 'DELETE', title: '删除数据',
callback: function (result) { callback: function (result) {
if ($.isPlainObject(result)) {
lgbSwal({ title: result.msg, type: result.result ? "success" : "error" });
result = result.result;
}
if (result) $(options.bootstrapTable).bootstrapTable('refresh'); if (result) $(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, null, element, { oper: 'del', success: result }); handlerCallback.call(that, null, element, { oper: 'del', success: result });
} }
@ -162,7 +158,7 @@
var that = this; var that = this;
var options = $.extend(true, {}, this.options, { data: this.dataEntity.get() }); var options = $.extend(true, {}, this.options, { data: this.dataEntity.get() });
$.bc({ $.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) { callback: function (result) {
if (result) { if (result) {
var finalData = null; 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 = { DataTable.prototype = {
constructor: DataTable, constructor: DataTable,
idEvents: function () { idEvents: function () {

View File

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

View File

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

View File

@ -23,7 +23,7 @@
events: { events: {
'#btn_assignUser': function (row) { '#btn_assignUser': function (row) {
$.bc({ $.bc({
id: row.Id, url: User.url, data: { type: "role" }, swal: false, id: row.Id, url: User.url, data: { type: "role" },
callback: function (result) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -39,7 +39,7 @@
}, },
'#btn_assignGroup': function (row) { '#btn_assignGroup': function (row) {
$.bc({ $.bc({
id: row.Id, url: Group.url, data: { type: "role" }, swal: false, id: row.Id, url: Group.url, data: { type: "role" },
callback: function (result) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -55,7 +55,7 @@
}, },
'#btn_assignMenu': function (row) { '#btn_assignMenu': function (row) {
$.bc({ $.bc({
id: row.Id, url: Menu.url, data: { type: "role" }, swal: false, id: row.Id, url: Menu.url, data: { type: "role" },
callback: function (result) { callback: function (result) {
$dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName)); $dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName));
$btnSubmitMenu.data('type', 'menu'); $btnSubmitMenu.data('type', 'menu');
@ -76,14 +76,14 @@
var userIds = $dialogUser.find(':checked').map(function (index, element) { var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).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) { '#btnSubmitGroup': function (row) {
var roleId = row.Id; var roleId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) { var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).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) { '#btnSubmitMenu': function (row) {
var roleId = row.Id; var roleId = row.Id;
@ -97,7 +97,7 @@
default: default:
break; 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({ $.bc({
url: Settings.url, url: Settings.url,
method: 'GET', method: 'GET',
swal: false,
callback: function (urls) { callback: function (urls) {
if (urls && $.isArray(urls)) { if (urls && $.isArray(urls)) {
$.each(urls, function (index, item) { $.each(urls, function (index, item) {
@ -62,7 +61,6 @@
xhrFields: { xhrFields: {
withCredentials: true withCredentials: true
}, },
swal: false,
callback: function (result) { callback: function (result) {
if ($.isArray(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>'; 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.append(content);
$sortable.find('[data-toggle="tooltip"]').tooltip(); $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'); else $refresh.removeClass('fa-spin');
} }
}); });
} };
var listCache = function (options) { var listCache = function (options) {
$.bc({ $.bc({
url: options.url, url: options.url,
xhrFields: { xhrFields: {
withCredentials: true withCredentials: true
}, }
swal: false
}); });
}; };
$('a[data-method]').on('click', function (e) { $('a[data-method]').on('click', function (e) {
@ -115,4 +112,4 @@
}); });
var $css = $('#dictCssDefine').dropdown('val'); var $css = $('#dictCssDefine').dropdown('val');
}) });

View File

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

View File

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