| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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<VmTableItem> 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<VmTableItem> 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<VmSearchItem> 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;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="isSingleSelect"></param>
- /// <param name="isSavePageSelect">多选保存分页数据</param>
- /// <returns></returns>
- 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<VmTableItem> items)
- {
- Items = items;
- return this;
- }
- public VmTable AddItems(List<VmTableItem> items)
- {
- Items ??= new List<VmTableItem>();
- Items.AddRange(items);
- return this;
- }
- public VmTable AddItem(VmTableItem item)
- {
- Items ??= new List<VmTableItem>();
- Items.Add(item);
- return this;
- }
- #endregion 方法
- }
|