|
28 | 28 | <Divider /> |
29 | 29 |
|
30 | 30 | <div style="margin-bottom: 16px;"> |
31 | | - <Space> |
32 | | - <SpaceItem> |
33 | | - <Button Type="@ButtonType.Primary" Loading="@_loadingTables" OnClick="LoadTables"> |
34 | | - 刷新表列表 |
35 | | - </Button> |
36 | | - </SpaceItem> |
37 | | - <SpaceItem> |
38 | | - <Checkbox Checked="_selectAll" CheckedChanged="OnSelectAllChanged">全选</Checkbox> |
39 | | - </SpaceItem> |
40 | | - </Space> |
| 31 | + <div style="display: flex; gap: 16px; align-items: center;"> |
| 32 | + <div style="flex: 1;"> |
| 33 | + <Input Placeholder="搜索表名或描述..." |
| 34 | + @bind-Value="_searchKeyword" |
| 35 | + @oninput="OnSearchChanged" |
| 36 | + AllowClear="true" /> |
| 37 | + </div> |
| 38 | + <div> |
| 39 | + <Space> |
| 40 | + <SpaceItem> |
| 41 | + <Button Type="@ButtonType.Primary" Loading="@_loadingTables" OnClick="LoadTables"> |
| 42 | + 刷新表列表 |
| 43 | + </Button> |
| 44 | + </SpaceItem> |
| 45 | + <SpaceItem> |
| 46 | + <Checkbox Checked="_selectAll" CheckedChanged="OnSelectAllChanged">全选</Checkbox> |
| 47 | + </SpaceItem> |
| 48 | + </Space> |
| 49 | + </div> |
| 50 | + </div> |
41 | 51 | </div> |
42 | 52 |
|
43 | | - @if (_tables.Any()) |
| 53 | + @if (_filteredTables.Any()) |
44 | 54 | { |
45 | 55 | <div style="border: 1px solid #d9d9d9; border-radius: 8px; padding: 16px;"> |
46 | | - @foreach (var table in _tables) |
| 56 | + @foreach (var table in _filteredTables) |
47 | 57 | { |
48 | 58 | <div style="margin-bottom: 8px; padding: 8px; border: 1px solid #f0f0f0; border-radius: 4px;"> |
49 | 59 | <Checkbox Checked="_selectedTables.Contains(table.TableName)" CheckedChanged="@((bool isChecked) => OnTableSelectionChanged(table.TableName, isChecked))"> |
|
60 | 70 | } |
61 | 71 | </div> |
62 | 72 |
|
| 73 | + @if (!string.IsNullOrWhiteSpace(_searchKeyword) && _filteredTables.Count != _tables.Count) |
| 74 | + { |
| 75 | + <div style="margin-top: 8px; color: #666; font-size: 14px;"> |
| 76 | + 找到 @_filteredTables.Count 个表(共 @_tables.Count 个表) |
| 77 | + </div> |
| 78 | + } |
| 79 | + |
63 | 80 | <div style="margin-top: 16px;"> |
64 | 81 | <Space> |
65 | 82 | <SpaceItem> |
|
77 | 94 | } |
78 | 95 | else if (!_loadingTables) |
79 | 96 | { |
80 | | - <div style="text-align: center; padding: 40px; color: #999;">暂无数据表</div> |
| 97 | + <div style="text-align: center; padding: 40px; color: #999;"> |
| 98 | + @if (!string.IsNullOrWhiteSpace(_searchKeyword)) |
| 99 | + { |
| 100 | + <div>未找到匹配的表</div> |
| 101 | + <div style="font-size: 12px; margin-top: 8px;">请尝试修改搜索关键词</div> |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + <div>暂无数据表</div> |
| 106 | + } |
| 107 | + </div> |
81 | 108 | } |
82 | 109 | } |
83 | 110 | </Card> |
|
90 | 117 |
|
91 | 118 | private DatabaseConnectionConfig? _model = null; |
92 | 119 | private List<TableInfo> _tables = new(); |
| 120 | + private List<TableInfo> _filteredTables = new(); |
93 | 121 | private List<string> _selectedTables = new(); |
| 122 | + private string _searchKeyword = string.Empty; |
94 | 123 | private bool _selectAll = false; |
95 | 124 | private bool _loading = false; |
96 | 125 | private bool _loadingTables = false; |
|
136 | 165 | try |
137 | 166 | { |
138 | 167 | _tables = await SchemaTrainingService.GetDatabaseTablesAsync(Id); |
| 168 | + ApplySearch(); |
139 | 169 | StateHasChanged(); |
140 | 170 | } |
141 | 171 | catch (Exception ex) |
|
154 | 184 | _selectAll = isChecked; |
155 | 185 | if (_selectAll) |
156 | 186 | { |
157 | | - _selectedTables = _tables.Select(t => t.TableName).ToList(); |
| 187 | + _selectedTables = _filteredTables.Select(t => t.TableName).ToList(); |
158 | 188 | } |
159 | 189 | else |
160 | 190 | { |
|
177 | 207 | _selectedTables.Remove(tableName); |
178 | 208 | } |
179 | 209 |
|
180 | | - _selectAll = _selectedTables.Count == _tables.Count; |
| 210 | + _selectAll = _selectedTables.Count == _filteredTables.Count; |
181 | 211 | StateHasChanged(); |
182 | 212 | } |
183 | 213 |
|
|
220 | 250 | { |
221 | 251 | NavigationManager.NavigateTo($"/database-connection/details/{Id}"); |
222 | 252 | } |
| 253 | + |
| 254 | + private void OnSearchChanged(ChangeEventArgs e) |
| 255 | + { |
| 256 | + _searchKeyword = e.Value?.ToString() ?? string.Empty; |
| 257 | + ApplySearch(); |
| 258 | + StateHasChanged(); |
| 259 | + } |
| 260 | + |
| 261 | + private void ApplySearch() |
| 262 | + { |
| 263 | + if (string.IsNullOrWhiteSpace(_searchKeyword)) |
| 264 | + { |
| 265 | + _filteredTables = _tables.ToList(); |
| 266 | + } |
| 267 | + else |
| 268 | + { |
| 269 | + var keyword = _searchKeyword.ToLowerInvariant(); |
| 270 | + _filteredTables = _tables.Where(t => |
| 271 | + t.TableName.ToLowerInvariant().Contains(keyword) || |
| 272 | + (!string.IsNullOrEmpty(t.Description) && t.Description.ToLowerInvariant().Contains(keyword)) |
| 273 | + ).ToList(); |
| 274 | + } |
| 275 | + |
| 276 | + // 更新全选状态 |
| 277 | + UpdateSelectAllState(); |
| 278 | + } |
| 279 | + |
| 280 | + private void UpdateSelectAllState() |
| 281 | + { |
| 282 | + if (_filteredTables.Any()) |
| 283 | + { |
| 284 | + _selectAll = _filteredTables.All(t => _selectedTables.Contains(t.TableName)); |
| 285 | + } |
| 286 | + else |
| 287 | + { |
| 288 | + _selectAll = false; |
| 289 | + } |
| 290 | + } |
223 | 291 | } |
0 commit comments