feat: Client 增加一个 Dummy 示例
This commit is contained in:
parent
0b96082364
commit
693e07588c
|
@ -0,0 +1,43 @@
|
|||
using PetaPoco;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Client.DataAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// 示例实体类
|
||||
/// </summary>
|
||||
[TableName("Dummy")]
|
||||
[PrimaryKey("Id", AutoIncrement = true)]
|
||||
public class Dummy
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 数据库主键 ID 列值
|
||||
/// </summary>
|
||||
public string? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 数据库 Item1 列
|
||||
/// </summary>
|
||||
public string Item1 { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 数据库 Item2 列
|
||||
/// </summary>
|
||||
public string Item2 { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 数据库 Item3 列
|
||||
/// </summary>
|
||||
public int Item3 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得所有菜单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Dummy> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create("client");
|
||||
return db.Fetch<Dummy>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
using Longbow.Data;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Client.DataAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// 示例操作帮助类
|
||||
/// </summary>
|
||||
public static class DummyHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据库中所有 Dummy 表数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Dummy> Retrieves()
|
||||
{
|
||||
// 此处启用智能切换数据库功能
|
||||
return DbContextManager.Create<Dummy>()?.Retrieves() ?? new Dummy[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存 Dummy 实例到数据库中
|
||||
/// </summary>
|
||||
/// <param name="dummy"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Save(Dummy dummy)
|
||||
{
|
||||
// 此处未启用智能
|
||||
using var db = DbManager.Create("client");
|
||||
db.Save(dummy);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定 ID 的 Dummy 数据
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Delete(IEnumerable<string> ids)
|
||||
{
|
||||
// 此处使用指定 Sqlite 数据方法执行数据库操作 演示同一个程序操作多个数据库的场景
|
||||
using var db = DbManager.CreateSqlite("client");
|
||||
db.Delete<Dummy>("where Id in (@ids)", new { ids });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Dummy 表维护控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class DummyController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有 Dummy 表数据方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<Dummy> Get([FromQuery]QueryDummyOption value) => value.Retrieves();
|
||||
|
||||
/// <summary>
|
||||
/// 保存方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
public bool Post([FromBody]Dummy value) => DummyHelper.Save(value);
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定 ID 集合的 Dummy 数据
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpDelete]
|
||||
public bool Delete([FromBody]IEnumerable<string> value) => DummyHelper.Delete(value);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,12 @@ namespace Bootstrap.Client.Controllers
|
|||
return View(new NavigatorBarModel(this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 演示视图
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Dummy() => View(new NavigatorBarModel(this));
|
||||
|
||||
/// <summary>
|
||||
/// About 视图
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
using Bootstrap.Client.DataAccess;
|
||||
using Longbow.Web.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Client.Query
|
||||
{
|
||||
/// <summary>
|
||||
/// 演示例子查询类
|
||||
/// </summary>
|
||||
public class QueryDummyOption : PaginationOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 查询条件1
|
||||
/// </summary>
|
||||
public string? Item1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 查询条件2
|
||||
/// </summary>
|
||||
public string? Item2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 查询条件3
|
||||
/// </summary>
|
||||
/// <remark>数据库定义此字段为数值型,查询类为何定义为 string? 类型?因为这里可以设置为全部</remark>
|
||||
public string? Item3 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字典表查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public QueryData<Dummy> 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<Dummy>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
@model NavigatorBarModel
|
||||
@{
|
||||
ViewData["Title"] = "演示视图";
|
||||
Layout = "_Default";
|
||||
}
|
||||
@section css {
|
||||
<link href="~/lib/longbow-select/longbow-select.css" rel="stylesheet" />
|
||||
}
|
||||
@section javascript {
|
||||
<script src="~/lib/longbow-select/longbow-select.js"></script>
|
||||
<script src="~/js/dummy.js"></script>
|
||||
}
|
||||
@section query {
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-12">
|
||||
<label class="control-label" for="item_query_1">演示属性1</label>
|
||||
<input type="text" class="form-control" id="item_query_1" data-provide="typeahead" data-default-val="" />
|
||||
</div>
|
||||
<div class="form-group col-12">
|
||||
<label class="control-label" for="item_query_2">演示属性2</label>
|
||||
<input type="text" class="form-control" id="item_query_2" data-default-val="" />
|
||||
</div>
|
||||
<div class="form-group col-12">
|
||||
<label class="control-label" for="item_query_3">演示属性3</label>
|
||||
<input class="form-control" data-toggle="lgbSelect" data-default-val="" />
|
||||
<select data-toggle="lgbSelect" class="d-none" id="item_query_3">
|
||||
<option value="">全部</option>
|
||||
<option value="0">系统使用</option>
|
||||
<option value="1">自定义</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
@section modal {
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="myModalLabel">演示视图编辑窗口</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<input type="hidden" id="dummyID" />
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label" for="item1">演示属性1</label>
|
||||
<input type="text" class="form-control" id="item1" placeholder="不可为空,50字以内" maxlength="50" data-valid="true" />
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label" for="item2">演示属性2</label>
|
||||
<input type="text" class="form-control" id="item2" placeholder="不可为空,50字以内" maxlength="50" data-valid="true" />
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label" for="item3">演示属性3</label>
|
||||
<input class="form-control" data-toggle="lgbSelect" />
|
||||
<select data-toggle="lgbSelect" class="d-none" data-default-val="1" id="item3">
|
||||
<option value="0">系统使用</option>
|
||||
<option value="1">自定义</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
}
|
|
@ -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": [
|
||||
{
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue