diff --git a/src/admin/Bootstrap.Admin/Query/QueryDictOption.cs b/src/admin/Bootstrap.Admin/Query/QueryDictOption.cs index 3fa9c3fb..86766c32 100644 --- a/src/admin/Bootstrap.Admin/Query/QueryDictOption.cs +++ b/src/admin/Bootstrap.Admin/Query/QueryDictOption.cs @@ -1,6 +1,7 @@ using Bootstrap.DataAccess; using Bootstrap.Security; using Longbow.Web.Mvc; +using System; using System.Linq; namespace Bootstrap.Admin.Query @@ -37,15 +38,19 @@ namespace Bootstrap.Admin.Query var data = DictHelper.RetrieveDicts(); if (!string.IsNullOrEmpty(Category)) { - data = data.Where(t => t.Category?.Contains(Category) ?? false); + data = data.Where(t => t.Category.Contains(Category, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(Name)) { - data = data.Where(t => t.Name?.Contains(Name) ?? false); + data = data.Where(t => t.Name.Contains(Name, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(Define)) { - data = data.Where(t => t.Define.ToString() == (Define ?? "")); + data = data.Where(t => t.Define.ToString() == Define); + } + if (!string.IsNullOrEmpty(Search)) + { + data = data.Where(t => t.Category.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Name.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Code.Contains(Search, StringComparison.OrdinalIgnoreCase)); } var ret = new QueryData(); ret.total = data.Count(); diff --git a/src/admin/Bootstrap.Admin/Query/QueryGroupOption.cs b/src/admin/Bootstrap.Admin/Query/QueryGroupOption.cs index 5e975659..be85a8f9 100644 --- a/src/admin/Bootstrap.Admin/Query/QueryGroupOption.cs +++ b/src/admin/Bootstrap.Admin/Query/QueryGroupOption.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using System; using System.Linq; namespace Bootstrap.Admin.Query @@ -29,11 +30,15 @@ namespace Bootstrap.Admin.Query var data = GroupHelper.Retrieves(); if (!string.IsNullOrEmpty(GroupName)) { - data = data.Where(t => t.GroupName?.Contains(GroupName) ?? false); + data = data.Where(t => t.GroupName.Contains(GroupName, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(Description)) { - data = data.Where(t => t.Description?.Contains(Description) ?? false); + data = data.Where(t => t.Description?.Contains(Description, StringComparison.OrdinalIgnoreCase) ?? false); + } + if (!string.IsNullOrEmpty(Search)) + { + data = data.Where(t => t.GroupName.Contains(Search, StringComparison.OrdinalIgnoreCase) || (t.Description?.Contains(Search, StringComparison.OrdinalIgnoreCase) ?? false)); } var ret = new QueryData(); ret.total = data.Count(); diff --git a/src/admin/Bootstrap.Admin/Query/QueryMenuOption.cs b/src/admin/Bootstrap.Admin/Query/QueryMenuOption.cs index 9b21cd97..b062fadc 100644 --- a/src/admin/Bootstrap.Admin/Query/QueryMenuOption.cs +++ b/src/admin/Bootstrap.Admin/Query/QueryMenuOption.cs @@ -6,37 +6,37 @@ using System.Linq; namespace Bootstrap.Admin.Query { /// - /// + /// /// public class QueryMenuOption : PaginationOption { /// - /// + /// /// public string? Name { get; set; } /// - /// + /// /// public string? ParentName { get; set; } /// - /// + /// /// public string? Category { get; set; } /// - /// + /// /// public string? IsResource { get; set; } /// - /// + /// /// public string? AppId { get; set; } /// - /// + /// /// /// /// @@ -45,15 +45,15 @@ namespace Bootstrap.Admin.Query var data = MenuHelper.RetrieveMenusByUserName(userName); if (!string.IsNullOrEmpty(ParentName)) { - data = data.Where(t => t.Name.Contains(ParentName) || (t.ParentName != null && t.ParentName.Contains(ParentName))); + data = data.Where(t => t.Name.Contains(ParentName, StringComparison.OrdinalIgnoreCase) || (t.ParentName != null && t.ParentName.Contains(ParentName, StringComparison.OrdinalIgnoreCase))); } if (!string.IsNullOrEmpty(Name)) { - data = data.Where(t => t.Name.Contains(Name)); + data = data.Where(t => t.Name.Contains(Name, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(Category)) { - data = data.Where(t => t.Category.Contains(Category)); + data = data.Where(t => t.Category.Contains(Category, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(IsResource)) { @@ -63,6 +63,10 @@ namespace Bootstrap.Admin.Query { data = data.Where(t => t.Application.Equals(AppId, StringComparison.OrdinalIgnoreCase)); } + if (!string.IsNullOrEmpty(Search)) + { + data = data.Where(t => t.Name.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.ParentName.Contains(Search, StringComparison.OrdinalIgnoreCase)); + } var ret = new QueryData(); ret.total = data.Count(); switch (Sort) diff --git a/src/admin/Bootstrap.Admin/Query/QueryRoleOption.cs b/src/admin/Bootstrap.Admin/Query/QueryRoleOption.cs index 5fe73d05..2412492e 100644 --- a/src/admin/Bootstrap.Admin/Query/QueryRoleOption.cs +++ b/src/admin/Bootstrap.Admin/Query/QueryRoleOption.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using System; using System.Linq; namespace Bootstrap.Admin.Query @@ -29,11 +30,15 @@ namespace Bootstrap.Admin.Query var data = RoleHelper.Retrieves(); if (!string.IsNullOrEmpty(RoleName)) { - data = data.Where(t => t.RoleName.Contains(RoleName)); + data = data.Where(t => t.RoleName.Contains(RoleName, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(Description)) { - data = data.Where(t => t.Description.Contains(Description)); + data = data.Where(t => t.Description.Contains(Description, StringComparison.OrdinalIgnoreCase)); + } + if (!string.IsNullOrEmpty(Search)) + { + data = data.Where(t => t.RoleName.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Description.Contains(Search, StringComparison.OrdinalIgnoreCase)); } var ret = new QueryData(); ret.total = data.Count(); diff --git a/src/admin/Bootstrap.Admin/Query/QueryUserOption.cs b/src/admin/Bootstrap.Admin/Query/QueryUserOption.cs index 8bcd8a98..c4488687 100644 --- a/src/admin/Bootstrap.Admin/Query/QueryUserOption.cs +++ b/src/admin/Bootstrap.Admin/Query/QueryUserOption.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using System; using System.Linq; namespace Bootstrap.Admin.Query @@ -29,11 +30,15 @@ namespace Bootstrap.Admin.Query var data = UserHelper.Retrieves(); if (!string.IsNullOrEmpty(Name)) { - data = data.Where(t => t.UserName.Contains(Name)); + data = data.Where(t => t.UserName.Contains(Name, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrEmpty(DisplayName)) { - data = data.Where(t => t.DisplayName.Contains(DisplayName)); + data = data.Where(t => t.DisplayName.Contains(DisplayName, StringComparison.OrdinalIgnoreCase)); + } + if (!string.IsNullOrEmpty(Search)) + { + data = data.Where(t => t.DisplayName.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Description.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.UserName.Contains(Search, StringComparison.OrdinalIgnoreCase)); } var ret = new QueryData(); ret.total = data.Count(); diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Dicts.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Dicts.cshtml index bd9f773d..90d44795 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Dicts.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Dicts.cshtml @@ -19,26 +19,23 @@ @section query {
-
+
- +
-
+
- +
-
+
- +
-
- -
} diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Groups.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Groups.cshtml index a7b84771..f7869d23 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Groups.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Groups.cshtml @@ -9,16 +9,13 @@ @section query {
-
+
- +
-
+
- -
-
- +
diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Menus.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Menus.cshtml index 2a756e05..b9932e9c 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Menus.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Menus.cshtml @@ -33,26 +33,26 @@ @section query {
-
+
- +
-
+
- +
-
+
- +
-
+
- +
-
+
- +
-
- -
} diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Roles.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Roles.cshtml index fe78fd5d..26ce092f 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Roles.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Roles.cshtml @@ -24,16 +24,13 @@ @section query {
-
+
- +
-
+
- -
-
- +
diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Users.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Users.cshtml index a53414ba..039d6d2a 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Users.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Users.cshtml @@ -9,16 +9,13 @@ @section query {
-
+
- +
-
+
- -
-
- +
diff --git a/src/admin/Bootstrap.Admin/Views/Shared/_Default.cshtml b/src/admin/Bootstrap.Admin/Views/Shared/_Default.cshtml index b1d868f7..0e420488 100644 --- a/src/admin/Bootstrap.Admin/Views/Shared/_Default.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Shared/_Default.cshtml @@ -52,14 +52,25 @@
+ @RenderSection("customModal", false) } -
-
查询条件
-
- @RenderSection("query", false) -
-
@@ -93,4 +104,4 @@ @RenderSection("tableButtons", false)
-@await RenderSectionAsync("body", false) \ No newline at end of file +@await RenderSectionAsync("body", false) diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/site.css b/src/admin/Bootstrap.Admin/wwwroot/css/site.css index 716d28c7..8eb90e28 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/site.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/site.css @@ -531,3 +531,7 @@ pre { outline: none; color: #371ed4; } + + .modal-query .form-group input.form-control { + flex: 1 1 auto; + } \ No newline at end of file diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/theme-responsive.css b/src/admin/Bootstrap.Admin/wwwroot/css/theme-responsive.css index 15208e0b..ae653867 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/theme-responsive.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/theme-responsive.css @@ -130,6 +130,12 @@ } } +@media (min-width: 1120px) { + .bootstrap-table .fixed-table-toolbar .columns button i + span, .bootstrap-table .fixed-table-toolbar .search button i + span { + display: inline-block; + } +} + @media (min-width: 1200px) { .modal-xl { max-width: 1100px; diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/theme.css b/src/admin/Bootstrap.Admin/wwwroot/css/theme.css index fa1ff074..870fc2e2 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/theme.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/theme.css @@ -774,6 +774,10 @@ input.pending { padding: 6px 20px; } +.bootstrap-table .fixed-table-toolbar .columns button i + span, .bootstrap-table .fixed-table-toolbar .search button i + span { + display: none; +} + .fixed-table-toolbar .dropdown-menu { min-width: unset; } diff --git a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js index 068d8b01..75366526 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js +++ b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js @@ -353,6 +353,14 @@ pageList: [20, 40, 80, 120], //可供选择的每页的行数(*) showExport: true, exportTypes: ['csv', 'txt', 'excel'], + advancedSearchModal: '#dialogAdvancedSearch', + search: true, + searchOnEnterKey: false, + searchTimeOut: 0, + showSearchClearButton: true, + showAdvancedSearchButton: true, + showButtonText: true, + showSearchButton: true, //是否显示搜索按钮 showColumns: true, //是否显示所有的列 showRefresh: true, //是否显示刷新按钮 showToggle: true, //是否显示详细视图和列表视图的切换按钮 @@ -383,6 +391,35 @@ } } }); + + if (settings.search) { + // 自动收集 SearchText + var queryParams = settings.queryParams; + + settings.queryParams = function (params) { + return $.extend({}, queryParams(params), { search: $('.bootstrap-table .fixed-table-toolbar .search-input').val() }); + } + + // 支持键盘回车搜索 + $(document).on('keyup', '.bootstrap-table .fixed-table-toolbar .search-input', this, function (event) { + if (event.keyCode === 13) { + // ENTER + var $buttons = $(this).next(); + var $search = $buttons.find('[name="search"]'); + if ($search.length === 1) { + $search.trigger('click'); + } + else { + // 无搜索按钮是使用 refresh 方法 + event.data.bootstrapTable('refresh'); + } + } + else if (event.keyCode === 27) { + // ESC + event.data.bootstrapTable('resetSearch'); + } + }); + } this.bootstrapTable(settings); $('.bootstrap-table .fixed-table-toolbar .columns .export .dropdown-menu').addClass("dropdown-menu-right"); var $gear = $(settings.toolbar).removeClass('d-none').find('.gear'); @@ -396,6 +433,52 @@ e.data.bootstrapTable('refresh'); }); } + + // 增加 Tooltip + if (settings.search) { + $('.bootstrap-table .fixed-table-toolbar .search-input').tooltip({ + sanitize: false, + title: "输入任意字符串全局搜索
Enter 搜索 ESC 清除搜索", + html: true + }); + } + + // 生成高级查询按钮 + if (settings.showAdvancedSearchButton) { + // template + var $advancedSearchButtonHtml = $(''); + $advancedSearchButtonHtml.insertAfter($('.bootstrap-table .fixed-table-toolbar .search [name="clearSearch"]')).on('click', function () { + // 弹出高级查询对话框 + $(settings.advancedSearchModal).modal('show'); + }); + + // 高级搜索有值时颜色为红色 + $(settings.advancedSearchModal).on('hide.bs.modal', function () { + var $modal = $(this) + var hasValue = false; + $modal.find('[data-default-val]').each(function (index, element) { + var $ele = $(element); + var val = $ele.attr('data-default-val'); + if ($ele.prop('nodeName') === 'INPUT') { + if ($ele.hasClass('form-select-input')) { + hasValue = $ele.prev().val() !== val; + } + else { + hasValue = $ele.val() !== val; + } + } + if (hasValue) return false; + }); + + if (hasValue) $advancedSearchButtonHtml.removeClass('btn-secondary').addClass('btn-primary'); + else $advancedSearchButtonHtml.removeClass('btn-primary').addClass('btn-secondary'); + }); + } + + // fix bug 移除 Toolbar 按钮 Title 中的 Html + $('.bootstrap-table .fixed-table-toolbar button[title]').each(function (index, element) { + element.title = element.title.replace('', '').replace('', ''); + }); return this; }, lgbPopover: function (options) { @@ -526,6 +609,68 @@ $.extend($.fn.bootstrapTable.defaults.icons, { refresh: 'fa-refresh' }); + + // fix bug bootstrap-table showButtonText support mobile + // argo at 2020-01-18 + $.extend($.fn.bootstrapTable.defaults, { + formatClearSearch: function formatClearSearch() { + return '清空过滤'; + }, + formatSearch: function formatSearch() { + return '搜索'; + }, + formatNoMatches: function formatNoMatches() { + return '没有找到匹配的记录'; + }, + formatPaginationSwitch: function formatPaginationSwitch() { + return '隐藏/显示分页'; + }, + formatPaginationSwitchDown: function formatPaginationSwitchDown() { + return '显示分页'; + }, + formatPaginationSwitchUp: function formatPaginationSwitchUp() { + return '隐藏分页'; + }, + formatRefresh: function formatRefresh() { + return '查询'; + }, + formatToggle: function formatToggle() { + return '切换'; + }, + formatToggleOn: function formatToggleOn() { + return '显示卡片视图'; + }, + formatToggleOff: function formatToggleOff() { + return '隐藏卡片视图'; + }, + formatColumns: function formatColumns() { + return ''; + }, + formatColumnsToggleAll: function formatColumnsToggleAll() { + return '切换所有'; + }, + formatFullscreen: function formatFullscreen() { + return '全屏'; + }, + formatAllRows: function formatAllRows() { + return '所有'; + }, + formatAutoRefresh: function formatAutoRefresh() { + return '自动刷新'; + }, + formatExport: function formatExport() { + return '导出数据'; + }, + formatJumpTo: function formatJumpTo() { + return '跳转'; + }, + formatAdvancedSearch: function formatAdvancedSearch() { + return '高级搜索'; + }, + formatAdvancedCloseButton: function formatAdvancedCloseButton() { + return '关闭'; + } + }); } // extend bootstrap-toggle @@ -540,7 +685,7 @@ $(this).trigger('click.bs.toggle'); e.preventDefault(); }); - } + }; } if (window.NProgress) { diff --git a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js index a27c5cc9..fb3df95d 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js +++ b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js @@ -123,9 +123,34 @@ modal: '#dialogNew', click: { '#btn_query': function (element) { - if (this.options.bootstrapTable !== null) this.options.bootstrapTable.bootstrapTable('refresh'); + if (this.options.bootstrapTable !== null) { + var options = this.options.bootstrapTable.bootstrapTable('getOptions'); + if (options.advancedSearchModal) { + $(options.advancedSearchModal).modal('hide'); + } + this.options.bootstrapTable.bootstrapTable('refresh'); + } handlerCallback.call(this, null, element, { oper: 'query' }); }, + '#btn_reset': function () { + if (this.options.bootstrapTable !== null) { + var options = this.options.bootstrapTable.bootstrapTable('getOptions'); + if (options.advancedSearchModal) { + $(options.advancedSearchModal).find('[data-default-val]').each(function (index, element) { + var $ele = $(element); + var val = $ele.attr('data-default-val'); + if ($ele.prop('nodeName') === 'INPUT') { + if ($ele.hasClass('form-select-input')) { + $ele.prev().lgbSelect('val', val); + } + else { + $ele.val(val); + } + } + }); + } + } + }, '#btn_add': function (element) { this.dataEntity.reset(); if (this.options.modal.constructor === String) $(this.options.modal).modal("show");