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.Enum; using VideoAnalysisCore.Model; namespace Learn.VideoAnalysis.Components.Pages { public partial class EvaluationProject : ComponentBase { [Inject] private ConfirmService ComfirmService { get; set; } = default!; [Inject] private ModalService ModalService { get; set; } = default!; [Inject] private Repository criteria { get; set; } = default!; [Inject] private INotificationService _notice { get; set; } = default!; IEnumerable _selectedRows = []; ITable _table; IForm? form; List _dataSource = null; RefAsync _total = 0; bool tableLoading = false; Table tableRef; List _editSource = null; bool modalShow =false; bool modalBtnLoading = false; CourseGradingCriteria rowData; SubjectEnum editSubject; async void SubjectEnumSelect() { _editSource = await criteria.GetListAsync(x => x.Subject.Value == 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(); } } /// /// 新增或者修改 /// void StartEdit() { rowData = new(); modalShow = true; } async Task EditOnOkAsync() { var data = rowData; modalBtnLoading = true; if (_editSource is null || _editSource.Count == 0) { await _notice.Open(new NotificationConfig() { Message = "提示", Description = "无效的学科课堂指标数据", NotificationType = NotificationType.Warning }); modalBtnLoading = false; return; } if (_editSource.Sum(x => x.TotalScore) != 100) { await _notice.Open(new NotificationConfig() { Message = "提示", Description = "课堂指标 总分不满100!请完善", NotificationType = NotificationType.Warning }); modalBtnLoading = false; return; } await criteria.DeleteAsync(s => s.Subject == editSubject); await criteria.InsertRangeAsync(_editSource); _table.ReloadData(); modalShow = false; modalBtnLoading = false; StateHasChanged(); } /// /// 分页 查询 筛选 时 /// /// async void OnChange(QueryModel query) { tableLoading = true; List 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(); } /// /// 删除行 /// /// /// async Task Delete(CourseGradingCriteria row) { if (!await Comfirm($"确定要删除这条数据吗? [{row.NamePrompt}]?")) return; await criteria.DeleteByIdAsync(row.Id); _table.ReloadData(); } /// /// 初始化 /// protected override void OnInitialized() { } private async Task Comfirm(string message) { return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes; } } }