using VberAdmin.Web.Models.Search; using VberZero.Tools.StringModel; namespace VberAdmin.Web.Models.Table; public class VmTable { #region 字段属性 public VmSearch Search { get; set; } public string TableId { get; set; } public string TableClass { get; set; } public string TheadClass { get; set; } public string TheadTrClass { get; set; } private string _rowId; public string RowId => _rowId.Empty() ? "id" : _rowId; public string Url { get; set; } public string Method { get; set; } public bool HasBox { get; set; } public bool HasCheckBox { get; set; } public bool IsTree { get; set; } public string ActiveMenu { get; set; } public bool IsPage { private get; set; } public int[] PageArray { private get; set; } public bool IsSingleSelect { get; set; } public bool IsPageSelect { private get; set; } public bool IsMultiplePageSelect { private get; set; } public bool IsClickSelect { private get; set; } public bool IsProcessing { private get; set; } public bool IsScrollCollapse { private get; set; } public string ScrollCollapseX { private get; set; } public string ScrollCollapseY { private get; set; } public bool IsLocalData { private get; set; } public string Actions { get; set; } public string Other { get; set; } public string RowAttributes { get; set; } public List Items { get; set; } public string Page => IsPage ? "true" : "false"; public string PageList => string.Join(",", PageArray); public string PageSelect => IsPageSelect ? "true" : "false"; public string MultiplePageSelect => IsMultiplePageSelect ? "true" : "false"; public string SingleSelect => IsSingleSelect ? "true" : "false"; public string ClickSelect => IsClickSelect ? "true" : "false"; public string Tree => IsTree ? "true" : "false"; public string CheckBox => HasCheckBox ? "true" : "false"; public string Processing => IsProcessing ? "true" : "false"; public string Scroll => $"data-scroll-collapse=\"{(IsScrollCollapse ? "true" : "false")}\" {(ScrollCollapseX.Empty() ? "" : $"data-scroll-x=\"{ScrollCollapseX}\"")} {(ScrollCollapseY.Empty() ? "" : $"data-scroll-y=\"{ScrollCollapseY}\"")}"; public string DataMethod => IsLocalData ? "" : $"data-method=\"{Method}\" data-side-pagination=\"server\""; #endregion 字段属性 public VmTable() { IsPage = true; IsClickSelect = true; IsSingleSelect = true; IsProcessing = true; IsPageSelect = true; IsMultiplePageSelect = false; PageArray = new[] { 20, 50, 100 }; HasCheckBox = true; IsScrollCollapse = true; Method = "post"; TableId = "table"; TableClass = "text-start table-striped table-row-dashed text-gray-700 fs-6 gx-3 gy-2"; TheadClass = ""; TheadTrClass = "text-start text-gray-800 fw-bolder fs-4 text-uppercase gx-3 gy-4"; Other = ""; } public VmTable(string url, string activeMenu, VmSearch search, string tableId = "table", bool hasBox = true) : this() { TableId = tableId; Url = url; ActiveMenu = activeMenu; Search = search; HasBox = hasBox; } public VmTable(string url, string activeMenu = null, string tableId = "table", bool hasBox = true) : this(url, activeMenu, null, tableId, hasBox) { TableId = tableId; Url = url; ActiveMenu = activeMenu; } public VmTable(string url, string activeMenu, VmSearch search, List items, string tableId = "table") : this(url, activeMenu, search, tableId) { TableId = tableId; Url = url; ActiveMenu = activeMenu; Items = items; Search = search; } #region 方法 public VmTable WithTable(string active, string url = "", bool hasBox = true, string id = "table") { ActiveMenu = active; TableId = id; Url = url; HasBox = HasBox; return this; } public VmTable WithTableId(string id) { TableId = id; return this; } public VmTable WithTableClass(string @class) { TableClass = @class; return this; } public VmTable WithTableHeadClass(string @class) { TheadClass = @class; return this; } public VmTable WithTableTheadTrClass(string @class) { TheadTrClass = @class; return this; } public VmTable WithRowId(string rowId) { _rowId = rowId; return this; } public VmTable WithNotBox() { HasBox = false; return this; } public VmTable WithNotHasCheckBox(bool hasCheckBox = false) { HasCheckBox = hasCheckBox; return this; } public VmTable WithSearch(VmSearch search) { Search = search; return this; } public VmTable WithSearch(List searchItems, string formId = "search-form") { Search = new VmSearch(formId).AddItems(searchItems); return this; } public VmTable WithTree() { IsTree = true; HasCheckBox = false; IsClickSelect = false; IsPageSelect = false; return this; } public VmTable WithNotPage(bool hasCheckBox = false) { IsPage = false; HasCheckBox = hasCheckBox; return this; } public VmTable WithPage(params int[] page) { IsPage = true; PageArray = page; return this; } /// /// /// /// /// 多选保存分页数据 /// public VmTable WithMultipleSelect(bool isSingleSelect = false, bool isSavePageSelect = true) { IsSingleSelect = isSingleSelect; IsMultiplePageSelect = isSavePageSelect; return this; } public VmTable WithMultiplePageSelect() { IsMultiplePageSelect = true; return this; } public VmTable WithRowAttributes(string rowAttributes) { RowAttributes = rowAttributes ?? ""; return this; } public VmTable WithAction(string actions) { Actions = actions; return this; } public VmTable WithOther(string other) { Other = other ?? ""; return this; } public VmTable WithLocalData() { IsLocalData = true; return this; } public VmTable WithGetMethod() { Method = "get"; return this; } public VmTable WithNotClickSelect(bool isClickSelect = false) { IsClickSelect = isClickSelect; return this; } public VmTable WithNotSingleSelect(bool isSingleSelect = false) { IsSingleSelect = isSingleSelect; return this; } public VmTable WithScroll(string x, bool isScrollCollapse = true) { ScrollCollapseX = x; IsScrollCollapse = isScrollCollapse; return this; } public VmTable WithScroll(string x, string y, bool isScrollCollapse = true) { ScrollCollapseX = x; ScrollCollapseY = y; IsScrollCollapse = isScrollCollapse; return this; } public VmTable WithItems(List items) { Items = items; return this; } public VmTable AddItems(List items) { Items ??= new List(); Items.AddRange(items); return this; } public VmTable AddItem(VmTableItem item) { Items ??= new List(); Items.Add(item); return this; } #endregion 方法 }