Compare commits

...

2 Commits

Author SHA1 Message Date
Zhanghu
13e6046b41 修改轮播项移动问题 2026-01-14 09:14:59 +08:00
Zhanghu
3c45381f28 改进轮播项 2026-01-13 18:11:20 +08:00
4 changed files with 93 additions and 22 deletions

View File

@@ -153,17 +153,31 @@ public class RotatorItemService
.Where(ri => ri.ApplicationId == applicationId)
.ToListAsync();
Console.WriteLine($"=== ReorderAsync called ===");
Console.WriteLine($"ApplicationId: {applicationId}");
Console.WriteLine($"Received itemIds: [{string.Join(", ", itemIds)}]");
Console.WriteLine($"Total items in DB: {items.Count}");
for (int i = 0; i < itemIds.Count; i++)
{
var item = items.FirstOrDefault(x => x.Id == itemIds[i]);
if (item != null)
{
var oldOrder = item.Order;
item.Order = i + 1;
item.UpdatedAt = DateTime.UtcNow;
Console.WriteLine($" Item {item.Id}: Order {oldOrder} -> {item.Order}");
}
else
{
Console.WriteLine($" WARNING: Item with ID {itemIds[i]} not found!");
}
}
await _context.SaveChangesAsync();
var affected = await _context.SaveChangesAsync();
Console.WriteLine($"SaveChangesAsync affected: {affected} rows");
Console.WriteLine($"=== ReorderAsync completed ===");
return true;
}
}

View File

