改进轮播项

This commit is contained in:
Zhanghu
2026-01-13 18:11:20 +08:00
parent 037a6b2079
commit 3c45381f28

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">
<!-- 添加新轮播项 -->
@@ -237,7 +237,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 +437,15 @@
}
}
private void CloseRotatorModal()
private async Task CloseRotatorModal()
{
_showRotatorModal = false;
_editingRotatorApp = null;
_rotatorItems = new();
_newRotatorUrl = "";
_rotatorError = "";
// 刷新应用列表以更新轮播项数量
await LoadApplications();
}
private async Task AddRotatorItem()
@@ -510,12 +512,16 @@
{
if (_editingRotatorApp == null || index <= 0 || index >= _rotatorItems.Count) return;
// 交换顺序
_rotatorItems[index].Order = _rotatorItems[index - 1].Order;
_rotatorItems[index - 1].Order = item.Order;
// 创建新的顺序列表:交换两个相邻项的位置
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();
// 更新到服务器
var itemIds = _rotatorItems.OrderBy(x => x.Order).Select(x => x.Id).ToList();
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
await LoadRotatorItems(_editingRotatorApp.Id);
}
@@ -524,12 +530,16 @@
{
if (_editingRotatorApp == null || index < 0 || index >= _rotatorItems.Count - 1) return;
// 交换顺序
_rotatorItems[index].Order = _rotatorItems[index + 1].Order;
_rotatorItems[index + 1].Order = item.Order;
// 创建新的顺序列表:交换两个相邻项的位置
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();
// 更新到服务器
var itemIds = _rotatorItems.OrderBy(x => x.Order).Select(x => x.Id).ToList();
await ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
await LoadRotatorItems(_editingRotatorApp.Id);
}