Learn.VideoAnalysis/VideoAnalysis/Components/Pages/NodeSubscriptionPage.razor.cs

133 lines
3.9 KiB
C#

using AntDesign;
using AntDesign.TableModels;
using FreeRedis;
using Learn.VideoAnalysis.Controllers.Dto;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using SqlSugar;
using System.Drawing;
using System.Linq.Expressions;
using System.Reflection;
using UserCenter.Model;
using UserCenter.Model.Enum;
using VideoAnalysisCore.Common;
using VideoAnalysisCore.Model.Enum;
using VideoAnalysisCore.Model;
namespace Learn.VideoAnalysis.Components.Pages
{
public partial class NodeSubscriptionPage : ComponentBase
{
[Inject] private ConfirmService ComfirmService { get; set; } = default!;
[Inject] private ModalService ModalService { get; set; } = default!;
[Inject] private Repository<NodeSubscription> criteria { get; set; } = default!;
[Inject] private INotificationService _notice { get; set; } = default!;
IEnumerable<NodeSubscription> _selectedRows = [];
ITable _table;
IForm? form;
List<NodeSubscription> _dataSource = null;
RefAsync<int> _total = 0;
bool tableLoading = false;
Table<NodeSubscription> tableRef;
List<NodeSubscription> _editSource = null;
bool modalShow =false;
bool modalBtnLoading = false;
NodeSubscription rowData;
SubjectEnum editSubject;
async void SubjectEnumSelect()
{
_editSource = await criteria.GetListAsync(x => x.Subject == editSubject);
await this.InvokeAsync(StateHasChanged);
}
void EditAddRow()
{
if (form is not null && form.Validate())
{
var data = rowData;
data.Subject = editSubject;
if (_editSource is null)
_editSource = new() { data };
else
_editSource.Add(data);
rowData = new();
StateHasChanged();
}
}
/// <summary>
/// 新增或者修改
/// </summary>
void StartEdit(NodeSubscription data)
{
rowData = data?? new();
modalShow = true;
}
async Task EditOnOkAsync()
{
var data = rowData;
modalBtnLoading = true;
await criteria.DeleteAsync(s => s.Subject == editSubject);
await criteria.InsertRangeAsync(_editSource);
_table.ReloadData();
modalShow = false;
modalBtnLoading = false;
StateHasChanged();
}
/// <summary>
/// 分页 查询 筛选 时
/// </summary>
/// <param name="query"></param>
async void OnChange(QueryModel<NodeSubscription> query)
{
tableLoading = true;
List<IConditionalModel> where = default!;
if (query.FilterModel != null && ((query.FilterModel?.Count() ?? 0) > 0))
{
where = query.ToSqlSugerWhere();
}
_dataSource = await criteria.AsQueryable()
.Where(where)
.ToPageListAsync(query.PageIndex, query.PageSize, _total);
tableLoading = false;
StateHasChanged();
}
/// <summary>
/// 删除行
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
async Task Delete(NodeSubscription row)
{
if (!await Comfirm($"确定要删除这条数据吗? [{row.NodeId}]?"))
return;
await criteria.DeleteByIdAsync(row.Id);
_table.ReloadData();
}
/// <summary>
/// 初始化
/// </summary>
protected override void OnInitialized()
{
}
private async Task<bool> Comfirm(string message)
{
return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
}
}
}