重构脚本:重写log.js逻辑,提高阅读质量

This commit is contained in:
Argo-MacBookPro 2018-09-09 13:58:31 +08:00
parent 1cc8b4d7fc
commit 5a0b028ae1
2 changed files with 40 additions and 44 deletions

View File

@ -1,59 +1,55 @@
(function ($) { (function ($) {
logPlugin = function (options) { var logPlugin = function (options) {
this.options = $.extend({}, logPlugin.settings, options); this.options = $.extend({}, logPlugin.settings, options);
var that = this;
for (var name in this.options.click) {
$(name).on('click', { handler: this.options.click[name] }, function (e) {
e.data.handler.call(that);
});
}
}; };
logPlugin.settings = { logPlugin.settings = {
url: 'api/Logs', url: 'api/Logs',
click: { click: {
query: '#btn_query', '#btn_delete': function () {
del: '#btn_delete', this.log({ crud: '删除' });
save: '#btnSubmit' },
'#btnSubmit': function () {
this.log({ crud: '保存' });
},
'#btnSubmitRole': function () {
this.log({ crud: '分配角色' });
},
'#btnSubmitGroup': function () {
this.log({ crud: '分配部门' });
},
'#btnSubmitUser': function () {
this.log({ crud: '分配用户' });
},
'#btnSubmitMenu': function () {
this.log({ crud: '分配菜单' });
}
} }
}; };
logPlugin.prototype = { logPlugin.prototype = {
constructor: logPlugin, constructor: logPlugin,
init: function () { log: function (data) {
var that = this; $.extend(data, { requestUrl: window.location.pathname });
// handler click event $.post({
for (name in this.options.click) { url: $.formatUrl(this.options.url),
var cId = this.options.click[name]; data: JSON.stringify(data),
var $source = $(cId); contentType: 'application/json',
$source.data('click', name); dataType: 'json'
$source.click(function () { });
var method = $(this).data('click');
logPlugin.prototype[method].call(that, this);
});
}
},
query: function (element) {
//log(this.options.url, { crud: '查询' });
},
save: function () {
log(this.options.url, { crud: '保存' });
},
del: function () {
log(this.options.url, { crud: '删除' });
} }
}; };
logPlugin.init = function (options) { $.extend({ logPlugin: function (options) { return new logPlugin(options); } });
var log = new logPlugin(options);
log.init();
};
var log = function (url, data) {
$.extend(data, { requestUrl: window.location.pathname });
$.post({
url: $.formatUrl(url),
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json'
});
};
})(jQuery); })(jQuery);
$(function () { $(function () {
logPlugin.init(); $.logPlugin();
}); });

View File

@ -394,26 +394,26 @@
// Roles // Roles
Role = { Role = {
url: 'api/Roles/', url: 'api/Roles/',
title: "授权角色" title: "分配角色"
}; };
// Users // Users
User = { User = {
url: 'api/Users/', url: 'api/Users/',
title: "授权用户" title: "分配用户"
}; };
// Groups // Groups
Group = { Group = {
url: 'api/Groups/', url: 'api/Groups/',
title: "授权部门" title: "分配部门"
}; };
// Menus // Menus
Menu = { Menu = {
url: 'api/Menus/', url: 'api/Menus/',
iconView: 'Admin/IconView', iconView: 'Admin/IconView',
title: "授权菜单" title: "分配菜单"
}; };
// Exceptions // Exceptions