VmTable.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using VberAdmin.Web.Models.Search;
  2. using VberZero.Tools.StringModel;
  3. namespace VberAdmin.Web.Models.Table;
  4. public class VmTable
  5. {
  6. #region 字段属性
  7. public VmSearch Search { get; set; }
  8. public string TableId { get; set; }
  9. public string TableClass { get; set; }
  10. public string TheadClass { get; set; }
  11. public string TheadTrClass { get; set; }
  12. private string _rowId;
  13. public string RowId => _rowId.Empty() ? "id" : _rowId;
  14. public string Url { get; set; }
  15. public string Method { get; set; }
  16. public bool HasBox { get; set; }
  17. public bool HasCheckBox { get; set; }
  18. public bool IsTree { get; set; }
  19. public string ActiveMenu { get; set; }
  20. public bool IsPage { private get; set; }
  21. public int[] PageArray { private get; set; }
  22. public bool IsSingleSelect { get; set; }
  23. public bool IsPageSelect { private get; set; }
  24. public bool IsMultiplePageSelect { private get; set; }
  25. public bool IsClickSelect { private get; set; }
  26. public bool IsProcessing { private get; set; }
  27. public bool IsScrollCollapse { private get; set; }
  28. public string ScrollCollapseX { private get; set; }
  29. public string ScrollCollapseY { private get; set; }
  30. public bool IsLocalData { private get; set; }
  31. public string Actions { get; set; }
  32. public string Other { get; set; }
  33. public string RowAttributes { get; set; }
  34. public List<VmTableItem> Items { get; set; }
  35. public string Page => IsPage ? "true" : "false";
  36. public string PageList => string.Join(",", PageArray);
  37. public string PageSelect => IsPageSelect ? "true" : "false";
  38. public string MultiplePageSelect => IsMultiplePageSelect ? "true" : "false";
  39. public string SingleSelect => IsSingleSelect ? "true" : "false";
  40. public string ClickSelect => IsClickSelect ? "true" : "false";
  41. public string Tree => IsTree ? "true" : "false";
  42. public string CheckBox => HasCheckBox ? "true" : "false";
  43. public string Processing => IsProcessing ? "true" : "false";
  44. public string Scroll => $"data-scroll-collapse=\"{(IsScrollCollapse ? "true" : "false")}\" {(ScrollCollapseX.Empty() ? "" : $"data-scroll-x=\"{ScrollCollapseX}\"")} {(ScrollCollapseY.Empty() ? "" : $"data-scroll-y=\"{ScrollCollapseY}\"")}";
  45. public string DataMethod => IsLocalData ? "" : $"data-method=\"{Method}\" data-side-pagination=\"server\"";
  46. #endregion 字段属性
  47. public VmTable()
  48. {
  49. IsPage = true;
  50. IsClickSelect = true;
  51. IsSingleSelect = true;
  52. IsProcessing = true;
  53. IsPageSelect = true;
  54. IsMultiplePageSelect = false;
  55. PageArray = new[] { 20, 50, 100 };
  56. HasCheckBox = true;
  57. IsScrollCollapse = true;
  58. Method = "post";
  59. TableId = "table";
  60. TableClass = "text-start table-striped table-row-dashed text-gray-700 fs-6 gx-3 gy-2";
  61. TheadClass = "";
  62. TheadTrClass = "text-start text-gray-800 fw-bolder fs-4 text-uppercase gx-3 gy-4";
  63. Other = "";
  64. }
  65. public VmTable(string url, string activeMenu, VmSearch search, string tableId = "table", bool hasBox = true) : this()
  66. {
  67. TableId = tableId;
  68. Url = url;
  69. ActiveMenu = activeMenu;
  70. Search = search;
  71. HasBox = hasBox;
  72. }
  73. public VmTable(string url, string activeMenu = null, string tableId = "table", bool hasBox = true)
  74. : this(url, activeMenu, null, tableId, hasBox)
  75. {
  76. TableId = tableId;
  77. Url = url;
  78. ActiveMenu = activeMenu;
  79. }
  80. public VmTable(string url, string activeMenu, VmSearch search, List<VmTableItem> items, string tableId = "table")
  81. : this(url, activeMenu, search, tableId)
  82. {
  83. TableId = tableId;
  84. Url = url;
  85. ActiveMenu = activeMenu;
  86. Items = items;
  87. Search = search;
  88. }
  89. #region 方法
  90. public VmTable WithTable(string active, string url = "", bool hasBox = true, string id = "table")
  91. {
  92. ActiveMenu = active;
  93. TableId = id;
  94. Url = url;
  95. HasBox = HasBox;
  96. return this;
  97. }
  98. public VmTable WithTableId(string id)
  99. {
  100. TableId = id;
  101. return this;
  102. }
  103. public VmTable WithTableClass(string @class)
  104. {
  105. TableClass = @class;
  106. return this;
  107. }
  108. public VmTable WithTableHeadClass(string @class)
  109. {
  110. TheadClass = @class;
  111. return this;
  112. }
  113. public VmTable WithTableTheadTrClass(string @class)
  114. {
  115. TheadTrClass = @class;
  116. return this;
  117. }
  118. public VmTable WithRowId(string rowId)
  119. {
  120. _rowId = rowId;
  121. return this;
  122. }
  123. public VmTable WithNotBox()
  124. {
  125. HasBox = false;
  126. return this;
  127. }
  128. public VmTable WithNotHasCheckBox(bool hasCheckBox = false)
  129. {
  130. HasCheckBox = hasCheckBox;
  131. return this;
  132. }
  133. public VmTable WithSearch(VmSearch search)
  134. {
  135. Search = search;
  136. return this;
  137. }
  138. public VmTable WithSearch(List<VmSearchItem> searchItems, string formId = "search-form")
  139. {
  140. Search = new VmSearch(formId).AddItems(searchItems);
  141. return this;
  142. }
  143. public VmTable WithTree()
  144. {
  145. IsTree = true;
  146. HasCheckBox = false;
  147. IsClickSelect = false;
  148. IsPageSelect = false;
  149. return this;
  150. }
  151. public VmTable WithNotPage(bool hasCheckBox = false)
  152. {
  153. IsPage = false;
  154. HasCheckBox = hasCheckBox;
  155. return this;
  156. }
  157. public VmTable WithPage(params int[] page)
  158. {
  159. IsPage = true;
  160. PageArray = page;
  161. return this;
  162. }
  163. /// <summary>
  164. ///
  165. /// </summary>
  166. /// <param name="isSingleSelect"></param>
  167. /// <param name="isSavePageSelect">多选保存分页数据</param>
  168. /// <returns></returns>
  169. public VmTable WithMultipleSelect(bool isSingleSelect = false, bool isSavePageSelect = true)
  170. {
  171. IsSingleSelect = isSingleSelect;
  172. IsMultiplePageSelect = isSavePageSelect;
  173. return this;
  174. }
  175. public VmTable WithMultiplePageSelect()
  176. {
  177. IsMultiplePageSelect = true;
  178. return this;
  179. }
  180. public VmTable WithRowAttributes(string rowAttributes)
  181. {
  182. RowAttributes = rowAttributes ?? "";
  183. return this;
  184. }
  185. public VmTable WithAction(string actions)
  186. {
  187. Actions = actions;
  188. return this;
  189. }
  190. public VmTable WithOther(string other)
  191. {
  192. Other = other ?? "";
  193. return this;
  194. }
  195. public VmTable WithLocalData()
  196. {
  197. IsLocalData = true;
  198. return this;
  199. }
  200. public VmTable WithGetMethod()
  201. {
  202. Method = "get";
  203. return this;
  204. }
  205. public VmTable WithNotClickSelect(bool isClickSelect = false)
  206. {
  207. IsClickSelect = isClickSelect;
  208. return this;
  209. }
  210. public VmTable WithNotSingleSelect(bool isSingleSelect = false)
  211. {
  212. IsSingleSelect = isSingleSelect;
  213. return this;
  214. }
  215. public VmTable WithScroll(string x, bool isScrollCollapse = true)
  216. {
  217. ScrollCollapseX = x;
  218. IsScrollCollapse = isScrollCollapse;
  219. return this;
  220. }
  221. public VmTable WithScroll(string x, string y, bool isScrollCollapse = true)
  222. {
  223. ScrollCollapseX = x;
  224. ScrollCollapseY = y;
  225. IsScrollCollapse = isScrollCollapse;
  226. return this;
  227. }
  228. public VmTable WithItems(List<VmTableItem> items)
  229. {
  230. Items = items;
  231. return this;
  232. }
  233. public VmTable AddItems(List<VmTableItem> items)
  234. {
  235. Items ??= new List<VmTableItem>();
  236. Items.AddRange(items);
  237. return this;
  238. }
  239. public VmTable AddItem(VmTableItem item)
  240. {
  241. Items ??= new List<VmTableItem>();
  242. Items.Add(item);
  243. return this;
  244. }
  245. #endregion 方法
  246. }