Compare commits
2 Commits
037a6b2079
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13e6046b41 | ||
|
|
3c45381f28 |
@@ -153,17 +153,31 @@ public class RotatorItemService
|
|||||||
.Where(ri => ri.ApplicationId == applicationId)
|
.Where(ri => ri.ApplicationId == applicationId)
|
||||||
.ToListAsync();
|
.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++)
|
for (int i = 0; i < itemIds.Count; i++)
|
||||||
{
|
{
|
||||||
var item = items.FirstOrDefault(x => x.Id == itemIds[i]);
|
var item = items.FirstOrDefault(x => x.Id == itemIds[i]);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
|
var oldOrder = item.Order;
|
||||||
item.Order = i + 1;
|
item.Order = i + 1;
|
||||||
item.UpdatedAt = DateTime.UtcNow;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,12 +133,12 @@
|
|||||||
<!-- 编辑轮播项 Modal -->
|
<!-- 编辑轮播项 Modal -->
|
||||||
@if (_showRotatorModal)
|
@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-dialog modal-lg" @onclick:stopPropagation="true">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">编辑轮播项 - @_editingRotatorApp?.Name</h5>
|
<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>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<!-- 添加新轮播项 -->
|
<!-- 添加新轮播项 -->
|
||||||
@@ -205,8 +205,9 @@
|
|||||||
@for (int i = 0; i < _rotatorItems.Count; i++)
|
@for (int i = 0; i < _rotatorItems.Count; i++)
|
||||||
{
|
{
|
||||||
var item = _rotatorItems[i];
|
var item = _rotatorItems[i];
|
||||||
var isFirst = (i == 0);
|
var index = i;
|
||||||
var isLast = (i == _rotatorItems.Count - 1);
|
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="list-group-item d-flex justify-content-between align-items-center">
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<i class="bi @GetRotatorItemIcon(item.ItemType) me-2"></i>
|
<i class="bi @GetRotatorItemIcon(item.ItemType) me-2"></i>
|
||||||
@@ -219,10 +220,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group">
|
<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>
|
<i class="bi bi-arrow-up"></i>
|
||||||
</button>
|
</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>
|
<i class="bi bi-arrow-down"></i>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteRotatorItem(item))">
|
<button class="btn btn-sm btn-outline-danger" @onclick="@(() => DeleteRotatorItem(item))">
|
||||||
@@ -237,7 +238,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -437,13 +438,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CloseRotatorModal()
|
private async Task CloseRotatorModal()
|
||||||
{
|
{
|
||||||
_showRotatorModal = false;
|
_showRotatorModal = false;
|
||||||
_editingRotatorApp = null;
|
_editingRotatorApp = null;
|
||||||
_rotatorItems = new();
|
_rotatorItems = new();
|
||||||
_newRotatorUrl = "";
|
_newRotatorUrl = "";
|
||||||
_rotatorError = "";
|
_rotatorError = "";
|
||||||
|
// 刷新应用列表以更新轮播项数量
|
||||||
|
await LoadApplications();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddRotatorItem()
|
private async Task AddRotatorItem()
|
||||||
@@ -508,30 +511,84 @@
|
|||||||
|
|
||||||
private async Task MoveRotatorItemUp(RotatorItemDto item, int index)
|
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)
|
||||||
_rotatorItems[index].Order = _rotatorItems[index - 1].Order;
|
{
|
||||||
_rotatorItems[index - 1].Order = item.Order;
|
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();
|
var result = await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
||||||
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
await JSRuntime.InvokeVoidAsync("console.log", $"API result: {result}");
|
||||||
|
|
||||||
await LoadRotatorItems(_editingRotatorApp.Id);
|
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)
|
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)
|
||||||
_rotatorItems[index].Order = _rotatorItems[index + 1].Order;
|
{
|
||||||
_rotatorItems[index + 1].Order = item.Order;
|
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();
|
var result = await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
||||||
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
await JSRuntime.InvokeVoidAsync("console.log", $"API result: {result}");
|
||||||
|
|
||||||
await LoadRotatorItems(_editingRotatorApp.Id);
|
await LoadRotatorItems(_editingRotatorApp.Id);
|
||||||
|
await JSRuntime.InvokeVoidAsync("console.log", $"Loaded order: [{string.Join(", ", _rotatorItems.Select(x => x.Id))}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TriggerFileUpload()
|
private async Task TriggerFileUpload()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Data Source=dashboard.db"
|
"DefaultConnection": "Data Source=data.db"
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Key": "DRS9_DASHBOARD_SECRET_KEY_2026_CHANGE_THIS_IN_PRODUCTION",
|
"Key": "DRS9_DASHBOARD_SECRET_KEY_2026_CHANGE_THIS_IN_PRODUCTION",
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user