CreateAppeal.razor.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using Microsoft.AspNetCore.Components.Forms;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net.Http;
  8. using System.Net.Http.Json;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. using wispro.sp.entity;
  12. using wispro.sp.web.Models;
  13. using wispro.sp.web.Services;
  14. namespace wispro.sp.web.Components
  15. {
  16. public partial class CreateAppeal
  17. {
  18. private CreateAppealModel _Model;
  19. private IFeedbackRef feedbackRef;
  20. [Inject]
  21. protected AppealTypeService _atService { get; set; }
  22. [Inject]
  23. protected HttpClient _httpClient{get;set;}
  24. #region 文件上传控件设定
  25. //List<UploadFileItem> fileList = new List<UploadFileItem>();
  26. Dictionary<string, object> attrs = new Dictionary<string, object>
  27. {
  28. {"Action", "http://localhost:39476/api/AttachFiles/PostFile" },
  29. {"Name", "files" },
  30. {"Multiple", false }
  31. };
  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 = $"http://localhost:39476/api/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.GetFromJsonAsync<bool>($"http://localhost:39476/api/AttachFiles/Delete?id={result[0].Id}");
  50. }
  51. catch {
  52. return false;
  53. }
  54. }
  55. #endregion
  56. protected override async void OnInitialized()
  57. {
  58. _Model = base.Options ?? new CreateAppealModel();
  59. //Console.WriteLine($"Success:{JsonSerializer.Serialize(_Model)}");
  60. base.OnInitialized();
  61. feedbackRef = base.FeedbackRef;
  62. }
  63. string _ErrorMessage;
  64. private async void OnFinish()
  65. {
  66. await base.OnFeedbackOkAsync(new ModalClosingEventArgs() { Cancel = true });
  67. }
  68. private void OnCancel()
  69. {
  70. base.OnFeedbackCancelAsync(new ModalClosingEventArgs() { Cancel = true });
  71. //_ = feedbackRef.CloseAsync();
  72. }
  73. //private void OnFinishFailed(EditContext editContext)
  74. //{
  75. // Console.WriteLine($"Failed:{JsonSerializer.Serialize(Model)}");
  76. //}
  77. }
  78. }