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 00000000..0f6a8a83 Binary files /dev/null and b/src/client/Bootstrap.Client/Client.db differ diff --git a/src/client/Bootstrap.Client/Controllers/Api/DummyController.cs b/src/client/Bootstrap.Client/Controllers/Api/DummyController.cs new file mode 100644 index 00000000..8cc8a770 --- /dev/null +++ b/src/client/Bootstrap.Client/Controllers/Api/DummyController.cs @@ -0,0 +1,40 @@ +using Bootstrap.Client.DataAccess; +using Bootstrap.Client.Query; +using Longbow.Web.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; + +namespace Bootstrap.Admin.Controllers.Api +{ + /// + /// 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