CreateAppeal.razor.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using Microsoft.AspNetCore.Components.Forms;
  4. using Microsoft.Extensions.Configuration;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Net.Http;
  9. using System.Net.Http.Json;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. using wispro.sp.entity;
  13. using wispro.sp.web.Models;
  14. using wispro.sp.web.Services;
  15. namespace wispro.sp.web.Components
  16. {
  17. public partial class CreateAppeal
  18. {
  19. private CreateAppealModel _Model;
  20. private IFeedbackRef feedbackRef;
  21. private List<Staff> _Staffs;
  22. [Inject]
  23. protected AppealTypeService _atService { get; set; }
  24. [Inject] IUserService _UserService { get; set; }
  25. [Inject]
  26. protected IHttpService _httpClient{get;set;}
  27. [Inject]
  28. protected IConfiguration _configuration { get; set; }
  29. #region 文件上传控件设定
  30. //List<UploadFileItem> fileList = new List<UploadFileItem>();
  31. Dictionary<string, object> attrs ;
  32. void HandleChange(UploadInfo fileinfo)
  33. {
  34. try
  35. {
  36. _Model.FileList.Where(file => file.State == UploadState.Success && !string.IsNullOrWhiteSpace(file.Response)).ForEach(file =>
  37. {
  38. var result = file.GetResponse<List<AttachFile>>();
  39. file.Url = $"{_configuration.GetValue<string>("APIUrl")}AttachFiles/Download?id={result[0].Id}";
  40. });
  41. }
  42. catch { }
  43. }
  44. private async Task<bool> RemoveFile(UploadFileItem fileinfo)
  45. {
  46. try
  47. {
  48. var result = fileinfo.GetResponse<List<AttachFile>>();
  49. return await _httpClient.Get<bool>($"{_configuration.GetValue<string>("APIUrl")}AttachFiles/Delete?id={result[0].Id}");
  50. }
  51. catch {
  52. return false;
  53. }
  54. }
  55. #endregion
  56. protected override async void OnInitialized()
  57. {
  58. attrs = new Dictionary<string, object>
  59. {
  60. {"Action", $"{_configuration.GetValue<string>("APIUrl")}AttachFiles/PostFile" },
  61. {"Name", "files" },
  62. {"Multiple", false }
  63. };
  64. _Model = base.Options ?? new CreateAppealModel();
  65. //if(!string.IsNullOrEmpty(_Model.AppealType.ReviewerExpress))
  66. //{
  67. _Staffs =await _UserService.GetReviewers(_Model.AppealRecord.ItemId, _Model.AppealType.Id);
  68. //}
  69. //else
  70. //{
  71. // _Staffs =await _UserService.GetAll();
  72. //}
  73. base.OnInitialized();
  74. feedbackRef = base.FeedbackRef;
  75. StateHasChanged();
  76. }
  77. string _ErrorMessage;
  78. private async void OnFinish()
  79. {
  80. await base.OnFeedbackOkAsync(new ModalClosingEventArgs() { Cancel = true });
  81. }
  82. private void OnCancel()
  83. {
  84. base.OnFeedbackCancelAsync(new ModalClosingEventArgs() { Cancel = true });
  85. //_ = feedbackRef.CloseAsync();
  86. }
  87. }
  88. }