QueryViewModel.cs 4.6 KB

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