改进轮播项
This commit is contained in:
@@ -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">
|
||||||
<!-- 添加新轮播项 -->
|
<!-- 添加新轮播项 -->
|
||||||
@@ -237,7 +237,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 +437,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()
|
||||||
@@ -510,12 +512,16 @@
|
|||||||
{
|
{
|
||||||
if (_editingRotatorApp == null || index <= 0 || index >= _rotatorItems.Count) return;
|
if (_editingRotatorApp == null || index <= 0 || index >= _rotatorItems.Count) return;
|
||||||
|
|
||||||
// 交换顺序
|
// 创建新的顺序列表:交换两个相邻项的位置
|
||||||
_rotatorItems[index].Order = _rotatorItems[index - 1].Order;
|
var newOrder = _rotatorItems.ToList();
|
||||||
_rotatorItems[index - 1].Order = item.Order;
|
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 ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
||||||
await LoadRotatorItems(_editingRotatorApp.Id);
|
await LoadRotatorItems(_editingRotatorApp.Id);
|
||||||
}
|
}
|
||||||
@@ -524,12 +530,16 @@
|
|||||||
{
|
{
|
||||||
if (_editingRotatorApp == null || index < 0 || index >= _rotatorItems.Count - 1) return;
|
if (_editingRotatorApp == null || index < 0 || index >= _rotatorItems.Count - 1) return;
|
||||||
|
|
||||||
// 交换顺序
|
// 创建新的顺序列表:交换两个相邻项的位置
|
||||||
_rotatorItems[index].Order = _rotatorItems[index + 1].Order;
|
var newOrder = _rotatorItems.ToList();
|
||||||
_rotatorItems[index + 1].Order = item.Order;
|
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 ApiClient.ReorderRotatorItemsAsync(_editingRotatorApp.Id, itemIds);
|
||||||
await LoadRotatorItems(_editingRotatorApp.Id);
|
await LoadRotatorItems(_editingRotatorApp.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user