From 3a6abfd294baba752870e95ecf8a5c8234c831f7 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 28 Dec 2023 11:07:48 +0800 Subject: [PATCH 1/5] Add the delay&MinimumInputLength property --- .../EasySelector/EasySelectorAttribute.cs | 18 +++++++++++++----- .../TagHelperPlusAbpSelectTagHelperService.cs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/EasySelector/EasySelectorAttribute.cs b/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/EasySelector/EasySelectorAttribute.cs index 6b05b46..e36b159 100644 --- a/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/EasySelector/EasySelectorAttribute.cs +++ b/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/EasySelector/EasySelectorAttribute.cs @@ -10,7 +10,7 @@ public class EasySelectorAttribute : Attribute /// /// /api/identity/users public string GetListedDataSourceUrl { get; set; } - + /// /// Url to get single data. /// Use {id}` as the key. @@ -27,7 +27,7 @@ public class EasySelectorAttribute : Attribute /// Used to be the display text of the option. /// public string TextPropertyName { get; set; } - + /// /// Used to be the display text of the option if the text property is null. /// @@ -49,14 +49,18 @@ public class EasySelectorAttribute : Attribute /// Hide the sub text (key) of items. /// public bool HideSubText { get; set; } - + /// /// Please set to true if the item is not in a modal. /// public bool RunScriptOnWindowLoad { get; set; } public string FilterParamName { get; set; } - + + public int Delay { get; set; } + + public int MinimumInputLength { get; set; } + public EasySelectorAttribute( [NotNull] string getListedDataSourceUrl, [NotNull] string getSingleDataSourceUrl, @@ -68,7 +72,9 @@ public EasySelectorAttribute( [NotNull] string filterParamName = "filter", int maxResultCount = 10, bool hideSubText = false, - bool runScriptOnWindowLoad = false) + bool runScriptOnWindowLoad = false, + int delay = 250, + int minimumInputLength = 0) { GetListedDataSourceUrl = getListedDataSourceUrl; GetSingleDataSourceUrl = getSingleDataSourceUrl; @@ -81,6 +87,8 @@ public EasySelectorAttribute( HideSubText = hideSubText; RunScriptOnWindowLoad = runScriptOnWindowLoad; FilterParamName = filterParamName; + Delay = delay; + MinimumInputLength = minimumInputLength; } } } \ No newline at end of file diff --git a/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/TagHelpers/TagHelperPlusAbpSelectTagHelperService.cs b/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/TagHelpers/TagHelperPlusAbpSelectTagHelperService.cs index 0570381..450ea60 100644 --- a/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/TagHelpers/TagHelperPlusAbpSelectTagHelperService.cs +++ b/src/EasyAbp.Abp.TagHelperPlus/EasyAbp/Abp/TagHelperPlus/TagHelpers/TagHelperPlusAbpSelectTagHelperService.cs @@ -132,7 +132,7 @@ protected virtual string GetScriptCode(TagHelperContext context, EasySelectorAtt var dropdownParent = easySelectorAttribute.RunScriptOnWindowLoad ? "" : $"dropdownParent: $('#{tagId}').parent().parent(),"; var baseUrl = configuration?.BaseUrl; - var innerCode = $"$(function () {{ let currentValues = {_jsonSerializer.Serialize(currentValues)}; function stringMatch(term,candidate){{return candidate&&candidate.toLowerCase().indexOf(term.toLowerCase())>=0}}; function matchCustom(params,data){{if($.trim(params.term)===\"\"){{return data}}if(typeof data.text===\"undefined\"){{return null}}if(stringMatch(params.term,data.text)){{return data}}if(stringMatch(params.term,state.id)){{return data}}return null}}; let select2Item = function (state) {{ return $('' + state.text{subTextContent} + ''); }}; let select2Option = {{ allowClear: true, width: \"100%\", matcher: matchCustom, templateResult: select2Item, templateSelection: select2Item,{dropdownParent} ajax: {{ url: '{baseUrl}{easySelectorAttribute.GetListedDataSourceUrl}', dataType: \"json\", delay: 250, data: function (params) {{ params.page = params.page || 1; return {{ {easySelectorAttribute.FilterParamName}: params.term, skipCount: (params.page - 1) * {easySelectorAttribute.MaxResultCount}, maxResultCount: {easySelectorAttribute.MaxResultCount}, }} }}, processResults: function (data, params) {{ params.page = params.page || 1; return {{ results: data.{easySelectorAttribute.ItemListPropertyName}.map(function (item) {{ return {{ id: item.{easySelectorAttribute.KeyPropertyName}, text: item.{easySelectorAttribute.TextPropertyName} ?? item.{easySelectorAttribute.AlternativeTextPropertyName} }} }}), pagination: {{ more: (params.page * {easySelectorAttribute.MaxResultCount}) < data.totalCount }} }}; }}, cache: true }}, placeholder: {{ id: '', text: '{placeHolder}' }} }}; $(\"#{tagId}\").select2(select2Option); currentValues && currentValues.values.forEach(function(e) {{ if (!$(\"#{tagId}\").find('option:contains(' + e + ')').length && (e != \"00000000-0000-0000-0000-000000000000\" && e != \"\" && e != \"0\")) abp.ajax({{ type: 'GET', url: '{baseUrl}{easySelectorAttribute.GetSingleDataSourceUrl}'.replace('{{id}}', e), success: function (result) {{ $(\"#{tagId}\").append($('