VmInputSelectAjax.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using VberZero.Tools.StringModel;
  2. namespace VberAdmin.Web.Models.Input;
  3. public class VmInputSelectAjax : VmInputBase
  4. {
  5. public VmInputSelectAjax(string name, string displayName) : base(name, displayName, VmInputType.AjaxSelect)
  6. {
  7. DefaultClass = "form-select form-select-sm form-control-sm form-select-solid ajax-select";
  8. }
  9. public VmInputSelectAjax(string name, string displayName, string codeKey, string modalId, string clear = "", int takeCount = 10) : this(name, displayName)
  10. {
  11. CodeKey = codeKey;
  12. TakeCount = takeCount;
  13. QueryModalId = modalId;
  14. if (clear.Empty())
  15. {
  16. WithQueryClear(Name);
  17. }
  18. else
  19. {
  20. WithQueryClear(clear, true);
  21. }
  22. }
  23. public string CodeKey { get; protected set; }
  24. public int TakeCount { get; protected set; }
  25. /// <summary>
  26. /// 展示模板函数
  27. /// </summary>
  28. public string FunResultTemplateName { get; protected set; }
  29. public string ControlDataStr =>
  30. "data-select-ajax=\"true\" " +
  31. $"data-dropdown-parent=\"#{ModalId}\" " +
  32. $"data-placeholder=\"{PlaceholderStr}\" " +
  33. $"data-param-key=\"{CodeKey}\" " +
  34. $"data-param-count=\"{TakeCount}\" " +
  35. $"{(FunResultTemplateName.Empty() ? "" : $"data-result-template-function=\"{FunResultTemplateName}\"")}";
  36. public VmInputSelectAjax WithCodeKey(string codeKey)
  37. {
  38. CodeKey = codeKey;
  39. return this;
  40. }
  41. public VmInputSelectAjax WithTakeCount(int takeCount)
  42. {
  43. TakeCount = takeCount;
  44. return this;
  45. }
  46. public VmInputSelectAjax WithResultTemplateName(string resultTemplateName)
  47. {
  48. FunResultTemplateName = resultTemplateName;
  49. return this;
  50. }
  51. }