From 6419ca64e7cb304f1b32ff2815c245baf2747f90 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sat, 5 Nov 2016 16:46:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0log=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=EF=BC=8C=E4=BD=BFlog=E5=85=A8=E5=B1=80=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Content/js/log.js | 56 ++++++++++++------- Bootstrap.Admin/Controllers/LogsController.cs | 1 - Bootstrap.Admin/Scripts/Logs.js | 1 - Bootstrap.Admin/Views/Shared/_Admin.cshtml | 1 - 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Bootstrap.Admin/Content/js/log.js b/Bootstrap.Admin/Content/js/log.js index a3e7cfa4..b118c429 100644 --- a/Bootstrap.Admin/Content/js/log.js +++ b/Bootstrap.Admin/Content/js/log.js @@ -1,22 +1,9 @@ (function ($) { - LogPlugin = function (options) { - var that = this; - this.options = $.extend({}, LogPlugin.settings, options); - - // handler click event - for (name in this.options.click) { - var cId = this.options.click[name]; - var source = $("#" + cId); - source.data('click', name); - source.click(function () { - var method = $(this).data('click'); - LogPlugin.prototype[method].call(that, this); - }); - } - + logPlugin = function (options) { + this.options = $.extend({}, logPlugin.settings, options); } - LogPlugin.settings = { + logPlugin.settings = { url: '../api/Logs', click: { query: 'btn_query', @@ -25,14 +12,43 @@ } } - LogPlugin.prototype = { - constructor: LogPlugin, + logPlugin.prototype = { + constructor: logPlugin, + init: function () { + var that = this; + // handler click event + for (name in this.options.click) { + var cId = this.options.click[name]; + var source = $("#" + cId); + source.data('click', name); + source.click(function () { + var method = $(this).data('click'); + logPlugin.prototype[method].call(that, this); + }); + } + }, query: function (element) { - log(this.options.url, { crud: 'Query' }); + //log(this.options.url, { crud: '查询' }); + }, + save: function () { + log(this.options.url, { crud: '保存' }); + }, + del: function () { + log(this.options.url, { crud: '删除' }); } } + logPlugin.init = function (options) { + var log = new logPlugin(options); + log.init(); + } + var log = function (url, data) { + $.extend(data, { requestUrl: window.location.pathname }); $.post(url, data); } -})(jQuery); \ No newline at end of file +})(jQuery); + +$(function () { + logPlugin.init(); +}); \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/LogsController.cs b/Bootstrap.Admin/Controllers/LogsController.cs index 3db5d7ab..76eb8b84 100644 --- a/Bootstrap.Admin/Controllers/LogsController.cs +++ b/Bootstrap.Admin/Controllers/LogsController.cs @@ -34,7 +34,6 @@ namespace Bootstrap.Admin.Controllers { var request = HttpContext.Current.Request; value.ClientAgent = request.UserAgent; - value.RequestUrl = request.Url.AbsolutePath; value.ClientIp = request.UserHostAddress; value.UserName = HttpContext.Current.User.Identity.Name; return LogHelper.SaveLog(value); diff --git a/Bootstrap.Admin/Scripts/Logs.js b/Bootstrap.Admin/Scripts/Logs.js index ac0ba73d..50cb0f2b 100644 --- a/Bootstrap.Admin/Scripts/Logs.js +++ b/Bootstrap.Admin/Scripts/Logs.js @@ -17,5 +17,4 @@ { title: "操作模块", field: "RequestUrl", sortable: false } ] }); - var log = new LogPlugin(); }); \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Shared/_Admin.cshtml b/Bootstrap.Admin/Views/Shared/_Admin.cshtml index 75b18e01..6d7bac14 100644 --- a/Bootstrap.Admin/Views/Shared/_Admin.cshtml +++ b/Bootstrap.Admin/Views/Shared/_Admin.cshtml @@ -16,7 +16,6 @@ - @RenderSection("Javascript", false)