| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- using VberAdmin.Web.Models.Input;
- using VberAdmin.Web.Models.Search;
- using VberZero.Tools.StringModel;
- namespace VberAdmin.Web.Models.Modals;
- using VberAdmin.Web.Models.Table;
- public class VmQueryModal
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="name"></param>
- /// <param name="url"></param>
- /// <param name="modalId"></param>
- /// <param name="queryItems"></param>
- /// <param name="originField">"id,name,name2,displayName"</param>
- /// <param name="targetField">"id,name" "1:name,3:displayName" "1:name|name2,3:displayName"</param>
- /// <param name="ajaxSelectNameField"></param>
- /// <param name="submitEventName"></param>
- /// <param name="itemDbClickEventName"></param>
- /// <param name="itemClickEventName"></param>
- /// <param name="isSingleSelect"></param>
- /// <param name="vmQueryTreeSearch"></param>
- /// <param name="searchBindFun"></param>
- /// <param name="modalWidth"></param>
- public VmQueryModal(string name, string url, string modalId, List<VmQueryItem> queryItems, string originField,
- string targetField,
- string ajaxSelectNameField = "", string submitEventName = null, string itemDbClickEventName = null,
- string itemClickEventName = null, bool isSingleSelect = true, VmQueryTreeSearch vmQueryTreeSearch = null,
- string searchBindFun = "", int modalWidth = 900)
- {
- ModalName = name;
- QueryUrl = url;
- QueryItems = queryItems;
- SearchBindFun = searchBindFun;
- AjaxSelectNameField = ajaxSelectNameField;
- VmQueryTreeSearch = vmQueryTreeSearch;
- OriginFields = originField.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- var targets = new string[OriginFields.Length];
- TargetFields = new List<string[]>();
- IsSingleSelect = isSingleSelect;
- if (string.IsNullOrEmpty(targetField))
- {
- for (var i = 0; i < targets.Length; i++) TargetFields.Add(new[] { $"[name='{OriginFields[i]}']" });
- }
- else
- {
- var targetArr = targetField.Split(new[] { ',' }, StringSplitOptions.None);
- for (var i = 0; i < targets.Length; i++)
- if (i < targetArr.Length)
- {
- if (!string.IsNullOrEmpty(targetArr[i]))
- {
- var unitArr = targetArr[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (unitArr.Length > 1)
- {
- if (int.TryParse(unitArr[0], out var index) && index < OriginFields.Length && index >= i)
- {
- for (; i < index; i++) TargetFields.Add(new[] { $"[name='{OriginFields[i]}']" });
- AddTargetField(unitArr[1], i);
- }
- else
- {
- AddTargetField(unitArr[1], i);
- }
- }
- else
- {
- AddTargetField(targetArr[i], i);
- }
- }
- else
- {
- TargetFields.Add(new[] { $"[name='{OriginFields[i]}']" });
- }
- }
- else
- {
- TargetFields.Add(new[] { $"[name='{OriginFields[i]}']" });
- }
- }
- SubmitEventName = submitEventName;
- ModalId = modalId;
- ModalWidth = modalWidth;
- ItemClickEventName = itemClickEventName;
- ItemDbClickEventName = itemDbClickEventName ?? submitEventName;
- }
- public string QueryUrl { get; set; }
- public List<VmQueryItem> QueryItems { get; set; }
- public string ModalId { get; set; }
- public string ModalName { get; set; }
- public int ModalWidth { get; set; }
- public string RowId { get; set; }
- public string[] OriginFields { get; set; }
- public List<string[]> TargetFields { get; set; }
- public string SubmitEventName { get; set; }
- public string ItemClickEventName { get; set; }
- public string ItemDbClickEventName { get; set; }
- public VmQueryTreeSearch VmQueryTreeSearch { get; set; }
- public string SearchBindFun { get; set; }
- public bool IsSingleSelect { get; set; }
- public bool IsMultiplePageSelect { private get; set; }
- public string PageSelect => IsMultiplePageSelect ? "true" : "false";
- public string SingleSelect => IsSingleSelect ? "true" : "false";
- public string AjaxSelectNameField { get; set; }
- private void AddTargetField(string targetStr, int index)
- {
- var target = targetStr.Split(new[] { '|' }, StringSplitOptions.None);
- for (var i = 0; i < target.Length; i++)
- target[i] = string.IsNullOrEmpty(target[i])
- ? $"[name='{OriginFields[index]}']"
- : target[i].StartsWith("#") || target[i].StartsWith(".")
- ? target[i]
- : $"[name='{target[i]}']";
- TargetFields.Add(target);
- }
- public VmQueryModal WithSearchFun(string funName)
- {
- SearchBindFun = funName;
- return this;
- }
- public VmQueryModal WithSearchTree(VmQueryTreeSearch searchTree)
- {
- VmQueryTreeSearch = searchTree;
- return this;
- }
- public VmSearch Search
- {
- get
- {
- var list = QueryItems.Where(a => a.IsSearch).ToList();
- if (list.Any())
- {
- var search = new List<VmSearchItem>();
- foreach (var item in list)
- {
- var s = new VmSearchItem(item.FiledName, item.DisplayName)
- {
- IsDisabled = item.IsDisabled,
- IsHidden = item.IsHidden,
- IsReadOnly = item.IsReadonly,
- IsOnlyView = item.IsOnlyView,
- FieldType = item.FieldType,
- ExpType = item.ExpType,
- };
- if (item.SelectStr.NotEmpty())
- {
- s.WithSelect(item.SelectStr, false, item.IsSelectTree);
- }
- search.Add(s);
- }
- return new VmSearch(search, ModalId + "_search");
- ;
- }
- return null;
- }
- }
- }
- public class VmQueryItem : VmTableItem
- {
- public VmQueryItem(
- string filedName,
- string displayName,
- bool isSearch = false,
- bool sort = false,
- int tipLength = 0,
- bool isDisabled = false,
- bool isHidden = false,
- FType fieldType = FType.S,
- EType expType = EType.Contains,
- string formatter = "")
- : base(filedName, displayName, formatter, sort, tipLength)
- {
- IsSearch = isSearch;
- IsDisabled = isDisabled;
- IsHidden = isHidden;
- FieldType = fieldType;
- ExpType = expType;
- }
- public bool IsSearch { get; set; }
- public bool IsHidden { get; set; }
- public bool IsFieldHidden { get; set; }
- public bool IsOnlyView { get; set; }
- public bool IsDisabled { get; set; }
- public bool IsReadonly { get; set; }
- public string DisabledStr => IsDisabled ? "disable" : "";
- public bool IsSelectTree { get; set; }
- public string SelectStr { get; set; }
- public FType FieldType { get; set; }
- public EType ExpType { get; set; }
- //public string FiledName { get; set; }
- //public string DisplayName { get; set; }
- //public string Formatter { get; set; }
- //public string FormatterStr => string.IsNullOrEmpty(Formatter) ? "" : "data-formatter=\"" + Formatter + "\"";
- //public string ClassName { get; set; }
- //public int? Width { get; set; }
- //public string WidthUnit { get; set; }
- //public string WidthStr => Width != null ? $" data-width=\"{Width}{WidthUnit}\"" : "";
- //public bool IsSort { get; set; }
- //public string Sort => IsSort ? " data-sortable=\"true\"" : "";
- //private int TipLength { get; set; }
- //public string Tip => TipLength > 0 ? $"data-tip=\"{TipLength}\"" : "";
- public new VmQueryItem WithWidth(int width, string unit = "px")
- {
- Width = width;
- WidthUnit = unit;
- return this;
- }
- /// <summary>
- /// 超过指定字符将 被截取 用tip的方式显示
- /// </summary>
- /// <param name="showLength">默认 30个字符</param>
- /// <returns></returns>
- public new VmQueryItem WithTip(int showLength = 30)
- {
- TipLength = showLength;
- return this;
- }
- public new VmQueryItem WithSort()
- {
- IsSort = true;
- return this;
- }
- public new VmQueryItem WithClassName(string className)
- {
- ClassName = className;
- return this;
- }
- public new VmQueryItem WithFormatter(string formatter)
- {
- Formatter = formatter;
- return this;
- }
- public VmQueryItem WithHidden()
- {
- IsHidden = true;
- return this;
- }
- public VmQueryItem WithDisabled()
- {
- IsDisabled = true;
- return this;
- }
- public VmQueryItem WithFieldType(FType fieldType, EType expType = EType.Contains)
- {
- FieldType = fieldType;
- ExpType = expType;
- return this;
- }
- public VmQueryItem WithExpType(EType expType)
- {
- ExpType = expType;
- return this;
- }
- public VmQueryItem WithSelectStr(string str, bool isSelectTree = false)
- {
- IsSelectTree = isSelectTree;
- SelectStr = str;
- return this;
- }
- public VmQueryItem WithSelectStr(Dictionary<string, string> dic, bool isSelectTree = false)
- {
- IsSelectTree = isSelectTree;
- if (dic.ContainsKey(FiledName)) SelectStr = dic[FiledName];
- return this;
- }
- public VmQueryItem WithOnlyView()
- {
- IsOnlyView = true;
- return this;
- }
- public VmQueryItem WithFieldHidden()
- {
- IsFieldHidden = true;
- IsSearch = true;
- return this;
- }
- public VmQueryItem WithSearch(bool isHidden = true, bool isDisabled = false, bool isReadonly = false, bool isOnlyView = false)
- {
- IsSearch = true;
- IsHidden = isHidden;
- IsDisabled = isDisabled;
- IsReadonly = isReadonly;
- IsOnlyView = isOnlyView;
- return this;
- }
- }
- public class VmQueryTreeSearch
- {
- public string Field { get; set; }
- public int FType { get; set; }
- public int EType { get; set; }
- public string SelectUrl { get; set; }
- public string SelectFieldName { get; set; }
- }
|