Merge pull request !14 from Vivian/dev-IW4W7

This commit is contained in:
Argo 2019-05-05 12:01:23 +08:00
commit 70089b8348
8 changed files with 68 additions and 22 deletions

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess; using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Web; using Longbow.Web;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
@ -21,17 +22,10 @@ namespace Bootstrap.Admin.Controllers.Api
/// <summary> /// <summary>
/// 获得登录历史记录 /// 获得登录历史记录
/// </summary> /// </summary>
/// <param name="po"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public QueryData<LoginUser> Get([FromQuery]PaginationOption po) public QueryData<LoginUser> Get([FromQuery]QueryLoginOption value) => value.RetrieveData();
{
var data = LoginHelper.Retrieves(po);
var ret = new QueryData<LoginUser>();
ret.total = data.TotalItems;
ret.rows = data.Items;
return ret;
}
/// <summary> /// <summary>
/// ///

View File

@ -0,0 +1,30 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
namespace Bootstrap.Admin.Query
{
/// <summary>
/// 登录日志查询条件
/// </summary>
public class QueryLoginOption : PaginationOption
{
/// <summary>
/// 登录IP地址
/// </summary>
public string LoginIP { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<LoginUser> RetrieveData()
{
var data = LoginHelper.Retrieves(this, LoginIP);
return new QueryData<LoginUser>
{
total = data.TotalItems,
rows = data.Items
};
}
}
}

View File

@ -22,8 +22,26 @@
<script src="~/js/logins.js" asp-append-version="true"></script> <script src="~/js/logins.js" asp-append-version="true"></script>
} }
<div class="card"> <div class="card">
<div class="card-header">登录用户<span class="pull-right"><a id="refreshUsers" href="javascript:;" class="fa fa-refresh" title="点击刷新" data-toggle="tooltip" data-placement="left"></a></span></div> <div class="card-header">查询条件</div>
<div class="card-body" style="padding-top: 25px;"> <div class="card-body">
<form class="form-inline">
<div class="row">
<div class="form-group col-sm-6 col-md-auto">
<label class="control-label" for="txt_ip">请求IP</label>
<input type="text" class="form-control" id="txt_ip" />
</div>
<div class="form-group col-sm-6 col-md-auto flex-md-fill justify-content-md-end">
<button type="button" id="btn_query" class="btn btn-primary btn-fill"><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>
</div>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-header">
查询结果
</div>
<div class="card-body">
<table></table> <table></table>
</div> </div>
</div> </div>

View File

@ -16,7 +16,7 @@
} }
}, },
"SwaggerPathBase": "", "SwaggerPathBase": "",
"AllowOrigins": "http://localhost:49823", "AllowOrigins": "http://localhost:49185",
"KeyPath": "..\\keys", "KeyPath": "..\\keys",
"DisableAutomaticKeyGeneration": false, "DisableAutomaticKeyGeneration": false,
"LongbowCache": { "LongbowCache": {

View File

@ -6,6 +6,7 @@ $(function () {
showToggle: false, showToggle: false,
showRefresh: false, showRefresh: false,
showColumns: false, showColumns: false,
queryParams: function (params) { return $.extend(params, { loginIp: $('#txt_ip').val() }); },
columns: [ columns: [
{ {
title: "序号", formatter: function (value, row, index) { title: "序号", formatter: function (value, row, index) {
@ -28,8 +29,4 @@ $(function () {
} }
] ]
}); });
$('#refreshUsers').tooltip().on('click', function () {
$table.bootstrapTable('refresh');
});
}); });

View File

@ -2,7 +2,6 @@
using MongoDB.Driver; using MongoDB.Driver;
using PetaPoco; using PetaPoco;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Bootstrap.DataAccess.MongoDB namespace Bootstrap.DataAccess.MongoDB
@ -28,10 +27,10 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary> /// </summary>
/// <param name="po"></param> /// <param name="po"></param>
/// <returns></returns> /// <returns></returns>
public override Page<DataAccess.LoginUser> Retrieves(PaginationOption po) public override Page<DataAccess.LoginUser> Retrieves(PaginationOption po, string ip)
{ {
var logs = DbManager.LoginUsers var logs = DbManager.LoginUsers
.Find(Builders<DataAccess.LoginUser>.Filter.Empty) .Find(Builders<DataAccess.LoginUser>.Filter.Eq("Ip", ip))
.Sort(Builders<DataAccess.LoginUser>.Sort.Descending(t => t.LoginTime)) .Sort(Builders<DataAccess.LoginUser>.Sort.Descending(t => t.LoginTime))
.ToList(); .ToList();

View File

@ -20,6 +20,7 @@ namespace Bootstrap.DataAccess
/// 查询所有登录日志 /// 查询所有登录日志
/// </summary> /// </summary>
/// <param name="po"></param> /// <param name="po"></param>
public static Page<LoginUser> Retrieves(PaginationOption po) => DbContextManager.Create<LoginUser>().Retrieves(po); /// <param name="ip"></param>
public static Page<LoginUser> Retrieves(PaginationOption po, string ip) => DbContextManager.Create<LoginUser>().Retrieves(po, ip);
} }
} }

View File

@ -71,7 +71,14 @@ namespace Bootstrap.DataAccess
/// ///
/// </summary> /// </summary>
/// <param name="po"></param> /// <param name="po"></param>
/// <param name="ip"></param>
/// <returns></returns> /// <returns></returns>
public virtual Page<LoginUser> Retrieves(PaginationOption po) => DbManager.Create().Page<LoginUser>(po.PageIndex, po.Limit, "select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs Order by LoginTime desc"); public virtual Page<LoginUser> 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<LoginUser>(po.PageIndex, po.Limit, sql);
}
} }
} }