QueryViewModel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ShwasherSys.Views.Shared.New.Query
  4. {
  5. #region Query
  6. public class QueryViewModel
  7. {
  8. public QueryViewModel(string name, string url, List<QueryItem> queryItems, string originField, string targetField = null, string submitEventName = null,
  9. string modalId = "query_modal", int modalWidth = 900, string itemDbClickEventName = null,
  10. string itemClickEventName = null, QueryTreeSearch queryTreeSearch = null, string searchBindFunc = "")
  11. {
  12. ModalName = name;
  13. QueryUrl = url;
  14. QueryItems = queryItems;
  15. SearchBindFunc = searchBindFunc;
  16. QueryTreeSearch = queryTreeSearch;
  17. OriginFields = originField.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  18. var targets = new string[OriginFields.Length];
  19. TargetFields = new List<string[]>();
  20. if (string.IsNullOrEmpty(targetField))
  21. {
  22. for (int i = 0; i < targets.Length; i++)
  23. {
  24. TargetFields.Add(new[] { "#" + OriginFields[i] });
  25. }
  26. }
  27. else
  28. {
  29. var targetArr = targetField.Split(new[] { ',' }, StringSplitOptions.None);
  30. for (int i = 0; i < targets.Length; i++)
  31. {
  32. if (i < targetArr.Length)
  33. {
  34. if (!string.IsNullOrEmpty(targetArr[i]))
  35. {
  36. var unitArr = targetArr[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  37. if (unitArr.Length > 1)
  38. {
  39. if (int.TryParse(unitArr[0], out int index) && index < OriginFields.Length && index >= i)
  40. {
  41. for (; i < index; i++)
  42. {
  43. TargetFields.Add(new[] { "#" + OriginFields[i] });
  44. }
  45. AddTargetField(unitArr[1], i);
  46. }
  47. else
  48. {
  49. AddTargetField(unitArr[1], i);
  50. }
  51. }
  52. else
  53. {
  54. AddTargetField(targetArr[i], i);
  55. }
  56. }
  57. else
  58. {
  59. TargetFields.Add(new[] { "#" + OriginFields[i] });
  60. }
  61. }
  62. else
  63. {
  64. TargetFields.Add(new[] { "#" + OriginFields[i] });
  65. }
  66. }
  67. }
  68. SubmitEventName = submitEventName;
  69. ModalId = modalId;
  70. ModalWidth = modalWidth;
  71. ItemClickEventName = itemClickEventName;
  72. ItemDbClickEventName = itemDbClickEventName ?? submitEventName;
  73. }
  74. public string QueryUrl { get; set; }
  75. public List<QueryItem> QueryItems { get; set; }
  76. public string ModalId { get; set; }
  77. public string ModalName { get; set; }
  78. public int ModalWidth { get; set; }
  79. public string[] OriginFields { get; set; }
  80. public List<string[]> TargetFields { get; set; }
  81. public string SubmitEventName { get; set; }
  82. public string ItemClickEventName { get; set; }
  83. public string ItemDbClickEventName { get; set; }
  84. public QueryTreeSearch QueryTreeSearch { get; set; }
  85. public string SearchBindFunc { get; set; }
  86. private void AddTargetField(string targetStr, int index)
  87. {
  88. var target = targetStr.Split(new[] { '|' }, StringSplitOptions.None);
  89. for (int i = 0; i < target.Length; i++)
  90. {
  91. target[i] = string.IsNullOrEmpty(target[i]) ? "#" + OriginFields[index] : (target[i].StartsWith("#") || target[i].StartsWith("."))
  92. ? target[i]
  93. : "#" + target[i];
  94. }
  95. TargetFields.Add(target);
  96. }
  97. }
  98. //public class SearchBindDto
  99. //{
  100. // public string KeyField { get; set; }
  101. // public string KeyWords { get; set; }
  102. // public int FieldType { get; set; }
  103. // public int ExpType { get; set; }
  104. //}
  105. #endregion
  106. }