修改轮播项移动问题
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))">
|
||||
@@ -510,7 +511,27 @@
|
||||
|
||||
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))}]");
|
||||
|
||||
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();
|
||||
@@ -520,15 +541,37 @@
|
||||
|
||||
// 获取按照新顺序排列的 ID 列表
|
||||
var itemIds = newOrder.Select(x => x.Id).ToList();
|
||||
await JSRuntime.InvokeVoidAsync("console.log", $"New order: [{string.Join(", ", itemIds)}]");
|
||||
|
||||
// 更新到服务器
|
||||
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))}]");
|
||||
|
||||
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();
|
||||
@@ -538,10 +581,14 @@
|
||||
|
||||
// 获取按照新顺序排列的 ID 列表
|
||||
var itemIds = newOrder.Select(x => x.Id).ToList();
|
||||
await JSRuntime.InvokeVoidAsync("console.log", $"New order: [{string.Join(", ", itemIds)}]");
|
||||
|
||||
// 更新到服务器
|
||||
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()
|
||||
|
||||
@@ -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",
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user