@@ -133,12 +133,12 @@
<!-- 编辑轮播项 Modal -->
@if (_showRotatorModal)
{
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="CloseRotatorModal">
<div class="modal fade show d-block" style="background-color: rgba(0,0,0,0.5)" tabindex="-1" @onclick="async () => await CloseRotatorModal()">
<div class="modal-dialog modal-lg" @onclick:stopPropagation="true">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">编辑轮播项 - @_editingRotatorApp?.Name</h5>
<button type="button" class="btn-close" @onclick="CloseRotatorModal"></button>
<button type="button" class="btn-close" @onclick="async () => await CloseRotatorModal()"></button>
</div>
<div class="modal-body">
<!-- 添加新轮播项 -->
@@ -205,8 +205,9 @@
@for (int i = 0; i < _rotatorItems.Count; i++)
{
var item = _rotatorItems[i];
var isFirst = (i == 0);
var isLast = (i == _rotatorItems.Count - 1);
var index = i;
var isFirst = (index == 0);
var isLast = (index == _rotatorItems.Count - 1);
<div class="list-group-item d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<i class="bi @GetRotatorItemIcon(item.ItemType) me-2"></i>
@@ -219,10 +220,10 @@
</div>
</div>
<div class="btn-group">
<button class="btn btn-sm btn-outline-secondary" @onclick="@(() => MoveRotatorItemUp(item, i))" disabled="@isFirst">
<button class="btn btn-sm btn-outline-secondary" @onclick="@(() => MoveRotatorItemUp(item, index))" disabled="@isFirst">
<i class="bi bi-arrow-up"></i>
</button>
<button class="btn btn-sm btn-outline-secondary" @onclick="@(() => MoveRotatorItemDown(item, i))" disabled="@isLast">
<button class="btn btn-sm btn-outline-secondary" @onclick="@(() => MoveRotatorItemDown(item, index))" disabled="@isLast">
<i class="bi bi-arrow-down"></i>
</button>
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteRotatorItem(item))">
@@ -237,7 +238,7 @@
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @onclick="CloseRotatorModal">关闭</button>
<button type="button" class="btn btn-secondary" @onclick="async () => await CloseRotatorModal()">关闭</button>
</div>
</div>
</div>
@@ -437,13 +438,15 @@
}
}
private void CloseRotatorModal()
private async Task CloseRotatorModal()
{
_showRotatorModal = false;
_editingRotatorApp = null;
_rotatorItems = new();
_newRotatorUrl = "";
_rotatorError = "";
// 刷新应用列表以更新轮播项数量
await LoadApplications();
}
private async Task AddRotatorItem()
@@ -508,30 +511,84 @@
private async Task MoveRotatorItemUp(RotatorItemDto item, int index)
{
if (_editingRotatorApp == null || index <= 0 || index >= _rotatorItems.Count) return;
await JSRuntime.InvokeVoidAsync("console.log", $"=== MoveRotatorItemUp ===");
await JSRuntime.InvokeVoidAsync("console.log", $"Index: {index}, Item ID: {item.Id}");
await JSRuntime.InvokeVoidAsync("console.log", $"EditingApp: {_editingRotatorApp?.Id}");
await JSRuntime.InvokeVoidAsync("console.log", $"ItemCount: {_rotatorItems.Count}");
await JSRuntime.InvokeVoidAsync("console.log", $"Current order: [{string.Join(", ", _rotatorItems.Select(x => x.Id))}]");
// 交换顺序
_rotatorItems[index].Order = _rotatorItems[index - 1].Order;
_rotatorItems[index - 1].Order = item.Order;
if (_editingRotatorApp == null)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: EditingApp is null");
return;
}
if (index <= 0)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: Index {index} <= 0");
return;
}
if (index >= _rotatorItems.Count)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: Index {index} >= Count {_rotatorItems.Count}");
return;
}
// 创建新的顺序列表:交换两个相邻项的位置
var newOrder = _rotatorItems.ToList();
var temp = newOrder[index];
newOrder[index] = newOrder[index - 1];
newOrder[index - 1] = temp;
// 获取按照新顺序排列的 ID 列表
var itemIds = newOrder.Select(x => x.Id).ToList();
await JSRuntime.InvokeVoidAsync("console.log", $"New order: [{string.Join(", ", itemIds)}]");
// 更新到服务器
var itemIds = _rotatorItems.OrderBy(x => x.Order).Select(x => x.Id).ToList();
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
var result = await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
await JSRuntime.InvokeVoidAsync("console.log", $"API result: {result}");
await LoadRotatorItems(_editingRotatorApp.Id);
await JSRuntime.InvokeVoidAsync("console.log", $"Loaded order: [{string.Join(", ", _rotatorItems.Select(x => x.Id))}]");
}
private async Task MoveRotatorItemDown(RotatorItemDto item, int index)
{
if (_editingRotatorApp == null || index < 0 || index >= _rotatorItems.Count - 1) return;
await JSRuntime.InvokeVoidAsync("console.log", $"=== MoveRotatorItemDown ===");
await JSRuntime.InvokeVoidAsync("console.log", $"Index: {index}, Item ID: {item.Id}");
await JSRuntime.InvokeVoidAsync("console.log", $"Current order: [{string.Join(", ", _rotatorItems.Select(x => x.Id))}]");
// 交换顺序
_rotatorItems[index].Order = _rotatorItems[index + 1].Order;
_rotatorItems[index + 1].Order = item.Order;
if (_editingRotatorApp == null)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: EditingApp is null");
return;
}
if (index < 0)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: Index {index} < 0");
return;
}
if (index >= _rotatorItems.Count - 1)
{
await JSRuntime.InvokeVoidAsync("console.log", $"BLOCKED: Index {index} >= Count-1 {_rotatorItems.Count - 1}");
return;
}
// 创建新的顺序列表:交换两个相邻项的位置
var newOrder = _rotatorItems.ToList();
var temp = newOrder[index];
newOrder[index] = newOrder[index + 1];
newOrder[index + 1] = temp;
// 获取按照新顺序排列的 ID 列表
var itemIds = newOrder.Select(x => x.Id).ToList();
await JSRuntime.InvokeVoidAsync("console.log", $"New order: [{string.Join(", ", itemIds)}]");
// 更新到服务器
var itemIds = _rotatorItems.OrderBy(x => x.Order).Select(x => x.Id).ToList();
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
var result = await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
await JSRuntime.InvokeVoidAsync("console.log", $"API result: {result}");
await LoadRotatorItems(_editingRotatorApp.Id);
await JSRuntime.InvokeVoidAsync("console.log", $"Loaded order: [{string.Join(", ", _rotatorItems.Select(x => x.Id))}]");
}
private async Task TriggerFileUpload()

View File

@@ -8,7 +8,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=dashboard.db"
"DefaultConnection": "Data Source=data.db"
},
"Jwt": {
"Key": "DRS9_DASHBOARD_SECRET_KEY_2026_CHANGE_THIS_IN_PRODUCTION",