From 7bc0b452a7d6d64c750646c116d0acb300f948ed Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 4 May 2019 16:44:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(#IW4W7):=20=E7=99=BB=E5=BD=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=A2=9E=E5=8A=A0IP=E5=9C=B0=E5=9D=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit comment #IW4W7 close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IW4W7 --- .../Controllers/Api/LoginController.cs | 14 +++------ Bootstrap.Admin/Query/QueryLoginOption.cs | 30 +++++++++++++++++++ Bootstrap.Admin/Views/Admin/Logins.cshtml | 22 ++++++++++++-- Bootstrap.Admin/wwwroot/js/logins.js | 5 +--- Bootstrap.DataAccess.MongoDB/LoginUser.cs | 5 ++-- Bootstrap.DataAccess/Helper/LoginHelper.cs | 3 +- Bootstrap.DataAccess/LoginUser.cs | 9 +++++- 7 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 Bootstrap.Admin/Query/QueryLoginOption.cs diff --git a/Bootstrap.Admin/Controllers/Api/LoginController.cs b/Bootstrap.Admin/Controllers/Api/LoginController.cs index 20500945..0ea0bcfd 100644 --- a/Bootstrap.Admin/Controllers/Api/LoginController.cs +++ b/Bootstrap.Admin/Controllers/Api/LoginController.cs @@ -1,4 +1,5 @@ -using Bootstrap.DataAccess; +using Bootstrap.Admin.Query; +using Bootstrap.DataAccess; using Bootstrap.Security; using Longbow.Web; using Longbow.Web.Mvc; @@ -21,17 +22,10 @@ namespace Bootstrap.Admin.Controllers.Api /// /// 获得登录历史记录 /// - /// + /// /// [HttpGet] - public QueryData Get([FromQuery]PaginationOption po) - { - var data = LoginHelper.Retrieves(po); - var ret = new QueryData(); - ret.total = data.TotalItems; - ret.rows = data.Items; - return ret; - } + public QueryData Get([FromQuery]QueryLoginOption value) => value.RetrieveData(); /// /// diff --git a/Bootstrap.Admin/Query/QueryLoginOption.cs b/Bootstrap.Admin/Query/QueryLoginOption.cs new file mode 100644 index 00000000..ea7e61c6 --- /dev/null +++ b/Bootstrap.Admin/Query/QueryLoginOption.cs @@ -0,0 +1,30 @@ +using Bootstrap.DataAccess; +using Longbow.Web.Mvc; + +namespace Bootstrap.Admin.Query +{ + /// + /// 登录日志查询条件 + /// + public class QueryLoginOption : PaginationOption + { + /// + /// 登录IP地址 + /// + public string LoginIP { get; set; } + + /// + /// + /// + /// + public QueryData RetrieveData() + { + var data = LoginHelper.Retrieves(this, LoginIP); + return new QueryData + { + total = data.TotalItems, + rows = data.Items + }; + } + } +} diff --git a/Bootstrap.Admin/Views/Admin/Logins.cshtml b/Bootstrap.Admin/Views/Admin/Logins.cshtml index 3b6fc20d..168a687e 100644 --- a/Bootstrap.Admin/Views/Admin/Logins.cshtml +++ b/Bootstrap.Admin/Views/Admin/Logins.cshtml @@ -22,8 +22,26 @@ }
-
登录用户
-
+
查询条件
+
+
+
+
+ + +
+
+ +
+
+
+
+
+
+
+ 查询结果 +
+
\ No newline at end of file diff --git a/Bootstrap.Admin/wwwroot/js/logins.js b/Bootstrap.Admin/wwwroot/js/logins.js index de563242..db578bc6 100644 --- a/Bootstrap.Admin/wwwroot/js/logins.js +++ b/Bootstrap.Admin/wwwroot/js/logins.js @@ -6,6 +6,7 @@ $(function () { showToggle: false, showRefresh: false, showColumns: false, + queryParams: function (params) { return $.extend(params, { loginIp: $('#txt_ip').val() }); }, columns: [ { title: "序号", formatter: function (value, row, index) { @@ -28,8 +29,4 @@ $(function () { } ] }); - - $('#refreshUsers').tooltip().on('click', function () { - $table.bootstrapTable('refresh'); - }); }); \ No newline at end of file diff --git a/Bootstrap.DataAccess.MongoDB/LoginUser.cs b/Bootstrap.DataAccess.MongoDB/LoginUser.cs index 661d9f57..2cb54140 100644 --- a/Bootstrap.DataAccess.MongoDB/LoginUser.cs +++ b/Bootstrap.DataAccess.MongoDB/LoginUser.cs @@ -2,7 +2,6 @@ using MongoDB.Driver; using PetaPoco; using System; -using System.Collections.Generic; using System.Linq; namespace Bootstrap.DataAccess.MongoDB @@ -28,10 +27,10 @@ namespace Bootstrap.DataAccess.MongoDB ///
/// /// - public override Page Retrieves(PaginationOption po) + public override Page Retrieves(PaginationOption po, string ip) { var logs = DbManager.LoginUsers - .Find(Builders.Filter.Empty) + .Find(Builders.Filter.Eq("Ip", ip)) .Sort(Builders.Sort.Descending(t => t.LoginTime)) .ToList(); diff --git a/Bootstrap.DataAccess/Helper/LoginHelper.cs b/Bootstrap.DataAccess/Helper/LoginHelper.cs index 477a76b8..1a24a483 100644 --- a/Bootstrap.DataAccess/Helper/LoginHelper.cs +++ b/Bootstrap.DataAccess/Helper/LoginHelper.cs @@ -20,6 +20,7 @@ namespace Bootstrap.DataAccess /// 查询所有登录日志 /// /// - public static Page Retrieves(PaginationOption po) => DbContextManager.Create().Retrieves(po); + /// + public static Page Retrieves(PaginationOption po, string ip) => DbContextManager.Create().Retrieves(po, ip); } } diff --git a/Bootstrap.DataAccess/LoginUser.cs b/Bootstrap.DataAccess/LoginUser.cs index b9e83e88..3b2847a0 100644 --- a/Bootstrap.DataAccess/LoginUser.cs +++ b/Bootstrap.DataAccess/LoginUser.cs @@ -71,7 +71,14 @@ namespace Bootstrap.DataAccess /// /// /// + /// /// - public virtual Page Retrieves(PaginationOption po) => DbManager.Create().Page(po.PageIndex, po.Limit, "select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs Order by LoginTime desc"); + public virtual Page Retrieves(PaginationOption po, string ip) + { + var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs"); + if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip); + sql.OrderBy("LoginTime desc"); + return DbManager.Create().Page(po.PageIndex, po.Limit, sql); + } } }