From 693e07588c4aba62be20cad77278c46b462f8640 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 7 Mar 2020 19:22:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Client=20=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20Dummy=20=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Client.DataAccess/Dummy.cs | 43 ++++++++++ .../Helper/DummyHelper.cs | 47 +++++++++++ src/client/Bootstrap.Client/Client.db | Bin 0 -> 12288 bytes .../Controllers/Api/DummyController.cs | 40 +++++++++ .../Controllers/HomeController.cs | 6 ++ .../Query/QueryDummyOption.cs | 76 ++++++++++++++++++ .../Bootstrap.Client/Views/Home/Dummy.cshtml | 64 +++++++++++++++ .../appsettings.Development.json | 2 +- .../Bootstrap.Client/wwwroot/js/dummy.js | 32 ++++++++ 9 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 src/client/Bootstrap.Client.DataAccess/Dummy.cs create mode 100644 src/client/Bootstrap.Client.DataAccess/Helper/DummyHelper.cs create mode 100644 src/client/Bootstrap.Client/Client.db create mode 100644 src/client/Bootstrap.Client/Controllers/Api/DummyController.cs create mode 100644 src/client/Bootstrap.Client/Query/QueryDummyOption.cs create mode 100644 src/client/Bootstrap.Client/Views/Home/Dummy.cshtml create mode 100644 src/client/Bootstrap.Client/wwwroot/js/dummy.js diff --git a/src/client/Bootstrap.Client.DataAccess/Dummy.cs b/src/client/Bootstrap.Client.DataAccess/Dummy.cs new file mode 100644 index 00000000..940d9dc8 --- /dev/null +++ b/src/client/Bootstrap.Client.DataAccess/Dummy.cs @@ -0,0 +1,43 @@ +using PetaPoco; +using System.Collections.Generic; + +namespace Bootstrap.Client.DataAccess +{ + /// + /// 示例实体类 + /// + [TableName("Dummy")] + [PrimaryKey("Id", AutoIncrement = true)] + public class Dummy + { + /// + /// 获得/设置 数据库主键 ID 列值 + /// + public string? Id { get; set; } + + /// + /// 获得/设置 数据库 Item1 列 + /// + public string Item1 { get; set; } = ""; + + /// + /// 获得/设置 数据库 Item2 列 + /// + public string Item2 { get; set; } = ""; + + /// + /// 获得/设置 数据库 Item3 列 + /// + public int Item3 { get; set; } + + /// + /// 通过当前用户名获得所有菜单 + /// + /// + public virtual IEnumerable Retrieves() + { + using var db = DbManager.Create("client"); + return db.Fetch(); + } + } +} diff --git a/src/client/Bootstrap.Client.DataAccess/Helper/DummyHelper.cs b/src/client/Bootstrap.Client.DataAccess/Helper/DummyHelper.cs new file mode 100644 index 00000000..50a19727 --- /dev/null +++ b/src/client/Bootstrap.Client.DataAccess/Helper/DummyHelper.cs @@ -0,0 +1,47 @@ +using Longbow.Data; +using System.Collections.Generic; + +namespace Bootstrap.Client.DataAccess +{ + /// + /// 示例操作帮助类 + /// + public static class DummyHelper + { + /// + /// 获取数据库中所有 Dummy 表数据 + /// + /// + public static IEnumerable Retrieves() + { + // 此处启用智能切换数据库功能 + return DbContextManager.Create()?.Retrieves() ?? new Dummy[0]; + } + + /// + /// 保存 Dummy 实例到数据库中 + /// + /// + /// + public static bool Save(Dummy dummy) + { + // 此处未启用智能 + using var db = DbManager.Create("client"); + db.Save(dummy); + return true; + } + + /// + /// 删除指定 ID 的 Dummy 数据 + /// + /// + /// + public static bool Delete(IEnumerable ids) + { + // 此处使用指定 Sqlite 数据方法执行数据库操作 演示同一个程序操作多个数据库的场景 + using var db = DbManager.CreateSqlite("client"); + db.Delete("where Id in (@ids)", new { ids }); + return true; + } + } +} diff --git a/src/client/Bootstrap.Client/Client.db b/src/client/Bootstrap.Client/Client.db new file mode 100644 index 0000000000000000000000000000000000000000..0f6a8a837f483c7af0e370445405c6f8a57e75b9 GIT binary patch literal 12288 zcmeI&F-yZh6bJCTM4}xe;&QmXF{MSc(cRb{8f;^Yr;tgao**=p+H}yZ-_%dw=I%?R zgGF>L@_*#+@*a0b_-zkzdC`9?Ej>Iv7kNpc*b-8TBO)P$$HV2Z2+1#Ni-gxI|0_JP zdqA7K%kcx@zw(5D00bZa0SG_<0uX=z1Rwwb2&}Nc(D78OC9^WW9ogw*#7* + /// Dummy 表维护控制器 + /// + [Route("api/[controller]")] + [Authorize] + [ApiController] + public class DummyController : ControllerBase + { + /// + /// 获取所有 Dummy 表数据方法 + /// + /// + /// + [HttpGet] + public QueryData Get([FromQuery]QueryDummyOption value) => value.Retrieves(); + + /// + /// 保存方法 + /// + /// + [HttpPost] + public bool Post([FromBody]Dummy value) => DummyHelper.Save(value); + + /// + /// 删除指定 ID 集合的 Dummy 数据 + /// + /// + [HttpDelete] + public bool Delete([FromBody]IEnumerable value) => DummyHelper.Delete(value); + } +} diff --git a/src/client/Bootstrap.Client/Controllers/HomeController.cs b/src/client/Bootstrap.Client/Controllers/HomeController.cs index 43db5055..25717e70 100644 --- a/src/client/Bootstrap.Client/Controllers/HomeController.cs +++ b/src/client/Bootstrap.Client/Controllers/HomeController.cs @@ -23,6 +23,12 @@ namespace Bootstrap.Client.Controllers return View(new NavigatorBarModel(this)); } + /// + /// 演示视图 + /// + /// + public IActionResult Dummy() => View(new NavigatorBarModel(this)); + /// /// About 视图 /// diff --git a/src/client/Bootstrap.Client/Query/QueryDummyOption.cs b/src/client/Bootstrap.Client/Query/QueryDummyOption.cs new file mode 100644 index 00000000..721baee2 --- /dev/null +++ b/src/client/Bootstrap.Client/Query/QueryDummyOption.cs @@ -0,0 +1,76 @@ +using Bootstrap.Client.DataAccess; +using Longbow.Web.Mvc; +using System; +using System.Linq; + +namespace Bootstrap.Client.Query +{ + /// + /// 演示例子查询类 + /// + public class QueryDummyOption : PaginationOption + { + /// + /// 获得/设置 查询条件1 + /// + public string? Item1 { get; set; } + + /// + /// 获得/设置 查询条件2 + /// + public string? Item2 { get; set; } + + /// + /// 获得/设置 查询条件3 + /// + /// 数据库定义此字段为数值型,查询类为何定义为 string? 类型?因为这里可以设置为全部 + public string? Item3 { get; set; } + + /// + /// 字典表查询 + /// + /// + public QueryData Retrieves() + { + if (string.IsNullOrEmpty(Order)) Order = "asc"; + if (string.IsNullOrEmpty(Sort)) Sort = "Item1"; + + var data = DummyHelper.Retrieves(); + if (!string.IsNullOrEmpty(Item1)) + { + data = data.Where(t => t.Item1.Contains(Item1, StringComparison.OrdinalIgnoreCase)); + } + if (!string.IsNullOrEmpty(Item2)) + { + data = data.Where(t => t.Item2.Contains(Item2, StringComparison.OrdinalIgnoreCase)); + } + if (!string.IsNullOrEmpty(Item3)) + { + // 此列为数值型 + data = data.Where(t => t.Item3.ToString() == Item3); + } + if (!string.IsNullOrEmpty(Search)) + { + // 处理快捷搜索文本条件 + data = data.Where(t => t.Item1.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Item2.Contains(Search, StringComparison.OrdinalIgnoreCase)); + } + var ret = new QueryData(); + ret.total = data.Count(); + // 通过option.Sort属性判断对那列进行排序 + switch (Sort) + { + case "Item1": + data = Order == "asc" ? data.OrderBy(t => t.Item1) : data.OrderByDescending(t => t.Item1); + break; + case "Item2": + data = Order == "asc" ? data.OrderBy(t => t.Item2) : data.OrderByDescending(t => t.Item2); + break; + case "Item3": + data = Order == "asc" ? data.OrderBy(t => t.Item3) : data.OrderByDescending(t => t.Item3); + break; + } + ret.rows = data.Skip(Offset).Take(Limit); + return ret; + } + } +} diff --git a/src/client/Bootstrap.Client/Views/Home/Dummy.cshtml b/src/client/Bootstrap.Client/Views/Home/Dummy.cshtml new file mode 100644 index 00000000..b2acf5dc --- /dev/null +++ b/src/client/Bootstrap.Client/Views/Home/Dummy.cshtml @@ -0,0 +1,64 @@ +@model NavigatorBarModel +@{ + ViewData["Title"] = "演示视图"; + Layout = "_Default"; +} +@section css { + +} +@section javascript { + + +} +@section query { +
+
+
+ + +
+
+ + +
+
+ + + +
+
+
+} +@section modal { + + +} diff --git a/src/client/Bootstrap.Client/appsettings.Development.json b/src/client/Bootstrap.Client/appsettings.Development.json index 80c4e91c..ad711c70 100644 --- a/src/client/Bootstrap.Client/appsettings.Development.json +++ b/src/client/Bootstrap.Client/appsettings.Development.json @@ -23,7 +23,7 @@ }, "ConnectionStrings": { "ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa", - "client": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa" + "client": "Data Source=Client.db;" }, "DB": [ { diff --git a/src/client/Bootstrap.Client/wwwroot/js/dummy.js b/src/client/Bootstrap.Client/wwwroot/js/dummy.js new file mode 100644 index 00000000..3193cf4b --- /dev/null +++ b/src/client/Bootstrap.Client/wwwroot/js/dummy.js @@ -0,0 +1,32 @@ +$(function () { + $('table').lgbTable({ + url: 'api/Dummy', + dataBinder: { + map: { + Id: "#dummyID", + Item1: "#item1", + Item2: "#item2", + Item3: "#item3" + } + }, + smartTable: { + sortName: 'item1', + queryParams: function (params) { + return $.extend(params, { + item1: $('#item_query_1').val(), + item2: $("#item_query_2").val(), + item3: $("#item_query_3").val() + }); + }, + columns: [ + { title: "示例属性1", field: "Item1", sortable: true }, + { title: "示例属性2", field: "Item2", sortable: true }, + { title: "示例属性3", field: "Item3", sortable: true, formatter: function (value) { return value === 0 ? "系统使用" : "自定义"; } } + ], + exportOptions: { + fileName: "下载示例文件", + ignoreColumn: [0, 5] + } + } + }); +}); \ No newline at end of file