ModalInputViewModel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. using Abp.Localization;
  5. using IwbZero;
  6. namespace ShwasherSys.Views.Shared.New.Modals
  7. {
  8. #region ModalBody
  9. public class Input
  10. {
  11. public Input(string id, string displayName = "", InputTypes inputType = InputTypes.Text, string placeholder = "", string name = null, string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "", string help = "")
  12. {
  13. Id = id;
  14. Name = string.IsNullOrEmpty(name) ? id : name;
  15. DisplayName = string.IsNullOrEmpty(displayName) ? L(id) : displayName;
  16. InputType = inputType;
  17. _placeholder = placeholder;
  18. Value = value;
  19. _class = @class;
  20. DataOptions = dataOptions;
  21. Events = events;
  22. Styles = styles;
  23. Other = other;
  24. IsHidden = hide;
  25. IsRequired = !hide;
  26. IsDisabled = false;
  27. IsReadOnly = false;
  28. _label = label;
  29. Help = help;
  30. IsSm = true;
  31. }
  32. #region 方法
  33. public Input SetDataOptions(string dataOptions)
  34. {
  35. DataOptions = dataOptions;
  36. return this;
  37. }
  38. public Input SetEvents(string events)
  39. {
  40. Events = events;
  41. return this;
  42. }
  43. public Input SetName(string name)
  44. {
  45. Name = name;
  46. return this;
  47. }
  48. public Input SetHelp(string help)
  49. {
  50. Help = help;
  51. return this;
  52. }
  53. public Input SetHidden()
  54. {
  55. IsHidden = true;
  56. return this;
  57. }
  58. public Input SetLabel(string label)
  59. {
  60. _label = label;
  61. return this;
  62. }
  63. public Input SetLabelName(string label)
  64. {
  65. _label = "<label class=\"iwb-label col-md-2 form-control-label\" for=\"" + Id + "\">" + label +
  66. "</label>";
  67. return this;
  68. }
  69. public Input SetLabelNameRequired(string label)
  70. {
  71. _label = "<label class=\"iwb-label col-md-2 form-control-label iwb-label-required\" for=\"" + Id + "\">" + label +
  72. "</label>";
  73. return this;
  74. }
  75. public Input SetNotRequired()
  76. {
  77. IsRequired = false;
  78. return this;
  79. }
  80. public Input SetDisabled()
  81. {
  82. IsDisabled = true;
  83. return this;
  84. }
  85. public Input SetReadonly()
  86. {
  87. IsReadOnly = true;
  88. return this;
  89. }
  90. public Input SetSelectOptions(List<SelectListItem> poSelectOptions, bool isMultiple = false, bool isAddBlank = true)
  91. {
  92. string lcRetval = isAddBlank ? "<option value=\"\" selected>请选择</option>" : "";
  93. IsMultiple = isMultiple;
  94. if (poSelectOptions != null && poSelectOptions.Any())
  95. {
  96. foreach (var s in poSelectOptions)
  97. {
  98. lcRetval += "<option value=\"" + s.Value + "\">" + s.Text + "</option>\r\n";
  99. }
  100. }
  101. SelectOptions = lcRetval;
  102. InputType = InputTypes.List;
  103. return this;
  104. }
  105. public Input SetSelectOptions(string poSelectOptions, bool isMultiple = false, bool isAddBlank = true)
  106. {
  107. string lcRetval = isAddBlank ? "<option value=\"\" selected>请选择</option>" : "";
  108. IsMultiple = isMultiple;
  109. if (!string.IsNullOrEmpty(poSelectOptions))
  110. {
  111. lcRetval += poSelectOptions;
  112. }
  113. SelectOptions = lcRetval;
  114. InputType = InputTypes.List;
  115. return this;
  116. }
  117. public Input SetLayout(string labelLayout, string inputLayout)
  118. {
  119. LabelLayoutClass = labelLayout;
  120. InputLayoutClass = inputLayout;
  121. return this;
  122. }
  123. //public Input SetLayout(int labelLayout, int? inputLayout = null, string layoutPrefix = "col-md-")
  124. //{
  125. // inputLayout = inputLayout ?? 12 - labelLayout;
  126. // LabelLayout = $"{layoutPrefix}{labelLayout}";
  127. // InputLayout = $"{layoutPrefix}{inputLayout}";
  128. // return this;
  129. //}
  130. public Input SetOuterDiv(string classStr, string other = "")
  131. {
  132. DivClass = classStr;
  133. DivOther = other;
  134. return this;
  135. }
  136. /// <summary>
  137. /// 外层上面其他标签
  138. /// </summary>
  139. /// <param name="beforeStr"></param>
  140. /// <returns></returns>
  141. public Input SetOuterBefore(string beforeStr)
  142. {
  143. DivOutBefore = beforeStr;
  144. return this;
  145. }
  146. /// <summary>
  147. /// 外层下面其他标签
  148. /// </summary>
  149. /// <param name="afterStr"></param>
  150. /// <returns></returns>
  151. public Input SetOuterAfter(string afterStr)
  152. {
  153. DivOutAfter = afterStr;
  154. return this;
  155. }
  156. /// <summary>
  157. /// 内层上面其他标签
  158. /// </summary>
  159. /// <param name="beforeStr"></param>
  160. /// <returns></returns>
  161. public Input SetInterBefore(string beforeStr)
  162. {
  163. DivInterBefore = beforeStr;
  164. return this;
  165. }
  166. /// <summary>
  167. /// 内层下面其他标签
  168. /// </summary>
  169. /// <param name="afterStr"></param>
  170. /// <returns></returns>
  171. public Input SetInterAfter(string afterStr)
  172. {
  173. DivInterAfter = afterStr;
  174. return this;
  175. }
  176. /// <summary>
  177. /// 添加搜索按钮
  178. /// </summary>
  179. /// <param name="searchModalId"></param>
  180. /// <param name="target"></param>
  181. /// <returns></returns>
  182. public Input SetSearchIcon(string searchModalId, string target = "")
  183. {
  184. SearchModalId = searchModalId;
  185. _target = target;
  186. return this;
  187. }
  188. /// <summary>
  189. /// 输入提示
  190. /// </summary>
  191. /// <param name="placeholder"></param>
  192. /// <returns></returns>
  193. public Input SetPlaceholder(string placeholder)
  194. {
  195. _placeholder = placeholder;
  196. return this;
  197. }
  198. public Input SetNotSmall()
  199. {
  200. IsSm = false;
  201. return this;
  202. }
  203. #endregion
  204. #region 字段属性
  205. public string Id { get; set; }
  206. public string Name { get; set; }
  207. public string DisplayName { get; set; }
  208. public string Help { get; set; }
  209. private string PlaceholderPrefix => InputType == InputTypes.List ? L("PlaceholderSelectHeader") : L("PlaceholderHeader");
  210. private string _placeholder;
  211. public string Placeholder => string.IsNullOrEmpty(_placeholder) ? $"{PlaceholderPrefix}{DisplayName}..." : _placeholder;
  212. public InputTypes InputType { get; set; }
  213. public string TypeStr
  214. {
  215. get
  216. {
  217. switch (InputType)
  218. {
  219. case InputTypes.Text:
  220. return "text";
  221. case InputTypes.Password:
  222. return "password";
  223. case InputTypes.Checkbox:
  224. return "checkbox";
  225. case InputTypes.Radio:
  226. return "radio";
  227. case InputTypes.File:
  228. return "file";
  229. case InputTypes.Number:
  230. return "number";
  231. default:
  232. return "text";
  233. }
  234. }
  235. }
  236. public DateTypes DateType { get; set; }
  237. public bool IsSm { get; set; }
  238. public string Number { get; set; }
  239. public int? Min { get; set; }
  240. public int? Max { get; set; }
  241. public string Value { get; set; }
  242. public string SelectOptions { get; private set; }
  243. private string _class;
  244. public string Class
  245. {
  246. get
  247. {
  248. var classStr = $"form-control {_class}";
  249. if (IsDisabled)
  250. {
  251. classStr += " disabled ";
  252. }
  253. if (IsReadOnly)
  254. {
  255. classStr += " readonly ";
  256. }
  257. if (InputType == InputTypes.Number)
  258. {
  259. classStr += $" {Number} ";
  260. }
  261. if (InputType == InputTypes.Date)
  262. {
  263. classStr += DateType == DateTypes.DateTime ? " iwb-date-time " : " iwb-date ";
  264. }
  265. return classStr;
  266. }
  267. set => _class = value;
  268. }
  269. public string DataOptions { get; set; }
  270. public string Events { get; set; }
  271. public string Styles { get; set; }
  272. public string Other { get; set; }
  273. public bool IsHidden { get; set; }
  274. public bool IsRequired { get; set; }
  275. public bool IsDisabled { get; set; }
  276. public bool IsReadOnly { get; set; }
  277. public bool IsMultiple { get; private set; }
  278. public string Required => IsHidden ? "" : (IsRequired ? " required" : "");
  279. public string DivClass { get; set; }
  280. public string DivOther { get; set; }
  281. public string DivOutBefore { get; set; }
  282. public string DivOutAfter { get; set; }
  283. public string DivInterBefore { get; set; }
  284. public string DivInterAfter { get; set; }
  285. public string SearchModalId { get; set; }
  286. public string LabelLayoutClass { get; set; }
  287. public string InputLayoutClass { get; set; }
  288. private string _label;
  289. public string Label => IsHidden
  290. ? ""
  291. : string.IsNullOrEmpty(_label)
  292. ? (IsRequired
  293. ? $"<label class=\"iwb-label {LabelLayoutClass} control-label iwb-label-required\" for=\"" + Id + "\">" +
  294. DisplayName + "</label>"
  295. : $"<label class=\"iwb-label {LabelLayoutClass} control-label\" for=\"" + Id + "\">" + DisplayName +
  296. "</label>")
  297. : _label;
  298. public string Disabled => IsDisabled ? "disabled=\"disabled\"" : "";
  299. public string ReadOnly => IsReadOnly ? "readonly=\"readonly\"" : "";
  300. public FileInputOption FileOption { get; set; }
  301. private string _target;
  302. public string Target =>
  303. string.IsNullOrEmpty(_target) ? DefaultTarget ?? "" :
  304. _target.StartsWith(".") ? _target :
  305. _target.StartsWith("#") ? _target : $"#{_target}";
  306. public string DefaultTarget { get; set; }
  307. #endregion
  308. private static string L(string name)
  309. {
  310. var str = LocalizationHelper.GetSource(ShwasherConsts.LocalizationSourceName).GetString(name);
  311. return str;
  312. }
  313. }
  314. public class InputHide : Input
  315. {
  316. public InputHide(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", string label = "")
  317. : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, true, label)
  318. {
  319. }
  320. }
  321. public class InputTextarea : Input
  322. {
  323. public InputTextarea(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  324. : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
  325. {
  326. }
  327. }
  328. public class InputKindeditor : InputTextarea
  329. {
  330. public InputKindeditor(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  331. : base(id, displayName, placeholder, name, value, "kindeditor", dataOptions, events, styles, other, hide, label)
  332. {
  333. }
  334. }
  335. public class InputDate : Input
  336. {
  337. public InputDate(string id, string displayName = "", DateTypes date = DateTypes.Date, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  338. : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
  339. {
  340. DateType = date;
  341. }
  342. public InputDate SetDateType(DateTypes date)
  343. {
  344. DateType = date;
  345. return this;
  346. }
  347. }
  348. public class InputDateTime : Input
  349. {
  350. public InputDateTime(string id, string displayName = "", DateTypes date = DateTypes.DateTime, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  351. : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
  352. {
  353. DateType = date;
  354. }
  355. public InputDateTime SetDateType(DateTypes date)
  356. {
  357. DateType = date;
  358. return this;
  359. }
  360. }
  361. public class InputNumber : Input
  362. {
  363. /// <summary>
  364. ///
  365. /// </summary>
  366. /// <param name="id"></param>
  367. /// <param name="displayName"></param>
  368. /// <param name="numberType">0是整数,其他是小数</param>
  369. /// <param name="min"></param>
  370. /// <param name="max"></param>
  371. /// <param name="placeholder"></param>
  372. /// <param name="name"></param>
  373. /// <param name="value"></param>
  374. /// <param name="class"></param>
  375. /// <param name="dataOptions"></param>
  376. /// <param name="events"></param>
  377. /// <param name="styles"></param>
  378. /// <param name="other"></param>
  379. /// <param name="hide"></param>
  380. /// <param name="label"></param>
  381. public InputNumber(string id, string displayName = "", int numberType = 0, int? min = null, int? max = null, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  382. : base(id, displayName, InputTypes.Number, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
  383. {
  384. Number = numberType == 0 ? "number" : "digits";
  385. Min = min;
  386. Max = max;
  387. }
  388. public InputNumber SetRange(int? min = null, int? max = null, int numberType = 1)
  389. {
  390. Min = min;
  391. Max = max;
  392. Number = numberType == 0 ? "number" : "digits";
  393. return this;
  394. }
  395. public InputNumber SetNumberType(int numberType = 1, int? min = null, int? max = null)
  396. {
  397. Number = numberType == 0 ? "number" : "digits";
  398. Min = min;
  399. Max = max;
  400. return this;
  401. }
  402. public InputNumber SetMin(int min)
  403. {
  404. Min = min;
  405. return this;
  406. }
  407. public InputNumber SetMax(int max)
  408. {
  409. Max = max;
  410. return this;
  411. }
  412. }
  413. public class InputFile : Input
  414. {
  415. public InputFile(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
  416. : base(id, displayName, InputTypes.File, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
  417. {
  418. }
  419. /// <summary>
  420. /// 文件选择框设置信息
  421. /// </summary>
  422. /// <param name="opt"></param>
  423. /// <returns></returns>
  424. public InputFile SetFileOption(FileInputOption opt)
  425. {
  426. opt.FileInfoField = string.IsNullOrEmpty(opt.FileInfoField) ? Id : opt.FileInfoField;
  427. FileOption = opt;
  428. InputType = InputTypes.File;
  429. return this;
  430. }
  431. /// <summary>
  432. /// 文件选择框设置信息
  433. /// </summary>
  434. /// <returns></returns>
  435. public InputFile SetFileOption(string fileInfoField="", string fileNameField = "", string fileExtField = "", int maxSize = 5)
  436. {
  437. fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField;
  438. FileOption = new FileInputOption(fileInfoField,fileNameField,fileExtField,false,maxSize);
  439. return this;
  440. }
  441. /// <summary>
  442. /// 图片选择框设置信息
  443. /// </summary>
  444. /// <returns></returns>
  445. public InputFile SetImageOption(string fileInfoField="", string fileNameField = "", string fileExtField = "", int maxSize = 5)
  446. {
  447. fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField;
  448. FileOption = new FileInputOption(fileInfoField,fileNameField,fileExtField,true,maxSize);
  449. return this;
  450. }
  451. }
  452. public class SpecialInputModel
  453. {
  454. public string Id { get; set; }
  455. public string InputStr { get; set; }
  456. }
  457. public class FileInputOption
  458. {
  459. public FileInputOption(string fileInfoField, string fileNameField = "", string fileExtField = "", bool isImage = true, int maxSize = 5, string fileIdField = null)
  460. {
  461. FileInfoField = fileInfoField;
  462. FileNameField = fileNameField;
  463. FileExtField = fileExtField;
  464. IsImage = isImage;
  465. MaxSize = maxSize;
  466. FileIdField = fileIdField;
  467. }
  468. public string FileIdField { get; set; }
  469. public string FileInfoField { get; set; }
  470. public string FileNameField { get; set; }
  471. public string FileExtField { get; set; }
  472. public bool IsImage { get; set; }
  473. /// <summary>
  474. /// 文件最大M(默认5M)
  475. /// </summary>
  476. public int MaxSize { get; set; } = 5;
  477. }
  478. //public class SelectOption
  479. //{
  480. // public SelectOption(string text, string value = "")
  481. // {
  482. // Text = text;
  483. // Value = value;
  484. // }
  485. // public string Value { get; set; }
  486. // public string Text { get; set; }
  487. //}
  488. public enum InputTypes
  489. {
  490. Text, List, Checkbox, Radio, Password, Textarea, File, Number, Date
  491. }
  492. public enum DateTypes
  493. {
  494. Date, DateTime
  495. }
  496. #endregion
  497. }