Skip to content

Commit d511b7e

Browse files
committed
增加选择表筛选框
1 parent 96ee618 commit d511b7e

File tree

2 files changed

+84
-16
lines changed

2 files changed

+84
-16
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
33
<PropertyGroup>
4-
<Version>0.1.3</Version>
4+
<Version>0.1.4</Version>
55
<SKVersion>1.17.1</SKVersion>
66
</PropertyGroup>
77
</Project>

src/Text2Sql.Net.Web/Pages/DatabaseConnection/SelectTables.razor

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,32 @@
2828
<Divider />
2929

3030
<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>
4151
</div>
4252

43-
@if (_tables.Any())
53+
@if (_filteredTables.Any())
4454
{
4555
<div style="border: 1px solid #d9d9d9; border-radius: 8px; padding: 16px;">
46-
@foreach (var table in _tables)
56+
@foreach (var table in _filteredTables)
4757
{
4858
<div style="margin-bottom: 8px; padding: 8px; border: 1px solid #f0f0f0; border-radius: 4px;">
4959
<Checkbox Checked="_selectedTables.Contains(table.TableName)" CheckedChanged="@((bool isChecked) => OnTableSelectionChanged(table.TableName, isChecked))">
@@ -60,6 +70,13 @@
6070
}
6171
</div>
6272

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+
6380
<div style="margin-top: 16px;">
6481
<Space>
6582
<SpaceItem>
@@ -77,7 +94,17 @@
7794
}
7895
else if (!_loadingTables)
7996
{
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>
81108
}
82109
}
83110
</Card>
@@ -90,7 +117,9 @@
90117

91118
private DatabaseConnectionConfig? _model = null;
92119
private List<TableInfo> _tables = new();
120+
private List<TableInfo> _filteredTables = new();
93121
private List<string> _selectedTables = new();
122+
private string _searchKeyword = string.Empty;
94123
private bool _selectAll = false;
95124
private bool _loading = false;
96125
private bool _loadingTables = false;
@@ -136,6 +165,7 @@
136165
try
137166
{
138167
_tables = await SchemaTrainingService.GetDatabaseTablesAsync(Id);
168+
ApplySearch();
139169
StateHasChanged();
140170
}
141171
catch (Exception ex)
@@ -154,7 +184,7 @@
154184
_selectAll = isChecked;
155185
if (_selectAll)
156186
{
157-
_selectedTables = _tables.Select(t => t.TableName).ToList();
187+
_selectedTables = _filteredTables.Select(t => t.TableName).ToList();
158188
}
159189
else
160190
{
@@ -177,7 +207,7 @@
177207
_selectedTables.Remove(tableName);
178208
}
179209

180-
_selectAll = _selectedTables.Count == _tables.Count;
210+
_selectAll = _selectedTables.Count == _filteredTables.Count;
181211
StateHasChanged();
182212
}
183213

@@ -220,4 +250,42 @@
220250
{
221251
NavigationManager.NavigateTo($"/database-connection/details/{Id}");
222252
}
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+
}
223291
}

0 commit comments

Comments
 (0)